Documentation ¶
Index ¶
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) Delta ¶
Delta calculates the 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.