Documentation
¶
Index ¶
- Constants
- Variables
- func SideToColorName(side SideType) string
- type Account
- func (a *Account) AddBalance(currency string, fund fixedpoint.Value) error
- func (a *Account) Balance(currency string) (balance Balance, ok bool)
- func (a *Account) Balances() BalanceMap
- func (a *Account) BindStream(stream Stream)
- func (a *Account) LockBalance(currency string, locked fixedpoint.Value) error
- func (a *Account) Print()
- func (a *Account) UnlockBalance(currency string, unlocked fixedpoint.Value) error
- func (a *Account) UpdateBalances(balances BalanceMap)
- func (a *Account) UseLockedBalance(currency string, fund fixedpoint.Value) error
- type Asset
- type AssetMap
- type Balance
- type BalanceMap
- type Channel
- type Deposit
- type DepositStatus
- type Direction
- type Duration
- type Exchange
- type ExchangeMarketDataService
- type ExchangeName
- type ExchangeRewardService
- type ExchangeTradingService
- type ExchangeTransferService
- type Interval
- type IntervalSlice
- type IntervalWindow
- type IsolatedMarginAccount
- type IsolatedMarginAsset
- type IsolatedUserAsset
- type KLine
- func (k KLine) BounceDown() bool
- func (k KLine) BounceUp() bool
- func (k KLine) Color() string
- func (k KLine) Direction() Direction
- func (k KLine) GetBody() float64
- func (k KLine) GetChange() float64
- func (k KLine) GetClose() float64
- func (k KLine) GetEndTime() time.Time
- func (k KLine) GetHigh() float64
- func (k KLine) GetInterval() Interval
- func (k KLine) GetLow() float64
- func (k KLine) GetLowerShadowHeight() float64
- func (k KLine) GetLowerShadowRatio() float64
- func (k KLine) GetMaxChange() float64
- func (k KLine) GetOpen() float64
- func (k KLine) GetStartTime() time.Time
- func (k KLine) GetThickness() float64
- func (k KLine) GetUpperShadowHeight() float64
- func (k KLine) GetUpperShadowRatio() float64
- func (k KLine) Mid() float64
- func (k KLine) SlackAttachment() slack.Attachment
- func (k KLine) String() string
- type KLineCallback
- type KLineOrWindow
- type KLineQueryOptions
- type KLineWindow
- func (k *KLineWindow) Add(line KLine)
- func (k KLineWindow) AllDrop() bool
- func (k KLineWindow) AllRise() bool
- func (k KLineWindow) BounceDown() bool
- func (k KLineWindow) BounceUp() bool
- func (k KLineWindow) Color() string
- func (k KLineWindow) First() KLine
- func (k KLineWindow) GetBody() float64
- func (k KLineWindow) GetChange() float64
- func (k KLineWindow) GetClose() float64
- func (k KLineWindow) GetHigh() float64
- func (k KLineWindow) GetInterval() Interval
- func (k KLineWindow) GetLow() float64
- func (k KLineWindow) GetLowerShadowHeight() float64
- func (k KLineWindow) GetLowerShadowRatio() float64
- func (k KLineWindow) GetMaxChange() float64
- func (k KLineWindow) GetOpen() float64
- func (k KLineWindow) GetThickness() float64
- func (k KLineWindow) GetTrend() int
- func (k KLineWindow) GetUpperShadowHeight() float64
- func (k KLineWindow) GetUpperShadowRatio() float64
- func (k KLineWindow) Last() KLine
- func (k KLineWindow) Len() int
- func (k KLineWindow) Mid() float64
- func (k KLineWindow) ReduceClose() float64
- func (k KLineWindow) SlackAttachment() slack.Attachment
- func (k KLineWindow) Tail(size int) KLineWindow
- func (k KLineWindow) Take(size int) KLineWindow
- func (k *KLineWindow) Truncate(size int)
- type MarginAccount
- type MarginExchange
- type MarginOrderSideEffectType
- type MarginSettings
- type MarginUserAsset
- type Market
- type MarketMap
- type MutexOrderBook
- type Order
- type OrderBook
- func (b *OrderBook) BestAsk() (PriceVolume, bool)
- func (b *OrderBook) BestBid() (PriceVolume, bool)
- func (b *OrderBook) Copy() (book OrderBook)
- func (b *OrderBook) EmitAsksChange(pvs PriceVolumeSlice)
- func (b *OrderBook) EmitBidsChange(pvs PriceVolumeSlice)
- func (b *OrderBook) EmitLoad(book *OrderBook)
- func (b *OrderBook) EmitUpdate(book *OrderBook)
- func (b *OrderBook) IsValid() (bool, error)
- func (b *OrderBook) Load(book OrderBook)
- func (b *OrderBook) OnAsksChange(cb func(pvs PriceVolumeSlice))
- func (b *OrderBook) OnBidsChange(cb func(pvs PriceVolumeSlice))
- func (b *OrderBook) OnLoad(cb func(book *OrderBook))
- func (b *OrderBook) OnUpdate(cb func(book *OrderBook))
- func (b *OrderBook) PriceVolumesBySide(side SideType) PriceVolumeSlice
- func (b *OrderBook) Print()
- func (b *OrderBook) Reset()
- func (b *OrderBook) String() string
- func (b *OrderBook) Update(book OrderBook)
- type OrderMap
- func (m OrderMap) Add(o Order)
- func (m OrderMap) Backup() (orderForms []SubmitOrder)
- func (m OrderMap) Canceled() OrderSlice
- func (m OrderMap) Exists(orderID uint64) bool
- func (m OrderMap) Filled() OrderSlice
- func (m OrderMap) FindByStatus(status OrderStatus) (orders OrderSlice)
- func (m OrderMap) IDs() (ids []uint64)
- func (m OrderMap) Orders() (orders OrderSlice)
- func (m OrderMap) Remove(orderID uint64)
- func (m OrderMap) Update(o Order)
- type OrderSlice
- type OrderStatus
- type OrderType
- type PlainText
- type PriceVolume
- type PriceVolumeSlice
- func (slice PriceVolumeSlice) Copy() PriceVolumeSlice
- func (slice PriceVolumeSlice) Find(price fixedpoint.Value, descending bool) (pv PriceVolume, idx int)
- func (slice PriceVolumeSlice) First() (PriceVolume, bool)
- func (slice PriceVolumeSlice) IndexByVolumeDepth(requiredVolume fixedpoint.Value) int
- func (slice PriceVolumeSlice) InsertAt(idx int, pv PriceVolume) PriceVolumeSlice
- func (slice PriceVolumeSlice) Len() int
- func (slice PriceVolumeSlice) Less(i, j int) bool
- func (slice PriceVolumeSlice) Remove(price fixedpoint.Value, descending bool) PriceVolumeSlice
- func (slice PriceVolumeSlice) Swap(i, j int)
- func (slice PriceVolumeSlice) Trim() (pvs PriceVolumeSlice)
- func (slice PriceVolumeSlice) Upsert(pv PriceVolume, descending bool) PriceVolumeSlice
- type Reward
- type RewardSlice
- type RewardSliceByCreationTime
- type RewardType
- type SideType
- type StandardStream
- func (stream *StandardStream) EmitBalanceSnapshot(balances BalanceMap)
- func (stream *StandardStream) EmitBalanceUpdate(balances BalanceMap)
- func (stream *StandardStream) EmitBookSnapshot(book OrderBook)
- func (stream *StandardStream) EmitBookUpdate(book OrderBook)
- func (stream *StandardStream) EmitConnect()
- func (stream *StandardStream) EmitDisconnect()
- func (stream *StandardStream) EmitKLine(kline KLine)
- func (stream *StandardStream) EmitKLineClosed(kline KLine)
- func (stream *StandardStream) EmitOrderUpdate(order Order)
- func (stream *StandardStream) EmitStart()
- func (stream *StandardStream) EmitTradeUpdate(trade Trade)
- func (stream *StandardStream) OnBalanceSnapshot(cb func(balances BalanceMap))
- func (stream *StandardStream) OnBalanceUpdate(cb func(balances BalanceMap))
- func (stream *StandardStream) OnBookSnapshot(cb func(book OrderBook))
- func (stream *StandardStream) OnBookUpdate(cb func(book OrderBook))
- func (stream *StandardStream) OnConnect(cb func())
- func (stream *StandardStream) OnDisconnect(cb func())
- func (stream *StandardStream) OnKLine(cb func(kline KLine))
- func (stream *StandardStream) OnKLineClosed(cb func(kline KLine))
- func (stream *StandardStream) OnOrderUpdate(cb func(order Order))
- func (stream *StandardStream) OnStart(cb func())
- func (stream *StandardStream) OnTradeUpdate(cb func(trade Trade))
- func (stream *StandardStream) Subscribe(channel Channel, symbol string, options SubscribeOptions)
- type StandardStreamEventHub
- type Stream
- type StreamOrderBook
- type SubmitOrder
- type SubscribeOptions
- type Subscription
- type SyncOrderMap
- func (m *SyncOrderMap) Add(o Order)
- func (m *SyncOrderMap) AnyFilled() (order Order, ok bool)
- func (m *SyncOrderMap) Backup() []SubmitOrder
- func (m *SyncOrderMap) Canceled() OrderSlice
- func (m *SyncOrderMap) Exists(orderID uint64) bool
- func (m *SyncOrderMap) Filled() OrderSlice
- func (m *SyncOrderMap) FindByStatus(status OrderStatus) OrderSlice
- func (m *SyncOrderMap) IDs() []uint64
- func (m *SyncOrderMap) Iterate(it func(id uint64, order Order) bool)
- func (m *SyncOrderMap) Len() int
- func (m *SyncOrderMap) Orders() (slice OrderSlice)
- func (m *SyncOrderMap) Remove(orderID uint64) (exists bool)
- func (m *SyncOrderMap) Update(o Order)
- type Ticker
- type Trade
- type TradeKey
- type TradeQueryOptions
- type TradeSlice
- type Withdraw
Constants ¶
const ( DepositPending = DepositStatus("pending") DepositRejected = DepositStatus("rejected") DepositSuccess = DepositStatus("success") DepositCancelled = DepositStatus("canceled") // created but can not withdraw DepositCredited = DepositStatus("credited") )
const ( ExchangeMax = ExchangeName("max") ExchangeBinance = ExchangeName("binance") ExchangeFTX = ExchangeName("ftx") )
const ( RewardAirdrop = RewardType("airdrop") RewardCommission = RewardType("commission") RewardHolding = RewardType("holding") RewardMining = RewardType("mining") RewardTrading = RewardType("trading") RewardVipRebate = RewardType("vip_rebate") )
const ( SideTypeBuy = SideType("BUY") SideTypeSell = SideType("SELL") SideTypeSelf = SideType("SELF") // SideTypeBoth is only used for the configuration context SideTypeBoth = SideType("BOTH") )
const DateFormat = "2006-01-02"
const DirectionDown = -1
const DirectionNone = 0
const DirectionUp = 1
const Green = "#228B22"
const Red = "#800000"
Variables ¶
var BNB = accounting.Accounting{Symbol: "BNB ", Precision: 4}
var BTC = accounting.Accounting{Symbol: "BTC ", Precision: 2}
var BookChannel = Channel("book")
var Interval12h = Interval("12h")
var Interval15m = Interval("15m")
var Interval1d = Interval("1d")
var Interval1h = Interval("1h")
var Interval1m = Interval("1m")
var Interval2h = Interval("2h")
var Interval30m = Interval("30m")
var Interval3d = Interval("3d")
var Interval4h = Interval("4h")
var Interval5m = Interval("5m")
var Interval6h = Interval("6h")
var KLineChannel = Channel("kline")
var SupportedIntervals = map[Interval]int{ Interval1m: 1, Interval5m: 5, Interval15m: 15, Interval30m: 30, Interval1h: 60, Interval2h: 60 * 2, Interval4h: 60 * 4, Interval6h: 60 * 6, Interval12h: 60 * 12, Interval1d: 60 * 24, Interval3d: 60 * 24 * 3, }
var USD = accounting.Accounting{Symbol: "$ ", Precision: 2}
Functions ¶
func SideToColorName ¶
Types ¶
type Account ¶
type Account struct { sync.Mutex `json:"-"` // bps. 0.15% fee will be 15. MakerCommission fixedpoint.Value `json:"makerCommission,omitempty"` TakerCommission fixedpoint.Value `json:"takerCommission,omitempty"` AccountType string `json:"accountType,omitempty"` // contains filtered or unexported fields }
func NewAccount ¶
func NewAccount() *Account
func (*Account) AddBalance ¶
func (a *Account) AddBalance(currency string, fund fixedpoint.Value) error
func (*Account) Balances ¶
func (a *Account) Balances() BalanceMap
Balances lock the balances and returned the copied balances
func (*Account) BindStream ¶
func (*Account) LockBalance ¶
func (a *Account) LockBalance(currency string, locked fixedpoint.Value) error
func (*Account) UnlockBalance ¶
func (a *Account) UnlockBalance(currency string, unlocked fixedpoint.Value) error
func (*Account) UpdateBalances ¶
func (a *Account) UpdateBalances(balances BalanceMap)
func (*Account) UseLockedBalance ¶
func (a *Account) UseLockedBalance(currency string, fund fixedpoint.Value) error
type Asset ¶ added in v1.11.0
type Asset struct { Currency string `json:"currency"` Total fixedpoint.Value `json:"total"` InUSD fixedpoint.Value `json:"inUSD"` InBTC fixedpoint.Value `json:"inBTC"` }
type Balance ¶
type Balance struct { Currency string `json:"currency"` Available fixedpoint.Value `json:"available"` Locked fixedpoint.Value `json:"locked"` }
func (Balance) Total ¶ added in v1.11.1
func (b Balance) Total() fixedpoint.Value
type BalanceMap ¶
func (BalanceMap) Assets ¶ added in v1.11.0
func (m BalanceMap) Assets(prices map[string]float64) AssetMap
func (BalanceMap) Print ¶
func (m BalanceMap) Print()
func (BalanceMap) String ¶ added in v1.2.0
func (m BalanceMap) String() string
type Deposit ¶
type Deposit struct { GID int64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` Time datatype.Time `json:"time" db:"time"` Amount float64 `json:"amount" db:"amount"` Asset string `json:"asset" db:"asset"` Address string `json:"address" db:"address"` AddressTag string `json:"addressTag"` TransactionID string `json:"transactionID" db:"txn_id"` Status DepositStatus `json:"status"` }
func (Deposit) EffectiveTime ¶
type DepositStatus ¶
type DepositStatus string
type Duration ¶ added in v1.3.1
func (*Duration) UnmarshalJSON ¶ added in v1.3.1
type Exchange ¶
type Exchange interface { Name() ExchangeName PlatformFeeCurrency() string // required implementation ExchangeMarketDataService ExchangeTradingService }
type ExchangeMarketDataService ¶ added in v1.14.0
type ExchangeMarketDataService interface { NewStream() Stream QueryMarkets(ctx context.Context) (MarketMap, error) QueryTicker(ctx context.Context, symbol string) (*Ticker, error) QueryTickers(ctx context.Context, symbol ...string) (map[string]Ticker, error) QueryKLines(ctx context.Context, symbol string, interval Interval, options KLineQueryOptions) ([]KLine, error) }
type ExchangeName ¶
type ExchangeName string
func ValidExchangeName ¶
func ValidExchangeName(a string) (ExchangeName, error)
func (ExchangeName) String ¶
func (n ExchangeName) String() string
func (*ExchangeName) UnmarshalJSON ¶ added in v1.11.1
func (n *ExchangeName) UnmarshalJSON(data []byte) error
type ExchangeRewardService ¶ added in v1.13.0
type ExchangeTradingService ¶ added in v1.14.0
type ExchangeTradingService interface { QueryAccount(ctx context.Context) (*Account, error) QueryAccountBalances(ctx context.Context) (BalanceMap, error) QueryTrades(ctx context.Context, symbol string, options *TradeQueryOptions) ([]Trade, error) SubmitOrders(ctx context.Context, orders ...SubmitOrder) (createdOrders OrderSlice, err error) QueryOpenOrders(ctx context.Context, symbol string) (orders []Order, err error) QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) (orders []Order, err error) CancelOrders(ctx context.Context, orders ...Order) error }
type ExchangeTransferService ¶ added in v1.14.0
type IntervalSlice ¶
type IntervalSlice []Interval
func (IntervalSlice) StringSlice ¶
func (s IntervalSlice) StringSlice() (slice []string)
type IntervalWindow ¶
type IntervalWindow struct { // The interval of kline Interval Interval // The windows size of the indicator (EWMA and SMA) Window int }
IntervalWindow is used by the indicators
func (IntervalWindow) String ¶ added in v1.4.0
func (iw IntervalWindow) String() string
type IsolatedMarginAccount ¶ added in v1.13.0
type IsolatedMarginAccount struct { TotalAssetOfBTC fixedpoint.Value `json:"totalAssetOfBtc"` TotalLiabilityOfBTC fixedpoint.Value `json:"totalLiabilityOfBtc"` TotalNetAssetOfBTC fixedpoint.Value `json:"totalNetAssetOfBtc"` Assets []IsolatedMarginAsset `json:"assets"` }
IsolatedMarginAccount defines isolated user assets of margin account
type IsolatedMarginAsset ¶ added in v1.13.0
type IsolatedMarginAsset struct { Symbol string `json:"symbol"` QuoteAsset IsolatedUserAsset `json:"quoteAsset"` BaseAsset IsolatedUserAsset `json:"baseAsset"` IsolatedCreated bool `json:"isolatedCreated"` MarginLevel fixedpoint.Value `json:"marginLevel"` MarginLevelStatus string `json:"marginLevelStatus"` MarginRatio fixedpoint.Value `json:"marginRatio"` IndexPrice fixedpoint.Value `json:"indexPrice"` LiquidatePrice fixedpoint.Value `json:"liquidatePrice"` LiquidateRate fixedpoint.Value `json:"liquidateRate"` TradeEnabled bool `json:"tradeEnabled"` }
IsolatedMarginAsset defines isolated margin asset information, like margin level, liquidation price... etc
type IsolatedUserAsset ¶ added in v1.13.0
type IsolatedUserAsset struct { Asset string `json:"asset"` Borrowed fixedpoint.Value `json:"borrowed"` Free fixedpoint.Value `json:"free"` Interest fixedpoint.Value `json:"interest"` Locked fixedpoint.Value `json:"locked"` NetAsset fixedpoint.Value `json:"netAsset"` NetAssetOfBtc fixedpoint.Value `json:"netAssetOfBtc"` BorrowEnabled bool `json:"borrowEnabled"` RepayEnabled bool `json:"repayEnabled"` TotalAsset fixedpoint.Value `json:"totalAsset"` }
IsolatedUserAsset defines isolated user assets of the margin account
type KLine ¶
type KLine struct { GID uint64 `json:"gid" db:"gid"` Exchange string `json:"exchange" db:"exchange"` Symbol string `json:"symbol" db:"symbol"` StartTime time.Time `json:"startTime" db:"start_time"` EndTime time.Time `json:"endTime" db:"end_time"` Interval Interval `json:"interval" db:"interval"` Open float64 `json:"open" db:"open"` Close float64 `json:"close" db:"close"` High float64 `json:"high" db:"high"` Low float64 `json:"low" db:"low"` Volume float64 `json:"volume" db:"volume"` QuoteVolume float64 `json:"quoteVolume" db:"quote_volume"` LastTradeID uint64 `json:"lastTradeID" db:"last_trade_id"` NumberOfTrades uint64 `json:"numberOfTrades" db:"num_trades"` Closed bool `json:"closed" db:"closed"` }
KLine uses binance's kline as the standard structure
func (KLine) BounceDown ¶
red candle with open and close near low price
func (KLine) GetEndTime ¶
func (KLine) GetInterval ¶
func (KLine) GetLowerShadowHeight ¶
func (KLine) GetLowerShadowRatio ¶
func (KLine) GetMaxChange ¶
func (KLine) GetStartTime ¶
func (KLine) GetThickness ¶
GetThickness returns the thickness of the kline. 1 => thick, 0.1 => thin
func (KLine) GetUpperShadowHeight ¶
func (KLine) GetUpperShadowRatio ¶
func (KLine) SlackAttachment ¶
func (k KLine) SlackAttachment() slack.Attachment
type KLineCallback ¶
type KLineCallback func(kline KLine)
type KLineOrWindow ¶
type KLineOrWindow interface { GetInterval() string Direction() Direction GetChange() float64 GetMaxChange() float64 GetThickness() float64 Mid() float64 GetOpen() float64 GetClose() float64 GetHigh() float64 GetLow() float64 BounceUp() bool BounceDown() bool GetUpperShadowRatio() float64 GetLowerShadowRatio() float64 SlackAttachment() slack.Attachment }
type KLineQueryOptions ¶
type KLineWindow ¶
type KLineWindow []KLine
func (*KLineWindow) Add ¶
func (k *KLineWindow) Add(line KLine)
func (KLineWindow) AllDrop ¶
func (k KLineWindow) AllDrop() bool
func (KLineWindow) AllRise ¶
func (k KLineWindow) AllRise() bool
func (KLineWindow) BounceDown ¶
func (k KLineWindow) BounceDown() bool
red candle with open and close near low price
func (KLineWindow) BounceUp ¶
func (k KLineWindow) BounceUp() bool
green candle with open and close near high price
func (KLineWindow) Color ¶
func (k KLineWindow) Color() string
func (KLineWindow) First ¶
func (k KLineWindow) First() KLine
func (KLineWindow) GetBody ¶
func (k KLineWindow) GetBody() float64
func (KLineWindow) GetChange ¶
func (k KLineWindow) GetChange() float64
func (KLineWindow) GetClose ¶
func (k KLineWindow) GetClose() float64
func (KLineWindow) GetHigh ¶
func (k KLineWindow) GetHigh() float64
func (KLineWindow) GetInterval ¶
func (k KLineWindow) GetInterval() Interval
func (KLineWindow) GetLow ¶
func (k KLineWindow) GetLow() float64
func (KLineWindow) GetLowerShadowHeight ¶
func (k KLineWindow) GetLowerShadowHeight() float64
func (KLineWindow) GetLowerShadowRatio ¶
func (k KLineWindow) GetLowerShadowRatio() float64
func (KLineWindow) GetMaxChange ¶
func (k KLineWindow) GetMaxChange() float64
func (KLineWindow) GetOpen ¶
func (k KLineWindow) GetOpen() float64
func (KLineWindow) GetThickness ¶
func (k KLineWindow) GetThickness() float64
func (KLineWindow) GetTrend ¶
func (k KLineWindow) GetTrend() int
func (KLineWindow) GetUpperShadowHeight ¶
func (k KLineWindow) GetUpperShadowHeight() float64
func (KLineWindow) GetUpperShadowRatio ¶
func (k KLineWindow) GetUpperShadowRatio() float64
func (KLineWindow) Last ¶
func (k KLineWindow) Last() KLine
func (KLineWindow) Len ¶
func (k KLineWindow) Len() int
func (KLineWindow) Mid ¶
func (k KLineWindow) Mid() float64
func (KLineWindow) ReduceClose ¶
func (k KLineWindow) ReduceClose() float64
ReduceClose reduces the closed prices
func (KLineWindow) SlackAttachment ¶
func (k KLineWindow) SlackAttachment() slack.Attachment
func (KLineWindow) Tail ¶
func (k KLineWindow) Tail(size int) KLineWindow
func (KLineWindow) Take ¶
func (k KLineWindow) Take(size int) KLineWindow
func (*KLineWindow) Truncate ¶
func (k *KLineWindow) Truncate(size int)
Truncate removes the old klines from the window
type MarginAccount ¶ added in v1.13.0
type MarginAccount struct { BorrowEnabled bool `json:"borrowEnabled"` MarginLevel fixedpoint.Value `json:"marginLevel"` TotalAssetOfBTC fixedpoint.Value `json:"totalAssetOfBtc"` TotalLiabilityOfBTC fixedpoint.Value `json:"totalLiabilityOfBtc"` TotalNetAssetOfBTC fixedpoint.Value `json:"totalNetAssetOfBtc"` TradeEnabled bool `json:"tradeEnabled"` TransferEnabled bool `json:"transferEnabled"` UserAssets []MarginUserAsset `json:"userAssets"` }
MarginAccount is for the cross margin account
type MarginExchange ¶ added in v1.8.0
type MarginExchange interface { UseMargin() UseIsolatedMargin(symbol string) GetMarginSettings() MarginSettings }
type MarginOrderSideEffectType ¶ added in v1.8.0
type MarginOrderSideEffectType string
MarginOrderSideEffectType define side effect type for orders
var ( SideEffectTypeNoSideEffect MarginOrderSideEffectType = "NO_SIDE_EFFECT" SideEffectTypeMarginBuy MarginOrderSideEffectType = "MARGIN_BUY" SideEffectTypeAutoRepay MarginOrderSideEffectType = "AUTO_REPAY" )
func (*MarginOrderSideEffectType) UnmarshalJSON ¶ added in v1.11.0
func (t *MarginOrderSideEffectType) UnmarshalJSON(data []byte) error
type MarginSettings ¶ added in v1.8.0
func (MarginSettings) GetMarginSettings ¶ added in v1.8.0
func (e MarginSettings) GetMarginSettings() MarginSettings
func (*MarginSettings) UseIsolatedMargin ¶ added in v1.8.0
func (e *MarginSettings) UseIsolatedMargin(symbol string)
func (*MarginSettings) UseMargin ¶ added in v1.8.0
func (e *MarginSettings) UseMargin()
type MarginUserAsset ¶ added in v1.13.0
type MarginUserAsset struct { Asset string `json:"asset"` Borrowed fixedpoint.Value `json:"borrowed"` Free fixedpoint.Value `json:"free"` Interest fixedpoint.Value `json:"interest"` Locked fixedpoint.Value `json:"locked"` NetAsset fixedpoint.Value `json:"netAsset"` }
MarginUserAsset define user assets of margin account
type Market ¶
type Market struct { Symbol string PricePrecision int VolumePrecision int QuoteCurrency string BaseCurrency string // The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol. // An order's notional value is the price * quantity MinNotional float64 MinAmount float64 // The LOT_SIZE filter defines the quantity MinQuantity float64 MaxQuantity float64 StepSize float64 MinPrice float64 MaxPrice float64 TickSize float64 }
func (Market) CanonicalizeVolume ¶
func (Market) FormatPrice ¶
func (Market) FormatPriceCurrency ¶
func (Market) FormatQuantity ¶
func (Market) FormatVolume ¶
type MutexOrderBook ¶
func NewMutexOrderBook ¶
func NewMutexOrderBook(symbol string) *MutexOrderBook
func (*MutexOrderBook) Get ¶
func (b *MutexOrderBook) Get() OrderBook
func (*MutexOrderBook) Load ¶
func (b *MutexOrderBook) Load(book OrderBook)
func (*MutexOrderBook) Reset ¶ added in v1.11.0
func (b *MutexOrderBook) Reset()
func (*MutexOrderBook) Update ¶
func (b *MutexOrderBook) Update(update OrderBook)
type Order ¶
type Order struct { SubmitOrder Exchange string `json:"exchange" db:"exchange"` GID uint64 `json:"gid" db:"gid"` OrderID uint64 `json:"orderID" db:"order_id"` // order id Status OrderStatus `json:"status" db:"status"` ExecutedQuantity float64 `json:"executedQuantity" db:"executed_quantity"` IsWorking bool `json:"isWorking" db:"is_working"` CreationTime datatype.Time `json:"creationTime" db:"created_at"` UpdateTime datatype.Time `json:"updateTime" db:"updated_at"` IsMargin bool `json:"isMargin" db:"is_margin"` IsIsolated bool `json:"isIsolated" db:"is_isolated"` }
func (Order) Backup ¶ added in v1.14.0
func (o Order) Backup() SubmitOrder
Backup backs up the current order quantity to a SubmitOrder object so that we can post the order later when we want to restore the orders.
type OrderBook ¶
type OrderBook struct { Symbol string Bids PriceVolumeSlice Asks PriceVolumeSlice // contains filtered or unexported fields }
func (*OrderBook) BestAsk ¶ added in v1.9.0
func (b *OrderBook) BestAsk() (PriceVolume, bool)
func (*OrderBook) BestBid ¶ added in v1.9.0
func (b *OrderBook) BestBid() (PriceVolume, bool)
func (*OrderBook) EmitAsksChange ¶
func (b *OrderBook) EmitAsksChange(pvs PriceVolumeSlice)
func (*OrderBook) EmitBidsChange ¶
func (b *OrderBook) EmitBidsChange(pvs PriceVolumeSlice)
func (*OrderBook) EmitUpdate ¶
func (*OrderBook) OnAsksChange ¶
func (b *OrderBook) OnAsksChange(cb func(pvs PriceVolumeSlice))
func (*OrderBook) OnBidsChange ¶
func (b *OrderBook) OnBidsChange(cb func(pvs PriceVolumeSlice))
func (*OrderBook) PriceVolumesBySide ¶
func (b *OrderBook) PriceVolumesBySide(side SideType) PriceVolumeSlice
type OrderMap ¶
OrderMap is used for storing orders by their order id
func (OrderMap) Backup ¶ added in v1.14.0
func (m OrderMap) Backup() (orderForms []SubmitOrder)
func (OrderMap) Canceled ¶
func (m OrderMap) Canceled() OrderSlice
func (OrderMap) Filled ¶
func (m OrderMap) Filled() OrderSlice
func (OrderMap) FindByStatus ¶
func (m OrderMap) FindByStatus(status OrderStatus) (orders OrderSlice)
func (OrderMap) Orders ¶
func (m OrderMap) Orders() (orders OrderSlice)
type OrderSlice ¶
type OrderSlice []Order
func (OrderSlice) IDs ¶
func (s OrderSlice) IDs() (ids []uint64)
type OrderStatus ¶
type OrderStatus string
const ( OrderStatusNew OrderStatus = "NEW" OrderStatusFilled OrderStatus = "FILLED" OrderStatusPartiallyFilled OrderStatus = "PARTIALLY_FILLED" OrderStatusCanceled OrderStatus = "CANCELED" OrderStatusRejected OrderStatus = "REJECTED" )
type PriceVolume ¶
type PriceVolume struct { Price fixedpoint.Value Volume fixedpoint.Value }
func (PriceVolume) String ¶
func (p PriceVolume) String() string
type PriceVolumeSlice ¶
type PriceVolumeSlice []PriceVolume
func (PriceVolumeSlice) Copy ¶
func (slice PriceVolumeSlice) Copy() PriceVolumeSlice
func (PriceVolumeSlice) Find ¶
func (slice PriceVolumeSlice) Find(price fixedpoint.Value, descending bool) (pv PriceVolume, idx int)
FindPriceVolumePair finds the pair by the given price, this function is a read-only operation, so we use the value receiver to avoid copy value from the pointer If the price is not found, it will return the index where the price can be inserted at. true for descending (bid orders), false for ascending (ask orders)
func (PriceVolumeSlice) First ¶
func (slice PriceVolumeSlice) First() (PriceVolume, bool)
func (PriceVolumeSlice) IndexByVolumeDepth ¶
func (slice PriceVolumeSlice) IndexByVolumeDepth(requiredVolume fixedpoint.Value) int
func (PriceVolumeSlice) InsertAt ¶
func (slice PriceVolumeSlice) InsertAt(idx int, pv PriceVolume) PriceVolumeSlice
func (PriceVolumeSlice) Len ¶
func (slice PriceVolumeSlice) Len() int
func (PriceVolumeSlice) Less ¶
func (slice PriceVolumeSlice) Less(i, j int) bool
func (PriceVolumeSlice) Remove ¶
func (slice PriceVolumeSlice) Remove(price fixedpoint.Value, descending bool) PriceVolumeSlice
func (PriceVolumeSlice) Swap ¶
func (slice PriceVolumeSlice) Swap(i, j int)
func (PriceVolumeSlice) Trim ¶
func (slice PriceVolumeSlice) Trim() (pvs PriceVolumeSlice)
Trim removes the pairs that volume = 0
func (PriceVolumeSlice) Upsert ¶
func (slice PriceVolumeSlice) Upsert(pv PriceVolume, descending bool) PriceVolumeSlice
type Reward ¶ added in v1.13.0
type Reward struct { GID int64 `json:"gid" db:"gid"` UUID string `json:"uuid" db:"uuid"` Exchange ExchangeName `json:"exchange" db:"exchange"` Type RewardType `json:"reward_type" db:"reward_type"` Currency string `json:"currency" db:"currency"` Quantity fixedpoint.Value `json:"quantity" db:"quantity"` State string `json:"state" db:"state"` Note string `json:"note" db:"note"` Spent bool `json:"spent" db:"spent"` // Unix timestamp in seconds CreatedAt datatype.Time `json:"created_at" db:"created_at"` }
type RewardSlice ¶ added in v1.13.0
type RewardSlice []Reward
func (RewardSlice) Len ¶ added in v1.13.0
func (s RewardSlice) Len() int
func (RewardSlice) Swap ¶ added in v1.13.0
func (s RewardSlice) Swap(i, j int)
type RewardSliceByCreationTime ¶ added in v1.13.0
type RewardSliceByCreationTime RewardSlice
func (RewardSliceByCreationTime) Len ¶ added in v1.13.0
func (s RewardSliceByCreationTime) Len() int
func (RewardSliceByCreationTime) Less ¶ added in v1.13.0
func (s RewardSliceByCreationTime) Less(i, j int) bool
Less reports whether x[i] should be ordered before x[j]
func (RewardSliceByCreationTime) Swap ¶ added in v1.13.0
func (s RewardSliceByCreationTime) Swap(i, j int)
type RewardType ¶ added in v1.13.0
type RewardType string
type SideType ¶
type SideType string
SideType define side type of order
func (*SideType) UnmarshalJSON ¶ added in v1.14.0
type StandardStream ¶
type StandardStream struct { Subscriptions []Subscription // contains filtered or unexported fields }
func (*StandardStream) EmitBalanceSnapshot ¶
func (stream *StandardStream) EmitBalanceSnapshot(balances BalanceMap)
func (*StandardStream) EmitBalanceUpdate ¶
func (stream *StandardStream) EmitBalanceUpdate(balances BalanceMap)
func (*StandardStream) EmitBookSnapshot ¶
func (stream *StandardStream) EmitBookSnapshot(book OrderBook)
func (*StandardStream) EmitBookUpdate ¶
func (stream *StandardStream) EmitBookUpdate(book OrderBook)
func (*StandardStream) EmitConnect ¶
func (stream *StandardStream) EmitConnect()
func (*StandardStream) EmitDisconnect ¶ added in v1.14.0
func (stream *StandardStream) EmitDisconnect()
func (*StandardStream) EmitKLine ¶
func (stream *StandardStream) EmitKLine(kline KLine)
func (*StandardStream) EmitKLineClosed ¶
func (stream *StandardStream) EmitKLineClosed(kline KLine)
func (*StandardStream) EmitOrderUpdate ¶
func (stream *StandardStream) EmitOrderUpdate(order Order)
func (*StandardStream) EmitStart ¶ added in v1.14.0
func (stream *StandardStream) EmitStart()
func (*StandardStream) EmitTradeUpdate ¶
func (stream *StandardStream) EmitTradeUpdate(trade Trade)
func (*StandardStream) OnBalanceSnapshot ¶
func (stream *StandardStream) OnBalanceSnapshot(cb func(balances BalanceMap))
func (*StandardStream) OnBalanceUpdate ¶
func (stream *StandardStream) OnBalanceUpdate(cb func(balances BalanceMap))
func (*StandardStream) OnBookSnapshot ¶
func (stream *StandardStream) OnBookSnapshot(cb func(book OrderBook))
func (*StandardStream) OnBookUpdate ¶
func (stream *StandardStream) OnBookUpdate(cb func(book OrderBook))
func (*StandardStream) OnConnect ¶
func (stream *StandardStream) OnConnect(cb func())
func (*StandardStream) OnDisconnect ¶ added in v1.14.0
func (stream *StandardStream) OnDisconnect(cb func())
func (*StandardStream) OnKLine ¶
func (stream *StandardStream) OnKLine(cb func(kline KLine))
func (*StandardStream) OnKLineClosed ¶
func (stream *StandardStream) OnKLineClosed(cb func(kline KLine))
func (*StandardStream) OnOrderUpdate ¶
func (stream *StandardStream) OnOrderUpdate(cb func(order Order))
func (*StandardStream) OnStart ¶ added in v1.14.0
func (stream *StandardStream) OnStart(cb func())
func (*StandardStream) OnTradeUpdate ¶
func (stream *StandardStream) OnTradeUpdate(cb func(trade Trade))
func (*StandardStream) Subscribe ¶
func (stream *StandardStream) Subscribe(channel Channel, symbol string, options SubscribeOptions)
type StandardStreamEventHub ¶
type StandardStreamEventHub interface { OnStart(cb func()) OnConnect(cb func()) OnDisconnect(cb func()) OnTradeUpdate(cb func(trade Trade)) OnOrderUpdate(cb func(order Order)) OnBalanceSnapshot(cb func(balances BalanceMap)) OnBalanceUpdate(cb func(balances BalanceMap)) OnKLineClosed(cb func(kline KLine)) OnKLine(cb func(kline KLine)) OnBookUpdate(cb func(book OrderBook)) OnBookSnapshot(cb func(book OrderBook)) }
type Stream ¶
type Stream interface { StandardStreamEventHub Subscribe(channel Channel, symbol string, options SubscribeOptions) SetPublicOnly() Connect(ctx context.Context) error Close() error }
type StreamOrderBook ¶
type StreamOrderBook struct { *MutexOrderBook C sigchan.Chan }
StreamOrderBook receives streaming data from websocket connection and update the order book with mutex lock, so you can safely access it.
func NewStreamBook ¶
func NewStreamBook(symbol string) *StreamOrderBook
func (*StreamOrderBook) BindStream ¶
func (sb *StreamOrderBook) BindStream(stream Stream)
type SubmitOrder ¶
type SubmitOrder struct { ClientOrderID string `json:"clientOrderID" db:"client_order_id"` Symbol string `json:"symbol" db:"symbol"` Side SideType `json:"side" db:"side"` Type OrderType `json:"orderType" db:"order_type"` Quantity float64 `json:"quantity" db:"quantity"` Price float64 `json:"price" db:"price"` StopPrice float64 `json:"stopPrice,omitempty" db:"stop_price"` Market Market `json:"-" db:"-"` // TODO: we can probably remove these field StopPriceString string `json:"-"` PriceString string `json:"-"` QuantityString string `json:"-"` TimeInForce string `json:"timeInForce,omitempty" db:"time_in_force"` // GTC, IOC, FOK GroupID uint32 `json:"groupID,omitempty"` MarginSideEffect MarginOrderSideEffectType `json:"marginSideEffect,omitempty"` // AUTO_REPAY = repay, MARGIN_BUY = borrow, defaults to NO_SIDE_EFFECT }
func (*SubmitOrder) PlainText ¶ added in v1.4.0
func (o *SubmitOrder) PlainText() string
func (*SubmitOrder) SlackAttachment ¶
func (o *SubmitOrder) SlackAttachment() slack.Attachment
func (*SubmitOrder) String ¶
func (o *SubmitOrder) String() string
type SubscribeOptions ¶
type SubscribeOptions struct { Interval string `json:"interval,omitempty"` Depth string `json:"depth,omitempty"` }
SubscribeOptions provides the standard stream options
func (SubscribeOptions) String ¶
func (o SubscribeOptions) String() string
type Subscription ¶
type Subscription struct { Symbol string `json:"symbol"` Channel Channel `json:"channel"` Options SubscribeOptions `json:"options"` }
type SyncOrderMap ¶
func NewSyncOrderMap ¶
func NewSyncOrderMap() *SyncOrderMap
func (*SyncOrderMap) Add ¶
func (m *SyncOrderMap) Add(o Order)
func (*SyncOrderMap) AnyFilled ¶
func (m *SyncOrderMap) AnyFilled() (order Order, ok bool)
AnyFilled find any order is filled and stop iterating the order map
func (*SyncOrderMap) Backup ¶ added in v1.14.0
func (m *SyncOrderMap) Backup() []SubmitOrder
func (*SyncOrderMap) Canceled ¶
func (m *SyncOrderMap) Canceled() OrderSlice
func (*SyncOrderMap) Exists ¶
func (m *SyncOrderMap) Exists(orderID uint64) bool
func (*SyncOrderMap) Filled ¶
func (m *SyncOrderMap) Filled() OrderSlice
func (*SyncOrderMap) FindByStatus ¶
func (m *SyncOrderMap) FindByStatus(status OrderStatus) OrderSlice
func (*SyncOrderMap) IDs ¶
func (m *SyncOrderMap) IDs() []uint64
func (*SyncOrderMap) Len ¶
func (m *SyncOrderMap) Len() int
func (*SyncOrderMap) Orders ¶
func (m *SyncOrderMap) Orders() (slice OrderSlice)
func (*SyncOrderMap) Remove ¶ added in v1.1.0
func (m *SyncOrderMap) Remove(orderID uint64) (exists bool)
func (*SyncOrderMap) Update ¶
func (m *SyncOrderMap) Update(o Order)
type Ticker ¶ added in v1.11.0
type Ticker struct { Time time.Time Volume float64 // `volume` from Max & binance Last float64 // `last` from Max, `lastPrice` from binance Open float64 // `open` from Max, `openPrice` from binance High float64 // `high` from Max, `highPrice` from binance Low float64 // `low` from Max, `lowPrice` from binance Buy float64 // `buy` from Max, `bidPrice` from binance Sell float64 // `sell` from Max, `askPrice` from binance }
type Trade ¶
type Trade struct { // GID is the global ID GID int64 `json:"gid" db:"gid"` // ID is the source trade ID ID int64 `json:"id" db:"id"` OrderID uint64 `json:"orderID" db:"order_id"` Exchange string `json:"exchange" db:"exchange"` Price float64 `json:"price" db:"price"` Quantity float64 `json:"quantity" db:"quantity"` QuoteQuantity float64 `json:"quoteQuantity" db:"quote_quantity"` Symbol string `json:"symbol" db:"symbol"` Side SideType `json:"side" db:"side"` IsBuyer bool `json:"isBuyer" db:"is_buyer"` IsMaker bool `json:"isMaker" db:"is_maker"` Time datatype.Time `json:"tradedAt" db:"traded_at"` Fee float64 `json:"fee" db:"fee"` FeeCurrency string `json:"feeCurrency" db:"fee_currency"` IsMargin bool `json:"isMargin" db:"is_margin"` IsIsolated bool `json:"isIsolated" db:"is_isolated"` StrategyID sql.NullString `json:"strategyID" db:"strategy"` PnL sql.NullFloat64 `json:"pnl" db:"pnl"` }
func (Trade) MakerOrTakerLabel ¶ added in v1.11.1
func (Trade) SlackAttachment ¶
func (trade Trade) SlackAttachment() slack.Attachment
type TradeQueryOptions ¶
type TradeSlice ¶ added in v1.11.0
type TradeSlice struct { Trades []Trade // contains filtered or unexported fields }
func (*TradeSlice) Append ¶ added in v1.11.0
func (s *TradeSlice) Append(t Trade)
func (*TradeSlice) Copy ¶ added in v1.11.0
func (s *TradeSlice) Copy() []Trade
func (*TradeSlice) Reverse ¶ added in v1.13.0
func (s *TradeSlice) Reverse()
type Withdraw ¶
type Withdraw struct { GID int64 `json:"gid" db:"gid"` Exchange ExchangeName `json:"exchange" db:"exchange"` Asset string `json:"asset" db:"asset"` Amount float64 `json:"amount" db:"amount"` Address string `json:"address" db:"address"` AddressTag string `json:"addressTag"` Status string `json:"status"` TransactionID string `json:"transactionID" db:"txn_id"` TransactionFee float64 `json:"transactionFee" db:"txn_fee"` TransactionFeeCurrency string `json:"transactionFeeCurrency" db:"txn_fee_currency"` WithdrawOrderID string `json:"withdrawOrderId"` ApplyTime datatype.Time `json:"applyTime" db:"time"` Network string `json:"network" db:"network"` }