Documentation ¶
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) Add(candle *Candle)
- func (c *Cache) CandlesCopy() []msgjson.Candle
- func (c *Cache) CompletedCandlesSince(lastStoredEndStamp uint64) (cs []*Candle)
- func (c *Cache) Delta(since time.Time) (changePct float64, vol, high, low uint64)
- func (c *Cache) Last() *Candle
- func (c *Cache) Reset()
- func (c *Cache) WireCandles(count int) *msgjson.WireCandles
- type Candle
Constants ¶
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 ¶
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 ¶
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 (*Cache) Add ¶
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
CandlesCopy returns a deep copy of Candles with the oldest candle at the first index.
func (*Cache) CompletedCandlesSince ¶ added in v1.0.0
CompletedCandlesSince returns any candles that fall into an epoch after the epoch of the provided timestamp, and before the current epoch.
func (*Cache) Delta ¶
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) 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.