charter

package
Version: v0.0.0-...-a8632a4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HTMLBackgroundColor = drawing.Color{R: 0x1e, G: 0x1e, B: 0x1e, A: 255}

Functions

func Color

func Color(c drawing.Color) func() drawing.Color

func EmptyImageWithText

func EmptyImageWithText(width, height int, text string, w io.Writer) (int, error)

EmptyImageWithText writes PNG picture with text in the center.

func LabelLast

func LabelLast(c *Curve, rend gochart.Renderer, width, height int)

LabelLast

func LabelLastMaxMin

func LabelLastMaxMin(c *Curve, rend gochart.Renderer, width, height int)

LabelLastMaxMin puts last, max and min values in to the top/center, top/left and top/rigt corners.

func LabelMaxMin

func LabelMaxMin(c *Curve, rend gochart.Renderer, width, height int)

LabelMaxMin puts max and min values in to the top/left and top/rigt corners.

func LabelMinMaxInterval

func LabelMinMaxInterval(c *Curve) string

func Last

func Last(c *Curve) string

func Max

func Max(c *Curve) string

func MaxFloor

func MaxFloor(c *Curve) string

func Min

func Min(c *Curve) string

func PnlColor

func PnlColor(last float64) drawing.Color

PnlColor

func PointsAsIs

func PointsAsIs(c *Curve) ([]time.Time, []float64)

PointsAsIs returns curve points as is without changes.

func PointsSquared

func PointsSquared(c *Curve) ([]time.Time, []float64)

PointsSquared returns points always horizontal or vertical lines.

func RenderMulti

func RenderMulti(cus []*Curve, width, height int, colors []string, widths []float64, pngbuf *bytes.Buffer) error

RenderMulti renders a few Curves at once.

func StyleInstancePnL

func StyleInstancePnL(c *Curve) gochart.Style

func StyleLastPrice

func StyleLastPrice(c *Curve) gochart.Style

StyleLastPrice returns style for last price curve.

func StyleMixedPnL

func StyleMixedPnL(c *Curve) gochart.Style

func StyleOpeningPrice

func StyleOpeningPrice(color drawing.Color) func(*Curve) gochart.Style

StyleOpeningPrice returns style for opening price curve. It's dashed.

func StylePnL

func StylePnL(c *Curve) gochart.Style

StylePnL returns style for pnl curve. The color changes between Red and Green in accordance to last value (below or above zero).

func StyleThreshold

func StyleThreshold(color drawing.Color) func(*Curve) gochart.Style

StyleThreshold returns style for high and low curves.

func WriteMultiJSONTo

func WriteMultiJSONTo(cus []*Curve, w io.Writer) (int, error)

func WritePositiveNegativeJSONTo

func WritePositiveNegativeJSONTo(cu *Curve, from int, w io.Writer) (int, error)

Types

type Charter

type Charter struct {
	// contains filtered or unexported fields
}

func NewCharter

func NewCharter(s store.Storer, logger *zerolog.Logger) *Charter

func (*Charter) AddCurve

func (c *Charter) AddCurve(vac *Curve)

AddCurve adds value curve. It's ignored if exist already.

func (*Charter) AddValue

func (c *Charter) AddValue(code string, vat ValueAt) bool

func (*Charter) Curve

func (c *Charter) Curve(id string) *Curve

func (*Charter) DebugHandler

func (c *Charter) DebugHandler(w http.ResponseWriter, r *http.Request)

func (*Charter) DeleteCurve

func (c *Charter) DeleteCurve(code string)

func (*Charter) DownloadFile

func (c *Charter) DownloadFile(w http.ResponseWriter, r *http.Request)

DownloadFile

func (*Charter) GroupPnLHandler

func (a *Charter) GroupPnLHandler(w http.ResponseWriter, r *http.Request)

func (*Charter) LastValue

func (c *Charter) LastValue(code string) (float64, bool)

LastValue returns last value related to curve code. Return false if curve not found or there is no values.

func (*Charter) Len

func (c *Charter) Len(code string) int

Len returns amount of Curve elements identified by code.

func (*Charter) MultiChartImage

func (c *Charter) MultiChartImage(w http.ResponseWriter, r *http.Request)

MultiChartImage returns a chart image representing a single curve.

func (*Charter) MultiChartJSON

func (c *Charter) MultiChartJSON(w http.ResponseWriter, r *http.Request)

func (*Charter) RedisSetNames

func (c *Charter) RedisSetNames(ctx context.Context, prefix string) (map[string]string, error)

RedisSetNames returns map of redis sets starting with prefix. The key of map is set name without prefix. Value is redis set name.

func (*Charter) RegisterCurve

func (c *Charter) RegisterCurve(cu *Curve)

func (*Charter) Reset

func (c *Charter) Reset(key, value string)

func (*Charter) SingleChartImage

func (c *Charter) SingleChartImage(w http.ResponseWriter, r *http.Request)

func (*Charter) SingleChartJSON

func (c *Charter) SingleChartJSON(w http.ResponseWriter, r *http.Request)

SingleChartJSON returns a chart representing a single curve.

func (*Charter) Traverse

func (c *Charter) Traverse(f func(c *Curve))

type Curve

type Curve struct {
	At    []time.Time `json:"at"`
	Value []float64   `json:"v"`

	//
	AtP []time.Time `json:"atp"`
	AtN []time.Time `json:"atn"`

	// ValueP holds only values above or equal to zero
	ValueP []float64 `json:"vp,omitempty"`
	// ValueN holds only values below zero
	ValueN []float64 `json:"vn,omitempty"`

	MaxIndex int
	MinIndex int
	// contains filtered or unexported fields
}

Curve holds values and related timestamps and becomes source for chart.

func NewCurve

func NewCurve(code, attr string, vrf ValueReaderFunc, lsf StyleFunc, pf PointFunc, f ...LabelFunc) *Curve

func (*Curve) AddSlice

func (vat *Curve) AddSlice(p []ValueAt)

AddSlice adds a slice of ValueAt wrapped by a single Mutex.

func (*Curve) Attr

func (c *Curve) Attr() string

func (*Curve) ETag

func (c *Curve) ETag() string

func (*Curve) LastValue

func (cu *Curve) LastValue() (float64, bool)

func (*Curve) Len

func (c *Curve) Len() int

func (*Curve) Max

func (c *Curve) Max() float64

func (*Curve) Min

func (c *Curve) Min() float64

func (*Curve) Push

func (c *Curve) Push(at int64, val float64)

Push adds elements in the end of the curve.

func (*Curve) Reset

func (c *Curve) Reset()

func (*Curve) WriteJSONTo

func (c *Curve) WriteJSONTo(w io.Writer, name string, from int) (int, error)

func (*Curve) WriteTo

func (c *Curve) WriteTo(w io.Writer) (int64, error)

type GroupPnL

type GroupPnL struct {
	Name  string  `json:"name"`
	Value float64 `json:"val"`
}

type LabelFunc

type LabelFunc func(c *Curve, r gochart.Renderer, width, height int)

LabelFunc describes function parameters

func Label

func Label(x, y int, label LabelGetterFunc, color drawing.Color) LabelFunc

type LabelGetterFunc

type LabelGetterFunc func(c *Curve) string

type PointFunc

type PointFunc func(c *Curve) ([]time.Time, []float64)

type StyleFunc

type StyleFunc func(c *Curve) gochart.Style

type ValueAt

type ValueAt struct {
	At    int64
	Value float64
}

type ValueReaderFunc

type ValueReaderFunc func(c *Curve) error

func RedisHashAttrReader

func RedisHashAttrReader(zl *zerolog.Logger, rs store.Storer, hashName, attr string, listprefix string) ValueReaderFunc

RedisHashAttrReader

func RedisPlatformPnLFiller

func RedisPlatformPnLFiller(zl *zerolog.Logger, rs store.Storer, redisListName string, c *Charter) ValueReaderFunc

func RedisPnLReader

func RedisPnLReader(zl *zerolog.Logger, rs store.Storer, redisListName string) ValueReaderFunc

RedisPnLReader

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL