Documentation ¶
Index ¶
- Constants
- Variables
- func CurrencyCodesHistorical() []currency.Unit
- func CurrencyCodesNow() []currency.Unit
- func CurrencyGetSymbol(unit currency.Unit) string
- func CurrencyIsFiat(unit currency.Unit) bool
- func CurrencyIsMetal(unit currency.Unit) bool
- func CurrencyIsTest(unit currency.Unit) bool
- func CurrencyParse(s string) (currency.Unit, error)
- func FindSamePairs(pairs map[Platform][]Pair) map[Pair][]Platform
- func FixCoinName(name string) string
- func FixCoinSymbol(symbol string) string
- func FixNameSymbol(s string) string
- func GetTotalAmount(input []OrderBook) gdecimal.Decimal
- func GetTotalPrice(input []OrderBook) gdecimal.Decimal
- func IsTradeSymbolFiat(sym string) bool
- func NewPairExt(p Pair, period *Period, market *Market, platform *Platform) pairExt
- func PairExtsEqual(a []pairExt, b []pairExt) bool
- func PairExtsInclude(src []pairExt, find pairExt) bool
- func PairExtsSort(src []pairExt)
- func PairMPEqual(a []PairMP, b []PairMP) bool
- func PairMPInclude(src []PairMP, find PairMP) bool
- func PairMPSort(src []PairMP)
- func ParsePairExtString(s string) (Pair, *Period, *Market, *Platform, error)
- func RoundPeriodEarlier(dotTime time.Time, period Period, prc PeriodRoundConfig) time.Time
- func SyncXAxis(ks1, ks2 *CandleSticks, fillIfNotExist Bar)
- type AR
- type ARs
- type Account
- func (a *Account) AddAccount(toAdd Account)
- func (a *Account) AddFree(ap AssetProperty, toAdd gdecimal.Decimal)
- func (a *Account) AddLock(ap AssetProperty, toAdd gdecimal.Decimal)
- func (a *Account) Borrow(tm time.Time, margin Margin, asset string, amount gdecimal.Decimal) error
- func (a *Account) ExchangeToUSD(ticks Ticks, ignorePairsNotFound bool) (*AssetAmount, error)
- func (a *Account) GetAmountByName(asset string) AssetAmount
- func (a *Account) GetAmountByProperty(ap AssetProperty) AssetAmount
- func (a *Account) JsonString() string
- func (a *Account) Lock(market Market, margin Margin, asset string, amount gdecimal.Decimal) error
- func (a *Account) RemoveZeroMembers()
- func (a *Account) Repay(tm time.Time, interestRateDaily gdecimal.Decimal, margin Margin, asset string, ...) error
- func (a *Account) SetAmount(ap AssetProperty, amount AssetAmount)
- func (a *Account) SetFreeAmount(ap AssetProperty, freeAmount gdecimal.Decimal)
- func (a *Account) SetLockedAmount(ap AssetProperty, lockedAmount gdecimal.Decimal)
- func (a *Account) String() string
- func (a *Account) Transfer(asset string, amount gdecimal.Decimal, from, to SubAcc) error
- func (a *Account) Unlock(ap AssetProperty, amount gdecimal.Decimal) error
- type AccountAddress
- type AccountSnapshot
- type Asset
- func AllFiats() []Asset
- func AllIndexes() []Asset
- func AllMetals() []Asset
- func AllQuoteAssets() []Asset
- func AllQuoteCoins() []Asset
- func AllStableCoins() []Asset
- func NewAsset(sdn string) (Asset, error)
- func NewCoin(name, symbol string, plt Platform) Asset
- func NewCoinWithSymbol(symbol string, plt Platform) Asset
- func NewStock(symbol string, exchange Platform) Asset
- func ParseFiat(s string) (Asset, error)
- func StableCoinsByFiat(anchorFiat Asset) []Asset
- func (a Asset) Against(quote Asset) Pair
- func (a Asset) Equal(cmp Asset) bool
- func (a Asset) MarshalJSON() ([]byte, error)
- func (a Asset) Name() string
- func (a Asset) String() string
- func (a Asset) Symbol() string
- func (a Asset) ToCoin() (platform Platform, name, symbol string, ok bool)
- func (a Asset) ToFiat() (string, bool)
- func (a Asset) ToFiatUnit() (currency.Unit, bool)
- func (a Asset) ToIndex() (string, bool)
- func (a Asset) ToMetal() (string, bool)
- func (a Asset) ToStock() (exchange Platform, symbol string, ok bool)
- func (a Asset) TradeSymbol() string
- func (a Asset) Type() AssetType
- func (a *Asset) UnmarshalJSON(b []byte) error
- type AssetAmount
- type AssetProperty
- type AssetSetting
- type AssetType
- type Balance
- func (b *Balance) Add(toAdd Balance) error
- func (b *Balance) AssetPropertyEquals(ap AssetProperty) bool
- func (b *Balance) BorrowedByHist() gdecimal.Decimal
- func (b *Balance) InterestByHist(tm time.Time, interestRateDaily gdecimal.Decimal) gdecimal.Decimal
- func (b *Balance) IsZero() bool
- func (b Balance) Len() int
- func (b Balance) Less(i, j int) bool
- func (b Balance) Swap(i, j int)
- func (b *Balance) VerifyAssetProperty(ap AssetProperty) error
- type Bar
- func (d *Bar) ExprValue(expr string) (gdecimal.Decimal, bool)
- func (d *Bar) ExprValueFloat64(expr string) (float64, bool)
- func (d Bar) GetId() (gdecimal.Decimal, error)
- func (d Bar) GetTime() (time.Time, error)
- func (d *Bar) IsCrossLine() bool
- func (d *Bar) IsNegativeLine() bool
- func (d *Bar) IsPositiveLine() bool
- type Borrow
- type CandleSticks
- func (k *CandleSticks) AcrossDays() float64
- func (k *CandleSticks) BeforeEqualClosest(tm time.Time) (item *Bar, exists bool)
- func (k *CandleSticks) CleanHMS(loc *time.Location) *CandleSticks
- func (k *CandleSticks) Clone() *CandleSticks
- func (k *CandleSticks) Close(i int) float64
- func (k *CandleSticks) CloseRaw(i int) gdecimal.Decimal
- func (k *CandleSticks) CloseValues() []float64
- func (k *CandleSticks) Closes() []gdecimal.Decimal
- func (k *CandleSticks) DetectPeriod() Period
- func (k *CandleSticks) ExprValues(expr string) ([]float64, error)
- func (k *CandleSticks) Exprs() []string
- func (k *CandleSticks) ExprsOfIndExpr(ie ta.IndExpr) []string
- func (k *CandleSticks) First() (Bar, bool)
- func (k *CandleSticks) FirstDay(tz *time.Location) gtime.Date
- func (k *CandleSticks) FirstTime(defIfEmpty time.Time) time.Time
- func (k *CandleSticks) FirstTimeEx() (last *time.Time, exists bool)
- func (k *CandleSticks) GetDoc(i int) TimeDoc
- func (k *CandleSticks) GetName() string
- func (k *CandleSticks) HasDuplicatedKeys() ([]time.Time, bool)
- func (k *CandleSticks) HasExpr(expr string) bool
- func (k *CandleSticks) HasTime(tm time.Time) bool
- func (k *CandleSticks) High(i int) float64
- func (k *CandleSticks) HighRaw(i int) gdecimal.Decimal
- func (k *CandleSticks) HighValues() []float64
- func (k *CandleSticks) Highs() []gdecimal.Decimal
- func (k *CandleSticks) IndexEqual(t time.Time) (int, Bar, bool)
- func (k *CandleSticks) IndicatorExps() []string
- func (k *CandleSticks) IsConsequentDayLine() bool
- func (k *CandleSticks) IsTimeOverlappingAreaEqual(cmp *CandleSticks) (equal bool)
- func (k *CandleSticks) Last() (Bar, bool)
- func (k *CandleSticks) LastClose(defIfEmpty gdecimal.Decimal) gdecimal.Decimal
- func (k *CandleSticks) LastCloseTime(defTime time.Time) time.Time
- func (k *CandleSticks) LastDay(tz *time.Location) gtime.Date
- func (k *CandleSticks) LastExprValue(expr string) (float64, error)
- func (k *CandleSticks) LastExprs() []string
- func (k *CandleSticks) LastLow(defIfEmpty gdecimal.Decimal) gdecimal.Decimal
- func (k *CandleSticks) LastTime(defIfEmpty time.Time) time.Time
- func (k *CandleSticks) LastTimeEx() (last *time.Time, exists bool)
- func (k *CandleSticks) Len() int
- func (k *CandleSticks) Less(i, j int) bool
- func (k *CandleSticks) Low(i int) float64
- func (k *CandleSticks) LowRaw(i int) gdecimal.Decimal
- func (k *CandleSticks) LowValues() []float64
- func (k *CandleSticks) Lows() []gdecimal.Decimal
- func (k *CandleSticks) MaxIndex() int
- func (k *CandleSticks) MaxIndexLT(t time.Time) int
- func (k *CandleSticks) MaxIndexLTE(t time.Time) int
- func (k *CandleSticks) Merge() Bar
- func (k *CandleSticks) MinIndexGT(t time.Time) int
- func (k *CandleSticks) MinIndexGTE(t time.Time) int
- func (k *CandleSticks) Open(i int) float64
- func (k *CandleSticks) OpenRaw(i int) gdecimal.Decimal
- func (k *CandleSticks) OpenValues() []float64
- func (k *CandleSticks) Opens() []gdecimal.Decimal
- func (k *CandleSticks) RemoveTail(n int) *CandleSticks
- func (k *CandleSticks) Set(newKs *CandleSticks)
- func (k *CandleSticks) SetIndicatorValue(indExpr ta.IndExpr, subItemName string, values []float64) error
- func (k *CandleSticks) SliceAfter(gt time.Time) *CandleSticks
- func (k *CandleSticks) SliceAfterEqual(gte time.Time) *CandleSticks
- func (k *CandleSticks) SliceBefore(lt time.Time) *CandleSticks
- func (k *CandleSticks) SliceBeforeEqual(lte time.Time) *CandleSticks
- func (k *CandleSticks) SliceBetween(gt, lt time.Time) *CandleSticks
- func (k *CandleSticks) SliceBetweenEqual(gte, lte time.Time) *CandleSticks
- func (k *CandleSticks) SliceBetweenId(gte, lte int) *CandleSticks
- func (k *CandleSticks) SliceHead(n int) *CandleSticks
- func (k *CandleSticks) SliceTail(n int) *CandleSticks
- func (k *CandleSticks) Sort()
- func (k *CandleSticks) SortClose()
- func (k *CandleSticks) SortCloseReverse()
- func (k *CandleSticks) SortHigh()
- func (k *CandleSticks) SortHighReverse()
- func (k *CandleSticks) SortLow()
- func (k *CandleSticks) SortLowReverse()
- func (k *CandleSticks) SortOpen()
- func (k *CandleSticks) SortOpenReverse()
- func (k *CandleSticks) String() string
- func (k *CandleSticks) Swap(i, j int)
- func (k *CandleSticks) TA() *KTA
- func (k *CandleSticks) Time(i int) time.Time
- func (k *CandleSticks) TimeOverlappingArea(cmp *CandleSticks) (exist bool, begin, end time.Time)
- func (k *CandleSticks) Times() []time.Time
- func (k *CandleSticks) ToBar() Bar
- func (k *CandleSticks) ToChartTemplate(indExprs ...string) (*ghtml.ChartTemplate, error)
- func (k *CandleSticks) ToPeriod(newPeriod Period, config PeriodRoundConfig) (*CandleSticks, error)
- func (k *CandleSticks) ToPeriodPartly(lastConverted *CandleSticks, newPeriod Period, config PeriodRoundConfig) error
- func (k *CandleSticks) ToPeriodWithTail(newPeriod Period, config PeriodRoundConfig, tail int) (*CandleSticks, error)
- func (k *CandleSticks) Update(time time.Time, itemName string, value gdecimal.Decimal) (updatedCount int)
- func (k *CandleSticks) Upsert(toUpsert *CandleSticks)
- func (k *CandleSticks) UpsertDot(dot Bar)
- func (k *CandleSticks) Volume(i int) float64
- func (k *CandleSticks) VolumeRaw(i int) gdecimal.Decimal
- func (k *CandleSticks) VolumeValues() []float64
- func (k *CandleSticks) Volumes() []gdecimal.Decimal
- type CandleSticksConverter
- type CustomPairParse
- type Depth
- func (d *Depth) MarketBuyDetect(quoteAmount gdecimal.Decimal) DepthTolerance
- func (d *Depth) MarketBuyDetectEx(quoteAmount gdecimal.Decimal, slippageAllowed gdecimal.Decimal, precision int, ...) DepthTolerance
- func (d *Depth) MarketSellDetect(unitAmount gdecimal.Decimal) DepthTolerance
- func (d *Depth) MarketSellDetectEx(unitAmount, slippageAllowed gdecimal.Decimal) DepthTolerance
- func (d *Depth) ParseBuyOnePrice() gdecimal.Decimal
- func (d *Depth) ParseBuyerTotal() (avgPrice, totalAmount gdecimal.Decimal)
- func (d *Depth) ParseSellOnePrice() gdecimal.Decimal
- func (d *Depth) ParseSellerTotal() (avgPrice, totalAmount gdecimal.Decimal)
- func (d *Depth) Sort()
- func (d Depth) String() string
- type DepthRawData
- type DepthTolerance
- type Dir
- type DirWT
- type DoubleDir
- type ExApi
- type ExProperty
- type Fill
- type FillOption
- type HighlyRelevant
- type Irrelevant
- type KForm
- type KTA
- func (kta *KTA) Break(breakUp bool, beginInclude bool, begin time.Time, endInclude bool, ...) (time.Time, bool)
- func (kta *KTA) CleanupIndicators()
- func (kta *KTA) Crosses(exp1, exp2 string, n int) ([]TACross, error)
- func (kta *KTA) FirstHeavyVolumePriceRose(gt time.Time, pricePercent float64, volumeCmpDays int, lowGt *float64) (Bar, bool)
- func (kta *KTA) K() *CandleSticks
- func (kta *KTA) LastDirReversalExprValue(exp string, gt *time.Time) (float64, error)
- func (kta *KTA) LastDirs(exp string, directionSize int, gt *time.Time) ([]DirWT, error)
- func (kta *KTA) LastHeavyVolumePriceRose(gt time.Time, pricePercent float64, volumeCmpDays int) (Bar, bool)
- func (kta *KTA) ReverseCross1(exp1, exp2 string) (*TACross, error)
- func (kta *KTA) ReverseCrosses(exp1, exp2 string, n int) ([]TACross, error)
- func (kta *KTA) UpdateIndicators(indicatorExpr ...string) error
- type KlineProviderInfo
- type LHS
- type Leverage
- func (l *Leverage) BuySideMaxLeverage() gdecimal.Decimal
- func (l *Leverage) SellSideMaxLeverage() gdecimal.Decimal
- func (l *Leverage) SetFixedFloat64(buySide bool, fixLeverages ...float64)
- func (l *Leverage) SetSmoothFloat64(buySide bool, min float64, step float64, max float64)
- func (l *Leverage) SupportLeverage(buySide bool) bool
- func (l *Leverage) Verify() error
- type LowlyRelevant
- type Margin
- type Market
- type MarketInfo
- func (mi *MarketInfo) AvailableSymbols() []string
- func (mi *MarketInfo) GetMakerFee(pm PairM) (gdecimal.Decimal, bool)
- func (mi *MarketInfo) GetTakerFee(pm PairM) (gdecimal.Decimal, bool)
- func (mi *MarketInfo) PairIMPs(period Period, platform Platform) []PairIMP
- func (mi *MarketInfo) PairMs() []PairM
- func (mi *MarketInfo) Pairs() []Pair
- func (mi *MarketInfo) PairsAllowedFilter(allowedSymbols []string) []Pair
- func (mi *MarketInfo) PairsIncludeFilter(includeSymbols []string, excludeSymbols []string) []Pair
- func (mi *MarketInfo) SupportMargin(pair Pair) bool
- func (mi *MarketInfo) Verify() error
- type ModeratelyRelevant
- type Order
- type OrderBook
- type OrderBookList
- type OrderId
- type OrderList
- type OrderSide
- type OrderStatus
- type OrderType
- type Pair
- func (p Pair) CustomFormat(config *ExProperty) string
- func (p Pair) First() string
- func (p Pair) Format(split string, upper bool) string
- func (p Pair) FormatISO() string
- func (p Pair) MarshalJSON() ([]byte, error)
- func (p Pair) Quote() string
- func (p Pair) Second() string
- func (p Pair) SetI(period Period) PairI
- func (p Pair) SetM(market Market) PairM
- func (p Pair) SetP(platform Platform) PairP
- func (p Pair) String() string
- func (p Pair) Unit() string
- func (p Pair) Verify() error
- type PairI
- type PairIM
- type PairIMP
- func (pimp PairIMP) I() Period
- func (pimp PairIMP) M() Market
- func (pimp PairIMP) P() Platform
- func (pimp PairIMP) Pair() Pair
- func (pimp PairIMP) PairMP() PairMP
- func (pimp PairIMP) SetI(i Period) PairIMP
- func (pimp PairIMP) SetM(m Market) PairIMP
- func (pimp PairIMP) SetP(p Platform) PairIMP
- func (pimp PairIMP) String() string
- func (pimp PairIMP) Verify() error
- type PairIP
- type PairInfo
- type PairM
- type PairMP
- func (pmp PairMP) M() Market
- func (pmp PairMP) P() Platform
- func (pmp PairMP) Pair() Pair
- func (pmp PairMP) PairM() PairM
- func (pmp PairMP) PairP() PairP
- func (pmp PairMP) SetI(i Period) PairIMP
- func (pmp PairMP) SetM(m Market) PairMP
- func (pmp PairMP) SetP(p Platform) PairMP
- func (pmp PairMP) String() string
- func (pmp PairMP) Verify() error
- type PairP
- type Pattern
- type PatternLHS
- type PatternRHS
- type Patterns
- type Period
- func (p Period) CustomFormat(config *ExProperty) (string, error)
- func (p Period) MarshalJSON() ([]byte, error)
- func (p Period) String() string
- func (p Period) ToDuration() time.Duration
- func (p Period) ToDurationExact(t time.Time, tz *time.Location) time.Duration
- func (p Period) ToSeconds() int64
- func (p *Period) UnmarshalJSON(b []byte) error
- type PeriodRoundConfig
- type Platform
- type PlatformInfo
- type Portfolio
- type RHS
- type Since
- type SubAcc
- type SubAccParsed
- type TACross
- type TACrosses
- type Tick
- type Ticks
- type TimeDoc
- type TimeSeries
- type TradeIncome
- type TradeIntent
Constants ¶
const ( ExprOpen = "O" ExprHigh = "H" ExprLow = "L" ExprClose = "C" ExprVolume = "V" )
const ( ExApiGetKline = ExApi("ExApiGetKline") ExApiGetFill = ExApi("ExApiGetFill") )
const ( OrderIdDelimiter = ":" OrderStatusError OrderStatus = "" // Pending is a status before 'new', indicates that the order has not been successfully created, // only some exchanges use it, like Kraken. OrderStatusPending OrderStatus = "pending" OrderStatusNew OrderStatus = "new" OrderStatusPartiallyFilled OrderStatus = "partially_filled" OrderStatusFilled OrderStatus = "filled" OrderStatusPartiallyCanceled OrderStatus = "partially_canceled" // binance没有这个状态,huobi有 OrderStatusCanceled OrderStatus = "canceled" OrderStatusCanceling OrderStatus = "canceling" OrderStatusRejected OrderStatus = "rejected" OrderStatusExpired OrderStatus = "expired" OrderSideError OrderSide = "" OrderSideBuyLong OrderSide = "buy" OrderSideSellShort OrderSide = "sell" OrderTypeError OrderType = "" OrderTypeLimit OrderType = "limit" OrderTypeMarket OrderType = "market" OrderTypeStopLossLimit OrderType = "stop_loss_limit" // Stop loss limit order. OrderTypeTakeProfitLimit OrderType = "take_profit_limit" // Take profit limit order. OrderTypeStopLossMarket OrderType = "stop_loss_market" // Stop loss market order. OrderTypeTakeProfitMarket OrderType = "take_profit_market" // Take profit market order. TradeIntentError TradeIntent = "" TradeIntentOpen TradeIntent = "open" // 开仓进场 TradeIntentReduce TradeIntent = "reduce" // 减仓 TradeIntentAdd TradeIntent = "add" // 加仓 TradeIntentClose TradeIntent = "close" // 平仓离场 TradeIntentAdjust TradeIntent = "adjust" // 调整限价单/止盈止损单的点位 TradeIncomeError TradeIncome = "" TradeIncomeLoss TradeIncome = "loss" // 止损 TradeIncomeProfit TradeIncome = "profit" // 止盈 )
Variables ¶
var ( // famous quote coins BTC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Bitcoin", "BTC", "", true}) LTC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Litecoin", "LTC", "", true}) ETH = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Ethereum", "ETH", "", true}) EOS = mustEnrollAsset(AssetSetting{AssetTypeCoin, "EOS", "EOS", "", true}) ZRX = mustEnrollAsset(AssetSetting{AssetTypeCoin, "0x", "ZRX", "", true}) BNB = mustEnrollAsset(AssetSetting{AssetTypeCoin, "BinanceCoin", "BNB", "", true}) ETC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Ethereum-Classic", "ETC", "", true}) TRX = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Tron", "TRX", "", true}) DOGE = mustEnrollAsset(AssetSetting{AssetTypeCoin, "DogeCoin", "DOGE", "", true}) XLM = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Stellar", "XLM", "", true}) XRP = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Ripple", "XRP", "", true}) // famous common coins AION = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Aion", "AION", "", false}) WAN = mustEnrollAsset(AssetSetting{AssetTypeCoin, "WanCoin", "WAN", "", false}) FSN = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Fusion", "FSN", "", false}) HOLO = mustEnrollAsset(AssetSetting{AssetTypeCoin, "HoloToken", "HOT", "", false}) DCR = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Decred", "DCR", "", false}) POA = mustEnrollAsset(AssetSetting{AssetTypeCoin, "POA-Network", "POA", "", false}) DFN = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Dfinity", "DFN", "", false}) AE = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Aeternity", "AE", "", false}) DOT = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Polkadot", "DOT", "", false}) ADA = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Cardano", "ADA", "", false}) RHOC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "RChain", "RHOC", "", false}) ICX = mustEnrollAsset(AssetSetting{AssetTypeCoin, "ICON", "ICX", "", false}) NANO = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Nano", "NANO", "", false}) ZEC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "ZenCash", "ZEC", "", false}) GRIN = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Grin", "GRIN", "", false}) // stable coins USDC = mustEnrollAsset(AssetSetting{AssetTypeCoin, "USD-Coin", "USDC", "USD", true}) USDT = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Tether", "USDT", "USD", true}) USDS = mustEnrollAsset(AssetSetting{AssetTypeCoin, "StableUSD", "USDS", "USD", true}) TUSD = mustEnrollAsset(AssetSetting{AssetTypeCoin, "TrueUSD", "TUSD", "USD", true}) PAX = mustEnrollAsset(AssetSetting{AssetTypeCoin, "Paxos-Standard-Token", "PAX", "USD", true}) DAI = mustEnrollAsset(AssetSetting{AssetTypeCoin, "DAI", "DAI", "USD", true}) BUSD = mustEnrollAsset(AssetSetting{AssetTypeCoin, "BinanceUSD", "BUSD", "USD", true}) BKRW = mustEnrollAsset(AssetSetting{AssetTypeCoin, "BinanceKRW", "BKRW", "KRW", true}) BIDR = mustEnrollAsset(AssetSetting{AssetTypeCoin, "BinanceIDR", "BIDR", "IDR", true}) // G10 currencies USD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.USD.String(), "", "", true}) // US Dollar ($) EUR = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.EUR.String(), "", "", true}) // Euro (€) JPY = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.JPY.String(), "", "", true}) // Japanese Yen (¥) GBP = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.GBP.String(), "", "", true}) // British Pound Sterling (£) CHF = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.CHF.String(), "", "", true}) // Swiss Franc (CHF) AUD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.AUD.String(), "", "", true}) // Australian Dollar, AUD (A$) NZD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.NZD.String(), "", "", true}) // New Zealand Dollar (NZ$) CAD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.CAD.String(), "", "", true}) // Canadian Dollar, CAD (C$) SEK = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.SEK.String(), "", "", true}) // Swedish Krona (SEK) NOK = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.NOK.String(), "", "", true}) // Norwegian Krone (NOK) // non-famous quote currencies NGN = mustEnrollAsset(AssetSetting{AssetTypeFiat, "NGN", "", "", true}) // Nigerian Naira (NGN) TRY = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.TRY.String(), "", "", true}) // Turkish Lira, TRY(₺) // Additional common currencies BRL = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.BRL.String(), "", "", false}) // Brazilian Real (R$) CNY = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.CNY.String(), "", "", false}) // Chinese Yuan (CN¥) DKK = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.DKK.String(), "", "", false}) // Danish Krone (DKK) INR = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.INR.String(), "", "", false}) // Indian Rupee (Rs.) RUB = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.RUB.String(), "", "", false}) // Russian Ruble (RUB) HKD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.HKD.String(), "", "", false}) // Hong Kong Dollar (HK$) IDR = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.IDR.String(), "", "", false}) // Indonesian Rupiah (IDR) KRW = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.KRW.String(), "", "", false}) // South Korean Won (₩) MXN = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.MXN.String(), "", "", false}) // Mexican Peso (MX$) PLN = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.PLN.String(), "", "", false}) // Polish Zloty (PLN) SAR = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.SAR.String(), "", "", false}) // Saudi Riyal (SAR) THB = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.THB.String(), "", "", false}) // Thai Baht (฿) TWD = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.TWD.String(), "", "", false}) // New Taiwan dollar, TWD (NT$) ZAR = mustEnrollAsset(AssetSetting{AssetTypeFiat, currency.ZAR.String(), "", "", false}) // South African Rand (ZAR) // precious metal XAU = mustEnrollAsset(AssetSetting{AssetTypeMetal, "xau", "", "", false}) // gold XAG = mustEnrollAsset(AssetSetting{AssetTypeMetal, "xag", "", "", false}) // silver XPT = mustEnrollAsset(AssetSetting{AssetTypeMetal, "xpt", "", "", false}) // platinum XPD = mustEnrollAsset(AssetSetting{AssetTypeMetal, "xpd", "", "", false}) // Palladium )
famous assets
var ( // https://www.blockchain.com/btc/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f BTCGenesisBlockTime = time.Date(2009, 1, 3, 18, 15, 5, 0, time.UTC) BTCGenesisBlockDate = gtime.TimeToDate(BTCGenesisBlockTime, time.UTC) )
var ( KlineDeepCopy = false // if set it true, will cost about 2.5x time than false KInternalExprs = []string{ExprOpen, ExprHigh, ExprLow, ExprClose, ExprVolume} )
var ( ErrFunctionNotSupported = gerrors.Errorf("function not supported") AllSupportedExs = []Platform{Binance} )
var (
IndexDJI, _ = NewAsset("i.dji") // Dow Jones Industrial Average (^DJI)
IndexSP, _ = NewAsset("i.sp") // S&P 500 (^GSPC)
IndexIXIC, _ = NewAsset("i.ixic") // NASDAQ Composite (^IXIC)
IndexNYA, _ = NewAsset("i.nya") // NYSE Composite (^NYA)
IndexRUT, _ = NewAsset("i.rut") // Russell 2000 (^RUT)
IndexVIX, _ = NewAsset("i.vix") // CBOE Volatility Index (^VIX)
IndexSHH, _ = NewAsset("i.shh") // SSE Composite Index (000001.SS), 上证指数
)
var ( MarginError = Margin("") MarginNo = enrollNewMargin("no") // 无杠杆 MarginIsolated = enrollNewMargin("isolated") // 逐仓 MarginCross = enrollNewMargin("cross") // 全仓 )
var ( MarketError Market = "" MarketSpot = enrollNewMarket("spot") MarketFuture = enrollNewMarket("future") MarketPerp = enrollNewMarket("perp") // Perpetual Swap MarketOption = enrollNewMarket("option") )
var ( AllPeriods = []Period{ Period1Min, Period3Min, Period5Min, Period15Min, Period30Min, Period1Hour, Period2Hour, Period4Hour, Period6Hour, Period8Hour, Period12Hour, Period1Day, Period1Week, Period1MonthFUZZY, Period1YearFUZZY, } DefaultPeriodRoundConfig = PeriodRoundConfig{Location: *time.UTC, WeekBegin: time.Sunday, UseLocalZeroOClockAsDayBeginning: false} )
var (
NASDAQOpenDate, _ = gtime.NewDate(1971, 2, 4)
NYSEOpenDate, _ = gtime.NewDate(1817, 3, 8)
AMEXOpenDate, _ = gtime.NewDate(1971, 2, 8) // https://www.loc.gov/rr/business/amex/amex.html
SSEOpenDate, _ = gtime.NewDate(1990, 12, 19)
SZSEOpenDate, _ = gtime.NewDate(1991, 7, 3)
HKEXOpenDate, _ = gtime.NewDate(1891, 2, 3) // https://www.ximalaya.com/shangye/22958651/178058751
TwOpenDate, _ = gtime.NewDate(1962, 2, 9)
PlatformUnknown = Platform("")
PlatformOpen = enrollPlatform("open", PlatformInfo{Support: []AssetType{AssetTypeCoin, AssetTypeStock, AssetTypeIndex, AssetTypeMetal}, OpenDate: 0}) // fake platform for internet finance data like gold price
PlatformIndex = enrollPlatform("index", PlatformInfo{Support: []AssetType{AssetTypeCoin, AssetTypeStock, AssetTypeIndex, AssetTypeMetal}, OpenDate: 0}) // fake platform for all indexes
// 第三方金融数据平台
CryptoCompare = enrollPlatform("cryptocompare", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
DataHub = enrollPlatform("datahub", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
YahooFinance = enrollPlatform("yahoofinance", PlatformInfo{Support: []AssetType{AssetTypeCoin, AssetTypeStock}, OpenDate: 0})
GoogleFinance = enrollPlatform("googlefinance", PlatformInfo{Support: []AssetType{AssetTypeCoin, AssetTypeStock}, OpenDate: 0})
CoinMarketCap = enrollPlatform("coinmarketcap", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
CoinGecko = enrollPlatform("coingecko", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
// 国内加密货币市场
Binance = enrollPlatform("binance", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
Huobi = enrollPlatform("huobi", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
Okex = enrollPlatform("okex", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
Gate = enrollPlatform("gate", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
// 美国证券市场
Nasdaq = enrollPlatform("nasdaq", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: NASDAQOpenDate})
Nyse = enrollPlatform("nyse", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: NYSEOpenDate})
Amex = enrollPlatform("amex", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: AMEXOpenDate}) // belongs to NYSE now
// 中国期货市场
Shfe = enrollPlatform("shfe", PlatformInfo{Support: []AssetType{AssetTypeUnknown}, OpenDate: gtime.NewDatePanic(1990, 11, 26)}) // 上海期货交易所
Czce = enrollPlatform("czce", PlatformInfo{Support: []AssetType{AssetTypeUnknown}, OpenDate: gtime.NewDatePanic(1990, 10, 12)}) // 郑州商品交易所
Dce = enrollPlatform("dce", PlatformInfo{Support: []AssetType{AssetTypeUnknown}, OpenDate: gtime.NewDatePanic(1993, 2, 28)}) // 大连商品交易所
// 国外加密货币市场
Kraken = enrollPlatform("kraken", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
Deribit = enrollPlatform("deribit", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
UniSwap = enrollPlatform("uniswap", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
Ftx = enrollPlatform("ftx", PlatformInfo{Support: []AssetType{AssetTypeCoin}, OpenDate: 0})
// 中国证券市场
Szse = enrollPlatform("szse", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: SZSEOpenDate}) // Shen Zhen Stock Exchange
Sse = enrollPlatform("sse", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: SSEOpenDate}) // Shanghai Stock Exchange
Hkex = enrollPlatform("hkex", PlatformInfo{Support: []AssetType{AssetTypeStock}, OpenDate: HKEXOpenDate}) // Hong Kong Exchange
)
var (
AssetNil = Asset("")
)
var (
PricePiercing = gdecimal.NewFromInt(-1)
)
Functions ¶
func CurrencyCodesHistorical ¶
func CurrencyCodesNow ¶
func CurrencyGetSymbol ¶
Returns $ like UTF8 string
func CurrencyIsFiat ¶
func CurrencyIsMetal ¶
func CurrencyIsTest ¶
func CurrencyParse ¶
Support ISO currency name and symbol 注意,有些常见的Symbol是简化的不完整版本,会在多个法币的完整Symbol中出现,比如¥和$
func FindSamePairs ¶
find same Pairs between exchanges
func FixNameSymbol ¶
Fix error coin names like "Ethereum (ETH)" or "FileCoin [Future]", they are data source error.
func IsTradeSymbolFiat ¶
func NewPairExt ¶
func PairExtsEqual ¶
func PairExtsEqual(a []pairExt, b []pairExt) bool
func PairExtsInclude ¶
func PairExtsInclude(src []pairExt, find pairExt) bool
func PairExtsSort ¶
func PairExtsSort(src []pairExt)
func PairMPEqual ¶
func PairMPInclude ¶
func PairMPSort ¶
func PairMPSort(src []PairMP)
func ParsePairExtString ¶
TODO 也许需要提高性能
func RoundPeriodEarlier ¶
根据给定时间和周期值,计算它归属于哪个OpenTime的周期 get kline dot open time by dotTime
func SyncXAxis ¶
func SyncXAxis(ks1, ks2 *CandleSticks, fillIfNotExist Bar)
Types ¶
type Account ¶
type Account struct {
Balances []Balance
}
func NewEmptyAccount ¶
func NewEmptyAccount() *Account
func NewTestAccount ¶
func (*Account) AddAccount ¶
func (*Account) AddFree ¶
func (a *Account) AddFree(ap AssetProperty, toAdd gdecimal.Decimal)
增加余额,如果已经有相关条目就着做加法,如果没有则新增
func (*Account) ExchangeToUSD ¶
func (a *Account) ExchangeToUSD(ticks Ticks, ignorePairsNotFound bool) (*AssetAmount, error)
换算成USD 计算的用途是统计回报的相关指标
func (*Account) GetAmountByName ¶
func (a *Account) GetAmountByName(asset string) AssetAmount
根据资产名称获取总数量
func (*Account) GetAmountByProperty ¶
func (a *Account) GetAmountByProperty(ap AssetProperty) AssetAmount
根据资产属性(market、margin、名称等等)获取数量
func (*Account) JsonString ¶
func (*Account) RemoveZeroMembers ¶
func (a *Account) RemoveZeroMembers()
清除为0的成员,用于Transfer等操作之后清除没必要显示的成员
func (*Account) SetAmount ¶
func (a *Account) SetAmount(ap AssetProperty, amount AssetAmount)
upsert new balance item
func (*Account) SetFreeAmount ¶
func (a *Account) SetFreeAmount(ap AssetProperty, freeAmount gdecimal.Decimal)
upsert free amount
func (*Account) SetLockedAmount ¶
func (a *Account) SetLockedAmount(ap AssetProperty, lockedAmount gdecimal.Decimal)
upsert locked amount
type AccountAddress ¶
type AccountAddress string
example: buffett@gmail.com@binance
const (
AccountAddressNull AccountAddress = ""
)
func NewAccountAddress ¶
func NewAccountAddress(email string, platform Platform) AccountAddress
func ParseAccountAddress ¶
func ParseAccountAddress(s string) (AccountAddress, error)
func (AccountAddress) Email ¶
func (tai AccountAddress) Email() string
func (AccountAddress) MarshalJSON ¶
func (tai AccountAddress) MarshalJSON() ([]byte, error)
func (AccountAddress) Platform ¶
func (tai AccountAddress) Platform() Platform
func (AccountAddress) String ¶
func (tai AccountAddress) String() string
func (*AccountAddress) UnmarshalJSON ¶
func (tai *AccountAddress) UnmarshalJSON(b []byte) error
type AccountSnapshot ¶
type AccountSnapshot struct { Time time.Time Asset Asset `json:"Asset, omitempty"` // 计算Total时用的的Fiat,通常是USD Total AssetAmount // 统计得来的法币总值,用于回测计算收益指标等 Detail Account }
func (*AccountSnapshot) Add ¶
func (as *AccountSnapshot) Add(toAdd AccountSnapshot)
type Asset ¶
type Asset string
func AllIndexes ¶
func AllIndexes() []Asset
func AllQuoteAssets ¶
func AllQuoteAssets() []Asset
func AllQuoteCoins ¶
func AllQuoteCoins() []Asset
func AllStableCoins ¶
func AllStableCoins() []Asset
func NewCoinWithSymbol ¶
func ParseFiat ¶
Support ISO currency name and symbol 注意,有些常见的Symbol是简化的不完整版本,会在多个法币的完整Symbol中出现,比如¥和$
func StableCoinsByFiat ¶
func (Asset) MarshalJSON ¶
func (Asset) TradeSymbol ¶
Trade symbol of assets, in fiat Trade Symbol is Name but not symbol
func (*Asset) UnmarshalJSON ¶
type AssetAmount ¶
type AssetAmount struct { // 沿用现货的成员 Free gdecimal.Decimal `json:"Free"` // available,可操作买卖,但不一定可以提现 Locked gdecimal.Decimal `json:"Locked"` // Borrowed gdecimal.Decimal `json:"Borrowed"` // to repay, only available in margin account Interest gdecimal.Decimal `json:"Interest"` // only available in margin account }
资产数量
func (*AssetAmount) Add ¶
func (b *AssetAmount) Add(toAdd AssetAmount)
type AssetProperty ¶
type AssetProperty struct { Market Market // 属于哪个市场 Margin Margin CustomSubAccName string // 自定义子账户名称 Asset string }
资产属性
type AssetSetting ¶
type Balance ¶
type Balance struct { AssetProperty // 资产属性 AssetAmount // 资产数量 BorrowHist []Borrow // 现货杠杆才有,用于回测 }
余额记录,一个特定市场特定杠杆类型下特定资产对应一个BTBalance
func (*Balance) AssetPropertyEquals ¶
func (b *Balance) AssetPropertyEquals(ap AssetProperty) bool
func (*Balance) BorrowedByHist ¶
func (*Balance) InterestByHist ¶
func (*Balance) VerifyAssetProperty ¶
func (b *Balance) VerifyAssetProperty(ap AssetProperty) error
验证资产种类,如果Market、Margin、CustomSubAccName、Asset不同则返回错误
type Bar ¶
type Bar struct { T time.Time `json:"_id" bson:"_id" csv:"_id"` // Statistic begin time. O gdecimal.Decimal `json:"O,omitempty" bson:"O,omitempty" csv:"O,omitempty"` // Open price. L gdecimal.Decimal `json:"L,omitempty" bson:"L,omitempty" csv:"L,omitempty"` // Lowest price. H gdecimal.Decimal `json:"H,omitempty" bson:"H,omitempty" csv:"H,omitempty"` // Highest price. C gdecimal.Decimal `json:"C,omitempty" bson:"C,omitempty" csv:"C,omitempty"` // Close price. V gdecimal.Decimal `json:"V,omitempty" bson:"V,omitempty" csv:"V,omitempty"` // Volume in unit asset, always. It is 'BTC' in 'BTC/USD' pair. E *time.Time `json:"E,omitempty" bson:"E,omitempty" csv:"E,omitempty"` // Close time, it is useful in last entry in candle sticks. Indicators map[string]float64 `json:"Indicators,omitempty" bson:"Indicators,omitempty" csv:"Indicators,omitempty"` }
type CandleSticks ¶
type CandleSticks struct { Pair PairIMP // 原始K线的周期 Items []Bar // 原始K线数据 // contains filtered or unexported fields }
Bar items for Global
func NewAndCopyBasicInfo ¶
func NewAndCopyBasicInfo(src *CandleSticks) *CandleSticks
func NewKline ¶
func NewKline(pair PairIMP, dots []Bar) *CandleSticks
func (*CandleSticks) AcrossDays ¶
func (k *CandleSticks) AcrossDays() float64
func (*CandleSticks) BeforeEqualClosest ¶
func (k *CandleSticks) BeforeEqualClosest(tm time.Time) (item *Bar, exists bool)
TODO 用sort.Search改造? 找出在指定时间tm之前,且与tm时间间隔最小的Kline条目
func (*CandleSticks) CleanHMS ¶
func (k *CandleSticks) CleanHMS(loc *time.Location) *CandleSticks
func (*CandleSticks) Clone ¶
func (k *CandleSticks) Clone() *CandleSticks
todo: test required note: 使用 nk := *k; return nk 这样是无法深度拷贝k的
func (*CandleSticks) Close ¶
func (k *CandleSticks) Close(i int) float64
func (*CandleSticks) CloseValues ¶
func (k *CandleSticks) CloseValues() []float64
func (*CandleSticks) Closes ¶
func (k *CandleSticks) Closes() []gdecimal.Decimal
func (*CandleSticks) DetectPeriod ¶
func (k *CandleSticks) DetectPeriod() Period
func (*CandleSticks) ExprValues ¶
func (k *CandleSticks) ExprValues(expr string) ([]float64, error)
func (*CandleSticks) Exprs ¶
func (k *CandleSticks) Exprs() []string
func (*CandleSticks) ExprsOfIndExpr ¶
func (k *CandleSticks) ExprsOfIndExpr(ie ta.IndExpr) []string
是否有指标表达式的值,比如Kline中有MACD(12,9,3).Mid,ie=MACD(12,9,3),那么就返回true
func (*CandleSticks) First ¶
func (k *CandleSticks) First() (Bar, bool)
func (*CandleSticks) FirstTime ¶
func (k *CandleSticks) FirstTime(defIfEmpty time.Time) time.Time
First T
func (*CandleSticks) FirstTimeEx ¶
func (k *CandleSticks) FirstTimeEx() (last *time.Time, exists bool)
Min time in records
func (*CandleSticks) GetDoc ¶
func (k *CandleSticks) GetDoc(i int) TimeDoc
func (*CandleSticks) GetName ¶
func (k *CandleSticks) GetName() string
func (*CandleSticks) HasDuplicatedKeys ¶
func (k *CandleSticks) HasDuplicatedKeys() ([]time.Time, bool)
func (*CandleSticks) HasExpr ¶
func (k *CandleSticks) HasExpr(expr string) bool
func (*CandleSticks) High ¶
func (k *CandleSticks) High(i int) float64
func (*CandleSticks) HighValues ¶
func (k *CandleSticks) HighValues() []float64
func (*CandleSticks) Highs ¶
func (k *CandleSticks) Highs() []gdecimal.Decimal
func (*CandleSticks) IndexEqual ¶
search index whose T == t
func (*CandleSticks) IndicatorExps ¶
func (k *CandleSticks) IndicatorExps() []string
func (*CandleSticks) IsConsequentDayLine ¶
func (k *CandleSticks) IsConsequentDayLine() bool
func (*CandleSticks) IsTimeOverlappingAreaEqual ¶
func (k *CandleSticks) IsTimeOverlappingAreaEqual(cmp *CandleSticks) (equal bool)
compare data of same timestamp items, time different items between them are ignored
func (*CandleSticks) Last ¶
func (k *CandleSticks) Last() (Bar, bool)
func (*CandleSticks) LastClose ¶
func (k *CandleSticks) LastClose(defIfEmpty gdecimal.Decimal) gdecimal.Decimal
func (*CandleSticks) LastCloseTime ¶
func (k *CandleSticks) LastCloseTime(defTime time.Time) time.Time
最后一根Bar的收线时间,用于判断最后一根线是否及时,尤其是K线周期比较大时,这个数据可以表示最后一根Bar的时效性 如果没有记录E,则使用T代替E
func (*CandleSticks) LastExprValue ¶
func (k *CandleSticks) LastExprValue(expr string) (float64, error)
func (*CandleSticks) LastExprs ¶
func (k *CandleSticks) LastExprs() []string
func (*CandleSticks) LastLow ¶
func (k *CandleSticks) LastLow(defIfEmpty gdecimal.Decimal) gdecimal.Decimal
func (*CandleSticks) LastTime ¶
func (k *CandleSticks) LastTime(defIfEmpty time.Time) time.Time
Last open time T
func (*CandleSticks) LastTimeEx ¶
func (k *CandleSticks) LastTimeEx() (last *time.Time, exists bool)
Max time in records
func (*CandleSticks) Len ¶
func (k *CandleSticks) Len() int
func (*CandleSticks) Less ¶
func (k *CandleSticks) Less(i, j int) bool
func (*CandleSticks) Low ¶
func (k *CandleSticks) Low(i int) float64
func (*CandleSticks) LowValues ¶
func (k *CandleSticks) LowValues() []float64
func (*CandleSticks) Lows ¶
func (k *CandleSticks) Lows() []gdecimal.Decimal
func (*CandleSticks) MaxIndex ¶
func (k *CandleSticks) MaxIndex() int
func (*CandleSticks) MaxIndexLT ¶
func (k *CandleSticks) MaxIndexLT(t time.Time) int
search max index whose T < t, index whose T == t is NOT included
func (*CandleSticks) MaxIndexLTE ¶
func (k *CandleSticks) MaxIndexLTE(t time.Time) int
TODO test required search max index whose T <= t, index whose T == t is included
func (*CandleSticks) Merge ¶
func (k *CandleSticks) Merge() Bar
func (*CandleSticks) MinIndexGT ¶
func (k *CandleSticks) MinIndexGT(t time.Time) int
search min index whose T > t, index whose T == t is NOT included
func (*CandleSticks) MinIndexGTE ¶
func (k *CandleSticks) MinIndexGTE(t time.Time) int
search min index whose T is >= t, index whose T == t is included if result <= k.Len() - 1 && k.items[result].T == t, there is a dot whose time is t otherwise not found, but result still means which index is mostly close to t
func (*CandleSticks) Open ¶
func (k *CandleSticks) Open(i int) float64
func (*CandleSticks) OpenValues ¶
func (k *CandleSticks) OpenValues() []float64
func (*CandleSticks) Opens ¶
func (k *CandleSticks) Opens() []gdecimal.Decimal
func (*CandleSticks) RemoveTail ¶
func (k *CandleSticks) RemoveTail(n int) *CandleSticks
func (*CandleSticks) Set ¶
func (k *CandleSticks) Set(newKs *CandleSticks)
func (*CandleSticks) SetIndicatorValue ¶
func (*CandleSticks) SliceAfter ¶
func (k *CandleSticks) SliceAfter(gt time.Time) *CandleSticks
select item which time before 'lte'
func (*CandleSticks) SliceAfterEqual ¶
func (k *CandleSticks) SliceAfterEqual(gte time.Time) *CandleSticks
select item which time before or equal 'lte'
func (*CandleSticks) SliceBefore ¶
func (k *CandleSticks) SliceBefore(lt time.Time) *CandleSticks
TODO: test required select item which time before or equal 'lte'
func (*CandleSticks) SliceBeforeEqual ¶
func (k *CandleSticks) SliceBeforeEqual(lte time.Time) *CandleSticks
TODO: test required select item which time before or equal 'lte'
func (*CandleSticks) SliceBetween ¶
func (k *CandleSticks) SliceBetween(gt, lt time.Time) *CandleSticks
TODO test required fixme 有问题
func (*CandleSticks) SliceBetweenEqual ¶
func (k *CandleSticks) SliceBetweenEqual(gte, lte time.Time) *CandleSticks
TODO test required
func (*CandleSticks) SliceBetweenId ¶
func (k *CandleSticks) SliceBetweenId(gte, lte int) *CandleSticks
func (*CandleSticks) SliceHead ¶
func (k *CandleSticks) SliceHead(n int) *CandleSticks
func (*CandleSticks) SliceTail ¶
func (k *CandleSticks) SliceTail(n int) *CandleSticks
func (*CandleSticks) Sort ¶
func (k *CandleSticks) Sort()
func (*CandleSticks) SortClose ¶
func (k *CandleSticks) SortClose()
func (*CandleSticks) SortCloseReverse ¶
func (k *CandleSticks) SortCloseReverse()
func (*CandleSticks) SortHigh ¶
func (k *CandleSticks) SortHigh()
func (*CandleSticks) SortHighReverse ¶
func (k *CandleSticks) SortHighReverse()
func (*CandleSticks) SortLow ¶
func (k *CandleSticks) SortLow()
func (*CandleSticks) SortLowReverse ¶
func (k *CandleSticks) SortLowReverse()
func (*CandleSticks) SortOpen ¶
func (k *CandleSticks) SortOpen()
func (*CandleSticks) SortOpenReverse ¶
func (k *CandleSticks) SortOpenReverse()
func (*CandleSticks) String ¶
func (k *CandleSticks) String() string
func (*CandleSticks) Swap ¶
func (k *CandleSticks) Swap(i, j int)
func (*CandleSticks) TA ¶
func (k *CandleSticks) TA() *KTA
func (*CandleSticks) Time ¶
func (k *CandleSticks) Time(i int) time.Time
implement TimeSeries and Series(in github.com/iwat) interface
func (*CandleSticks) TimeOverlappingArea ¶
func (k *CandleSticks) TimeOverlappingArea(cmp *CandleSticks) (exist bool, begin, end time.Time)
func (*CandleSticks) Times ¶
func (k *CandleSticks) Times() []time.Time
func (*CandleSticks) ToBar ¶
func (k *CandleSticks) ToBar() Bar
func (*CandleSticks) ToChartTemplate ¶
func (k *CandleSticks) ToChartTemplate(indExprs ...string) (*ghtml.ChartTemplate, error)
TODO: test required 转换为chart模板,方便绘图
func (*CandleSticks) ToPeriod ¶
func (k *CandleSticks) ToPeriod(newPeriod Period, config PeriodRoundConfig) (*CandleSticks, error)
转换周期,但不缓存转换之后的数据 NOTE: 如果交易所中间维护,中间空缺的数据会被忽略,而不是填充空数据 FIXME: 如果最后一个周期数据尚未Close,那最后一根线会画出来吗?
func (*CandleSticks) ToPeriodPartly ¶
func (k *CandleSticks) ToPeriodPartly(lastConverted *CandleSticks, newPeriod Period, config PeriodRoundConfig) error
局部周期转换,只转换lastConverted的最后一个时间(包含)往后的数据 lastConverted is input and output config TODO: test required
func (*CandleSticks) ToPeriodWithTail ¶
func (k *CandleSticks) ToPeriodWithTail(newPeriod Period, config PeriodRoundConfig, tail int) (*CandleSticks, error)
just convert last tail dots in newPeriod
func (*CandleSticks) Upsert ¶
func (k *CandleSticks) Upsert(toUpsert *CandleSticks)
func (*CandleSticks) UpsertDot ¶
func (k *CandleSticks) UpsertDot(dot Bar)
func (*CandleSticks) Volume ¶
func (k *CandleSticks) Volume(i int) float64
func (*CandleSticks) VolumeValues ¶
func (k *CandleSticks) VolumeValues() []float64
func (*CandleSticks) Volumes ¶
func (k *CandleSticks) Volumes() []gdecimal.Decimal
type CandleSticksConverter ¶
type CandleSticksConverter struct {
// contains filtered or unexported fields
}
type CustomPairParse ¶
type Depth ¶
type Depth struct { Time time.Time `json:"T"` // T DepthRawData }
Depth = open order books.
func (*Depth) MarketBuyDetect ¶
func (d *Depth) MarketBuyDetect(quoteAmount gdecimal.Decimal) DepthTolerance
拉盘探测,能拉多高
func (*Depth) MarketBuyDetectEx ¶
func (d *Depth) MarketBuyDetectEx(quoteAmount gdecimal.Decimal, slippageAllowed gdecimal.Decimal, precision int, lot gdecimal.Decimal) DepthTolerance
拉盘探测,能拉多高 note: 如果不给出Prec,可能导致模拟成交的时候由于除法除不尽导致结果不精确而稍稍大于绝对精确值的情况,从而产生连锁反应 FIXME: precision 确定一下是unit的precision吗,同理也给marketSell确认一下
func (*Depth) MarketSellDetect ¶
func (d *Depth) MarketSellDetect(unitAmount gdecimal.Decimal) DepthTolerance
砸盘探测,能砸多深
func (*Depth) MarketSellDetectEx ¶
func (d *Depth) MarketSellDetectEx(unitAmount, slippageAllowed gdecimal.Decimal) DepthTolerance
砸盘探测,能砸多深
func (*Depth) ParseBuyOnePrice ¶
func (*Depth) ParseBuyerTotal ¶
func (*Depth) ParseSellOnePrice ¶
func (*Depth) ParseSellerTotal ¶
type DepthRawData ¶
type DepthRawData struct { Sells OrderBookList `json:"Sells"` // Asks Buys OrderBookList `json:"Buys"` // Bids }
Raw depth data without timestamp. Useful in remake new Depth like struct.
func (*DepthRawData) Equal ¶
func (drd *DepthRawData) Equal(cmp *DepthRawData) bool
func (*DepthRawData) GetMaxBuy ¶
func (drd *DepthRawData) GetMaxBuy() (price, amount gdecimal.Decimal, err error)
func (*DepthRawData) GetMinSell ¶
func (drd *DepthRawData) GetMinSell() (price, amount gdecimal.Decimal, err error)
type DepthTolerance ¶
type DepthTolerance struct { UnitDealAmount gdecimal.Decimal QuoteDealAmount gdecimal.Decimal Price1 gdecimal.Decimal PriceReach gdecimal.Decimal // 上/下探价格, -1 means 击穿 }
盘口承受力
func (*DepthTolerance) Equal ¶
func (dt *DepthTolerance) Equal(cmp DepthTolerance) bool
func (*DepthTolerance) Verify ¶
func (dt *DepthTolerance) Verify() error
verify price and unit amount
type ExProperty ¶
type ExProperty struct { Name Platform Email string // optional MaxDepth int MaxFills int IgnorePairs []string // custom step 1, ignore invalid/test pairs CustomToStdPairs map[string]Pair // custom step 2, hard to parse special pairs: like [USDTCHF]:USDT/CHF CustomPairParse CustomPairParse // custom step 3 Periods map[Period]string OrderStatus map[OrderStatus]string OrderTypes map[OrderType]string OrderSides map[OrderSide]string RateLimits map[ExApi]time.Duration MarketEnabled map[Market]bool Clock gtime.Clock IsBackTestEx bool TradeBeginTime time.Time BarCountLimitSinceNow *int // how many bar provided by exchange since now, if it is nil means no limit -- you can get first bar from exchange open }
PairDelimiter string // pair separator PairDelimiterLeftTail []string PairDelimiterRightHead []string PairNormalOrder bool // whether is ISO order —— unit first quote second PairUpperCase bool PairsSeparator string // separator between multiple pairs in api request CustomPairPreCrop CustomPairPreCrop // custom step 3 StdToCustomHeadTailMap map[string]string // custom step 4, [StdSym]CustomSym like: BTC
func (ExProperty) MinPeriod ¶
func (cc ExProperty) MinPeriod() Period
func (ExProperty) SupportedPeriods ¶
func (cc ExProperty) SupportedPeriods() []Period
type Fill ¶
type Fill struct { Id int64 `json:"Id" bson:"_id"` Time time.Time `json:"T" bson:"T"` Price gdecimal.Decimal `json:"Price" bson:"Price"` UnitQty gdecimal.Decimal `json:"UnitQty" bson:"UnitQty"` Side string `json:"Side" bson:"Side"` // "buy", "sell", "auction"... }
QuoteQty decimals.Decimal `json:"QuoteQty" bson:"QuoteQty"` BuyerMaker bool `json:"BuyerMaker" bson:"BuyerMaker"` // binance use it only
type FillOption ¶
type FillOption struct { BeginTime time.Time TimeDuration time.Duration BeginId int64 IdLimit int64 }
func (FillOption) VerifyBinance ¶
func (fo FillOption) VerifyBinance() error
type HighlyRelevant ¶
type HighlyRelevant struct {
Items []PairMP
}
type Irrelevant ¶
type Irrelevant struct {
Lows []LowlyRelevant
}
type KTA ¶
type KTA CandleSticks
func (*KTA) CleanupIndicators ¶
func (kta *KTA) CleanupIndicators()
func (*KTA) FirstHeavyVolumePriceRose ¶
func (kta *KTA) FirstHeavyVolumePriceRose(gt time.Time, pricePercent float64, volumeCmpDays int, lowGt *float64) (Bar, bool)
从前往后找放量上涨 pricePercent 价格上涨幅度 volumeCmpDays 成交量大于之前多少天 lowGt low价必须大于这个值,相当于给出一条最低线,忽略低于这条线的大阳线
func (*KTA) K ¶
func (kta *KTA) K() *CandleSticks
func (*KTA) LastDirReversalExprValue ¶
最后一个方向反转处的某表达式的值 适用于Donchian Channel
func (*KTA) LastHeavyVolumePriceRose ¶
func (kta *KTA) LastHeavyVolumePriceRose(gt time.Time, pricePercent float64, volumeCmpDays int) (Bar, bool)
从后往前找放量上涨 pricePercent 价格上涨幅度 volumeCmpDays 成交量大于之前多少天
func (*KTA) ReverseCrosses ¶
从后往前 exp1: slow expression exp2: fast expression n: how much cross do you want, n <= 0: ignore it
func (*KTA) UpdateIndicators ¶
NOTE: 能否把已经计算过的缓存起来?很难,因为有些指数是和之前的值相关联的,你无法核实之前的值是否改动过
type KlineProviderInfo ¶
type Leverage ¶
type Leverage struct { BuySideFixed []gdecimal.Decimal BuySideSmoothMinStepMax []gdecimal.Decimal SellSideFixed []gdecimal.Decimal SellSideSmoothMinStepMax []gdecimal.Decimal }
func (*Leverage) BuySideMaxLeverage ¶
func (*Leverage) SellSideMaxLeverage ¶
func (*Leverage) SetFixedFloat64 ¶
func (*Leverage) SetSmoothFloat64 ¶
func (*Leverage) SupportLeverage ¶
type LowlyRelevant ¶
type LowlyRelevant struct {
Mids []ModeratelyRelevant
}
type MarketInfo ¶
func (*MarketInfo) AvailableSymbols ¶
func (mi *MarketInfo) AvailableSymbols() []string
func (*MarketInfo) GetMakerFee ¶
func (mi *MarketInfo) GetMakerFee(pm PairM) (gdecimal.Decimal, bool)
func (*MarketInfo) GetTakerFee ¶
func (mi *MarketInfo) GetTakerFee(pm PairM) (gdecimal.Decimal, bool)
func (*MarketInfo) PairIMPs ¶
func (mi *MarketInfo) PairIMPs(period Period, platform Platform) []PairIMP
func (*MarketInfo) PairMs ¶
func (mi *MarketInfo) PairMs() []PairM
func (*MarketInfo) Pairs ¶
func (mi *MarketInfo) Pairs() []Pair
all trading pairs, if some pair exist in different markets(spot,margin...), only one be kept
func (*MarketInfo) PairsAllowedFilter ¶
func (mi *MarketInfo) PairsAllowedFilter(allowedSymbols []string) []Pair
func (*MarketInfo) PairsIncludeFilter ¶
func (mi *MarketInfo) PairsIncludeFilter(includeSymbols []string, excludeSymbols []string) []Pair
func (*MarketInfo) SupportMargin ¶
func (mi *MarketInfo) SupportMargin(pair Pair) bool
func (*MarketInfo) Verify ¶
func (mi *MarketInfo) Verify() error
type ModeratelyRelevant ¶
type ModeratelyRelevant struct {
Highs []HighlyRelevant
}
type Order ¶
type Order struct { Id OrderId Time time.Time Market Market Margin Margin Leverage int // FIXME change to decimal Pair Pair Side OrderSide Type OrderType Status OrderStatus StopPrice gdecimal.Decimal // 止盈止损触发价,限价单才有 FIXME 如果该用*会导致程序崩溃 Price gdecimal.Decimal Amount gdecimal.Decimal // initial total amount in unit, unit always AvgPrice gdecimal.Decimal // Binance貌似不提供AvgPrice DealAmount gdecimal.Decimal // filled amount in unit, NOT quote,PaperEx在撮合的时候是这么理解的,如果以后要改,也要修正paperEx Fee gdecimal.Decimal // Binance貌似不提供Fee }
type OrderBook ¶
type OrderBookList ¶
type OrderBookList []OrderBook
func (OrderBookList) Len ¶
func (obl OrderBookList) Len() int
func (OrderBookList) Less ¶
func (obl OrderBookList) Less(i, j int) bool
func (OrderBookList) Swap ¶
func (obl OrderBookList) Swap(i, j int)
type OrderSide ¶
type OrderSide string
func (OrderSide) CustomFormat ¶
func (tt OrderSide) CustomFormat(config *ExProperty) string
type OrderStatus ¶
type OrderStatus string
func (OrderStatus) String ¶
func (ts OrderStatus) String() string
type OrderType ¶
type OrderType string
func (OrderType) CustomFormat ¶
func (tt OrderType) CustomFormat(config *ExProperty) string
func (OrderType) IsStopLimit ¶
Is stop loss limit or take profit limit order. On the front page of some platforms, there is no distinction between 'stop loss limit' and 'take profit limit', but rather a 'stop limit' order to express.
type Pair ¶
type Pair string // BTC/USDT
TODO test pairExt
func ParsePairCustom ¶
func ParsePairCustom(s string, config *ExProperty) (Pair, error)
func (Pair) MarshalJSON ¶
type PairIMP ¶
type PairIMP string // Pair with Interval, Market & Platform
TODO test pairExt
func ParsePairIMP ¶
type PairInfo ¶
type PairInfo struct { // spot only Enabled bool UnitPrecision int // precision of unit amount? No, seems useless QuotePrecision int // precision of quote price? No, seems useless UnitMin gdecimal.Decimal // unit min trade amount, mostly it is the same as LostStep UnitStep gdecimal.Decimal // unit min step amount, min trade amount in unit, same as amount in SetPosition() QuoteStep gdecimal.Decimal // quote min movement // shared Leverage Leverage MarginIsolatedEnabled bool MarginCrossEnabled bool MakerFee gdecimal.Decimal // fee of depth maker, 挂单等吃费率 TakerFee gdecimal.Decimal // fee of depth taker, 主动吃单费率 // contract only MaintMarginPercent gdecimal.Decimal RequiredMarginPercent gdecimal.Decimal }
币安的永续合约说明,可以辅助完善PairInfo https://binance.zendesk.com/hc/zh-cn/articles/360033161972-%E5%90%88%E7%BA%A6%E7%BB%86%E5%88%99 MinNotional decimals.Decimal // notional = price * amount
type Pattern ¶
type Pattern struct { PatternLHS PatternRHS }
type PatternLHS ¶
type PatternLHS struct {
Forms [3]KForm
}
type PatternRHS ¶
type Patterns ¶
type Patterns struct {
Items map[PatternLHS]PatternRHS
}
func NewPatterns ¶
func NewPatterns() *Patterns
func (*Patterns) MaxLongTimes ¶
func (*Patterns) MaxShockTimes ¶
func (*Patterns) MaxShortTimes ¶
type Period ¶
type Period string
const ( PeriodError Period = "" Period1Min Period = "1min" Period3Min Period = "3min" Period5Min Period = "5min" Period15Min Period = "15min" Period30Min Period = "30min" Period1Hour Period = "1hour" Period2Hour Period = "2hour" Period4Hour Period = "4hour" Period6Hour Period = "6hour" Period8Hour Period = "8hour" Period12Hour Period = "12hour" Period1Day Period = "1day" Period1Week Period = "1week" Period1MonthFUZZY Period = "1mon" Period1YearFUZZY Period = "1year" )
func DurationToPeriod ¶
func ParsePeriod ¶
func (Period) CustomFormat ¶
func (p Period) CustomFormat(config *ExProperty) (string, error)
func (Period) MarshalJSON ¶
func (Period) ToDuration ¶
func (Period) ToDurationExact ¶
对于Period1MonthFUZZY和Period1YearFUZZY也能精确计算
func (*Period) UnmarshalJSON ¶
type PeriodRoundConfig ¶
type PeriodRoundConfig struct { Location time.Location // FIXME 按下面的说法是不是不需要Location? WeekBegin time.Weekday // 本身time.Round是和时区无关的,都是依据UTC进行Round的,但是金融市场中根据Period进行RoundPeriod时,某些Period(周)就需要参考时区了,同一时刻不同时区可能属于不同的Weekday // 当然,如果偏要以当地时间的0点作为Round的起点,那么就要把UseLocalZeroOClockAsDayBeginning设置为true // 以2019-09-01 09:00:00 +0800 CST 为例,Round24小时,标准结果应该等于2019-09-01 08:00:00 +0800 CST,这个是Go标准库的执行结果 // 要遵循Go标准库time.Round的思路,就需要把UseLocalZeroOClockAsDayBeginning设置为false UseLocalZeroOClockAsDayBeginning bool // false: use UTC zero clock }
func (PeriodRoundConfig) String ¶
func (cc PeriodRoundConfig) String() string
type Platform ¶
type Platform string
func AllStockExchanges ¶
func AllStockExchanges() []Platform
func ParsePlatform ¶
func (*Platform) Info ¶
func (p *Platform) Info() PlatformInfo
func (Platform) IsSupported ¶
Check whether supported exchange or n ot.
func (Platform) MarshalJSON ¶
func (*Platform) UnmarshalJSON ¶
type PlatformInfo ¶
type Portfolio ¶
type Portfolio struct { RelevantSet *Irrelevant `json:"RelevantSet,omitempty"` DirectSet []PairMP `json:"DirectSet,omitempty"` }
type SubAcc ¶
type SubAcc string
* 子账户
SubAcc的形式: ::spot:: ::spot::cross customSubAcc::spot::cross
func (SubAcc) Parse ¶
func (sa SubAcc) Parse() (sap SubAccParsed, err error)
type SubAccParsed ¶
* 子账户
SubAcc的形式: ::spot:: ::spot::cross customSubAcc::spot::cross
func ParseSubAcc ¶
func ParseSubAcc(s string) (sap SubAccParsed, err error)
type TACross ¶
func TACrossesSort ¶
type Tick ¶
type Tick struct { Time time.Time `json:"time"` Last gdecimal.Decimal `json:"last"` // 最新成交价, binance has Last only Buy gdecimal.Decimal `json:"buy"` // 买一价 Sell gdecimal.Decimal `json:"sell"` // 卖一价 High gdecimal.Decimal `json:"high"` // 最高价 Low gdecimal.Decimal `json:"low"` // 最低价 Volume gdecimal.Decimal `json:"vol"` // 最近的24小时成交量 }
In some exchange, it won't return H/L/V, even returns T & Last only, like binance They will be filled with -1
type Ticks ¶
In some exchange, it won't return H/L/V, even returns T & Last only, like binance They will be filled with -1
func TicksToPrices ¶
type TimeSeries ¶
type TradeIncome ¶
type TradeIncome string
type TradeIntent ¶
type TradeIntent string // 交易意图
Source Files ¶
- account.go
- account_address.go
- account_subacc.go
- assets.go
- assets_const.go
- balance.go
- blockchain.go
- candlestick.go
- candlestick_provider.go
- candlestick_ta.go
- candlesticks.go
- coin.go
- currency.go
- depth.go
- ex_config.go
- fiat.go
- fill.go
- index.go
- leverage.go
- margin.go
- market.go
- market_info.go
- order.go
- pair.go
- period.go
- platform.go
- portfolio.go
- since.go
- tick.go
- time_series.go