Documentation ¶
Index ¶
- Constants
- Variables
- func StoreInDatabase(in *Item, force bool) (uint64, error)
- func TotalCandlesPerInterval(start, end time.Time, interval Interval) (out float64)
- type ByDate
- type Candle
- type Error
- type ExchangeCapabilitiesEnabled
- type ExchangeCapabilitiesSupported
- type Interval
- type IntervalData
- type IntervalRange
- type IntervalRangeHolder
- type IntervalTime
- type Item
- func ConvertToNewInterval(item *Item, newInterval Interval) (*Item, error)
- func CreateKline(trades []order.TradeHistory, interval Interval, p currency.Pair, a asset.Item, ...) (Item, error)
- func LoadFromDatabase(exchange string, pair currency.Pair, a asset.Item, interval Interval, ...) (Item, error)
- func (k *Item) FillMissingDataWithEmptyEntries(i *IntervalRangeHolder)
- func (k *Item) FormatDates()
- func (k *Item) GetClosePriceAtTime(t time.Time) (float64, error)
- func (k *Item) RemoveDuplicates()
- func (k *Item) RemoveOutsideRange(start, end time.Time)
- func (k *Item) SortCandlesByTimestamp(desc bool)
- type Kline
Constants ¶
const ( FifteenSecond = Interval(15 * time.Second) OneMin = Interval(time.Minute) ThreeMin = 3 * OneMin FiveMin = 5 * OneMin TenMin = 10 * OneMin FifteenMin = 15 * OneMin ThirtyMin = 30 * OneMin OneHour = Interval(time.Hour) TwoHour = 2 * OneHour FourHour = 4 * OneHour SixHour = 6 * OneHour EightHour = 8 * OneHour TwelveHour = 12 * OneHour OneDay = 24 * OneHour ThreeDay = 3 * OneDay SevenDay = 7 * OneDay FifteenDay = 15 * OneDay OneWeek = 7 * OneDay TwoWeek = 2 * OneWeek OneMonth = 31 * OneDay OneYear = 365 * OneDay )
Consts here define basic time intervals
const (
// ErrRequestExceedsExchangeLimits locale for exceeding rate limits message
ErrRequestExceedsExchangeLimits = "requested data would exceed exchange limits please lower range or use GetHistoricCandlesEx"
)
Variables ¶
var ( // ErrUnsetInterval is an error for date range calculation ErrUnsetInterval = errors.New("cannot calculate range, interval unset") // ErrUnsupportedInterval returns when the provided interval is not supported by an exchange ErrUnsupportedInterval = errors.New("interval unsupported by exchange") // ErrCanOnlyDownscaleCandles returns when attempting to upscale candles ErrCanOnlyDownscaleCandles = errors.New("interval must be a longer duration to scale") // ErrWholeNumberScaling returns when old interval data cannot neatly fit into new interval size ErrWholeNumberScaling = errors.New("new interval must scale properly into new candle") // ErrNotFoundAtTime returned when looking up a candle at a specific time ErrNotFoundAtTime = errors.New("candle not found at time") // SupportedIntervals is a list of all supported intervals SupportedIntervals = []Interval{ FifteenSecond, OneMin, ThreeMin, FiveMin, TenMin, FifteenMin, ThirtyMin, OneHour, TwoHour, FourHour, SixHour, EightHour, TwelveHour, OneDay, ThreeDay, SevenDay, FifteenDay, OneWeek, TwoWeek, OneMonth, OneYear, } )
Functions ¶
func StoreInDatabase ¶
StoreInDatabase returns Item from database seeded data
Types ¶
type Candle ¶
type Candle struct { Time time.Time Open float64 High float64 Low float64 Close float64 Volume float64 ValidationIssues string }
Candle holds historic rate information.
func LoadFromGCTScriptCSV ¶
LoadFromGCTScriptCSV loads kline data from a CSV file
type Error ¶
Error struct to hold kline interval errors
type ExchangeCapabilitiesEnabled ¶
type ExchangeCapabilitiesEnabled struct { Intervals map[string]bool `json:"intervals,omitempty"` ResultLimit uint32 }
ExchangeCapabilitiesEnabled all kline related exchange enabled options
type ExchangeCapabilitiesSupported ¶
ExchangeCapabilitiesSupported all kline related exchange supported options
type Interval ¶
Interval type for kline Interval usage
func (*Interval) IntervalsPerYear ¶
IntervalsPerYear helps determine the number of intervals in a year used in CAGR calculation to know the amount of time of an interval in a year
type IntervalData ¶
type IntervalData struct { Start IntervalTime End IntervalTime HasData bool }
IntervalData is used to monitor which candles contain data to determine if any data is missing
type IntervalRange ¶
type IntervalRange struct { Start IntervalTime End IntervalTime Intervals []IntervalData }
IntervalRange is a subset of candles based on exchange API request limits
type IntervalRangeHolder ¶
type IntervalRangeHolder struct { Start IntervalTime End IntervalTime Ranges []IntervalRange }
IntervalRangeHolder holds the entire range of intervals and the start end dates of everything
func CalculateCandleDateRanges ¶
func CalculateCandleDateRanges(start, end time.Time, interval Interval, limit uint32) (*IntervalRangeHolder, error)
CalculateCandleDateRanges will calculate the expected candle data in intervals in a date range If an API is limited in the amount of candles it can make in a request, it will automatically separate ranges into the limit
func (*IntervalRangeHolder) DataSummary ¶
func (h *IntervalRangeHolder) DataSummary(includeHasData bool) []string
DataSummary returns a summary of a data range to highlight where data is missing
func (*IntervalRangeHolder) HasDataAtDate ¶
func (h *IntervalRangeHolder) HasDataAtDate(t time.Time) bool
HasDataAtDate determines whether a there is any data at a set date inside the existing limits
func (*IntervalRangeHolder) SetHasDataFromCandles ¶
func (h *IntervalRangeHolder) SetHasDataFromCandles(c []Candle)
SetHasDataFromCandles will calculate whether there is data in each candle allowing any missing data from an API request to be highlighted
type IntervalTime ¶
IntervalTime benchmarks demonstrate, see BenchmarkJustifyIntervalTimeStoringUnixValues1 && BenchmarkJustifyIntervalTimeStoringUnixValues2
func CreateIntervalTime ¶
func CreateIntervalTime(tt time.Time) IntervalTime
CreateIntervalTime is a simple helper function to set the time twice
type Item ¶
type Item struct { Exchange string Pair currency.Pair Asset asset.Item Interval Interval Candles []Candle SourceJobID uuid.UUID ValidationJobID uuid.UUID }
Item holds all the relevant information for internal kline elements
func ConvertToNewInterval ¶
ConvertToNewInterval allows the scaling of candles to larger candles eg convert OneDay candles to ThreeDay candles, if there are adequate candles incomplete candles are NOT converted eg an 4 OneDay candles will convert to one ThreeDay candle, skipping the fourth
func CreateKline ¶
func CreateKline(trades []order.TradeHistory, interval Interval, p currency.Pair, a asset.Item, exchange string) (Item, error)
CreateKline creates candles out of trade history data for a set time interval
func LoadFromDatabase ¶
func LoadFromDatabase(exchange string, pair currency.Pair, a asset.Item, interval Interval, start, end time.Time) (Item, error)
LoadFromDatabase returns Item from database seeded data
func (*Item) FillMissingDataWithEmptyEntries ¶
func (k *Item) FillMissingDataWithEmptyEntries(i *IntervalRangeHolder)
FillMissingDataWithEmptyEntries amends a kline item to have candle entries for every interval between its start and end dates derived from ranges
func (*Item) GetClosePriceAtTime ¶
GetClosePriceAtTime returns the close price of a candle at a given time
func (*Item) RemoveDuplicates ¶
func (k *Item) RemoveDuplicates()
RemoveDuplicates removes any duplicate candles
func (*Item) RemoveOutsideRange ¶
RemoveOutsideRange removes any candles outside the start and end date
func (*Item) SortCandlesByTimestamp ¶
SortCandlesByTimestamp sorts candles by timestamp
type Kline ¶
type Kline struct { Amount float64 `json:"amount" description:"成交量"` Count int `json:"count" description:"成交笔数"` Open float64 `json:"open" description:"开盘价"` Close float64 `json:"close" description:"收盘价"` Low float64 `json:"low" description:"最低价"` High float64 `json:"high" description:"最高价"` Vol float64 `json:"vol" description:"成交额,即SUM(每一笔成交价 * 该笔的成交数量)"` OpenTime time.Time `json:"opentime" description:"开盘时间"` CloseTime time.Time `json:"closetime" description:"收盘时间"` }
Kline K线的映射