candles

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: BlueOak-1.0.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultCandleRequest is the number of candles to return if the request
	// does not specify otherwise.
	DefaultCandleRequest = 50
	// CacheSize is the default cache size. Also represents the maximum number
	// of candles that can be requested at once.
	CacheSize = 1000
)

Variables

View Source
var (
	// BinSizes is the default bin sizes for candlestick data sets. Exported for
	// use in the 'config' response. Internally, we will parse these to uint64
	// milliseconds.
	BinSizes = []string{"24h", "1h", "5m"}
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Candles []Candle
	BinSize uint64
	// contains filtered or unexported fields
}

Cache is a sized cache of candles. Cache provides methods for adding to the cache and reading cache data out. Candles is a typical slice until it reaches capacity, when it becomes a "circular array" to avoid re-allocations.

func NewCache

func NewCache(cap int, binSize uint64) *Cache

NewCache is a constructor for a Cache.

func (*Cache) Add

func (c *Cache) Add(candle *Candle)

Add adds a new candle TO THE END of the Cache. The caller is responsible to ensure that candles added with Add are always newer than the last candle added.

func (*Cache) CandlesCopy added in v0.6.0

func (c *Cache) CandlesCopy() []msgjson.Candle

CandlesCopy returns a deep copy of Candles with the oldest candle at the first index.

func (*Cache) CompletedCandlesSince added in v1.0.0

func (c *Cache) CompletedCandlesSince(lastStoredEndStamp uint64) (cs []*Candle)

CompletedCandlesSince returns any candles that fall into an epoch after the epoch of the provided timestamp, and before the current epoch.

func (*Cache) Delta

func (c *Cache) Delta(since time.Time) (changePct float64, vol, high, low uint64)

Delta calculates the change in rate, as a percentage, and total volume over the specified period going backwards from now. Because the first candle does not necessarily align with the cutoff, the rate and volume contribution from that candle is linearly interpreted between the endpoints. The caller is responsible for making sure that dur >> binSize, otherwise the results will be of little value.

func (*Cache) Last

func (c *Cache) Last() *Candle

Last gets the most recent candle in the cache.

func (*Cache) Reset

func (c *Cache) Reset()

func (*Cache) WireCandles

func (c *Cache) WireCandles(count int) *msgjson.WireCandles

WireCandles encodes up to 'count' most recent candles as *msgjson.WireCandles. If the Cache contains fewer than 'count', only those available will be returned, with no indication of error.

type Candle

type Candle = msgjson.Candle

Candle is a report about the trading activity of a market over some specified period of time. Candles are managed with a Cache, which takes into account bin sizes and handles candle addition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL