Documentation ¶
Index ¶
- type AccountBalanceProvider
- type BookEvent
- type DataType
- type Exchange
- func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (errs error)
- func (e *Exchange) GetAllFeeRates(ctx context.Context) (bybitapi.FeeRates, error)
- func (e *Exchange) IsSupportedInterval(interval types.Interval) bool
- func (e *Exchange) Name() types.ExchangeName
- func (e *Exchange) NewStream() types.Stream
- func (e *Exchange) PlatformFeeCurrency() string
- func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error)
- func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error)
- func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, util time.Time, lastOrderID uint64) (orders []types.Order, err error)
- func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, ...) ([]types.KLine, error)
- func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error)
- func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders []types.Order, err error)
- func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error)
- func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) (trades []types.Trade, err error)
- func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error)
- func (e *Exchange) QueryTickers(ctx context.Context, symbols ...string) (map[string]types.Ticker, error)
- func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error)
- func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*types.Order, error)
- func (e *Exchange) SupportedInterval() map[types.Interval]int
- type KLine
- type KLineEvent
- type MarketInfoProvider
- type MarketTradeEvent
- type OrderEvent
- type Stream
- func (s *Stream) EmitBookEvent(e BookEvent)
- func (s *Stream) EmitKLineEvent(e KLineEvent)
- func (s *Stream) EmitMarketTradeEvent(e []MarketTradeEvent)
- func (s *Stream) EmitOrderEvent(e []OrderEvent)
- func (s *Stream) EmitTradeEvent(e []TradeEvent)
- func (s *Stream) EmitWalletEvent(e []bybitapi.WalletBalances)
- func (s *Stream) OnBookEvent(cb func(e BookEvent))
- func (s *Stream) OnKLineEvent(cb func(e KLineEvent))
- func (s *Stream) OnMarketTradeEvent(cb func(e []MarketTradeEvent))
- func (s *Stream) OnOrderEvent(cb func(e []OrderEvent))
- func (s *Stream) OnTradeEvent(cb func(e []TradeEvent))
- func (s *Stream) OnWalletEvent(cb func(e []bybitapi.WalletBalances))
- func (s *Stream) Unsubscribe()
- type StreamDataProvider
- type TopicType
- type TradeEvent
- type WebSocketOpEvent
- type WebSocketTopicEvent
- type WebsocketOp
- type WsEvent
- type WsOpType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountBalanceProvider ¶
type AccountBalanceProvider interface {
QueryAccountBalances(ctx context.Context) (types.BalanceMap, error)
}
AccountBalanceProvider provides a function to query all balances at streaming connected and emit balance snapshot.
type BookEvent ¶
type BookEvent struct { // Symbol name Symbol string `json:"s"` // Bids. For snapshot stream, the element is sorted by price in descending order Bids types.PriceVolumeSlice `json:"b"` // Asks. For snapshot stream, the element is sorted by price in ascending order Asks types.PriceVolumeSlice `json:"a"` // Update ID. Is a sequence. Occasionally, you'll receive "u"=1, which is a snapshot data due to the restart of // the service. So please overwrite your local orderbook UpdateId fixedpoint.Value `json:"u"` // Cross sequence. You can use this field to compare different levels orderbook data, and for the smaller seq, // then it means the data is generated earlier. SequenceId fixedpoint.Value `json:"seq"` // internal use // Copied from WebSocketTopicEvent.Type, WebSocketTopicEvent.Ts // Type can be one of snapshot or delta. Type DataType // ServerTime using the websocket timestamp as server time. Since the event not provide server time information. ServerTime time.Time }
func (*BookEvent) OrderBook ¶
func (e *BookEvent) OrderBook() (snapshot types.SliceOrderBook)
type Exchange ¶
type Exchange struct {
// contains filtered or unexported fields
}
func (*Exchange) CancelOrders ¶
func (*Exchange) GetAllFeeRates ¶
func (*Exchange) IsSupportedInterval ¶
func (*Exchange) Name ¶
func (e *Exchange) Name() types.ExchangeName
func (*Exchange) PlatformFeeCurrency ¶
PlatformFeeCurrency returns empty string. The platform does not support "PlatformFeeCurrency" but instead charges fees using the native token.
func (*Exchange) QueryAccount ¶
func (*Exchange) QueryAccountBalances ¶
func (*Exchange) QueryClosedOrders ¶
func (*Exchange) QueryKLines ¶
func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error)
QueryKLines queries for historical klines (also known as candles/candlesticks). Charts are returned in groups based on the requested interval.
A k-line's start time is inclusive, but end time is not(startTime + interval - 1 millisecond). e.q. 15m interval k line can be represented as 00:00:00.000 ~ 00:14:59.999
func (*Exchange) QueryMarkets ¶
func (*Exchange) QueryOpenOrders ¶
func (*Exchange) QueryOrder ¶
func (*Exchange) QueryOrderTrades ¶
func (*Exchange) QueryTicker ¶
func (*Exchange) QueryTickers ¶
func (*Exchange) QueryTrades ¶
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error)
QueryTrades queries trades by time range or trade id range. If options.StartTime is not specified, you can only query for records in the last 7 days. If you want to query for records older than 7 days, options.StartTime is required. It supports to query records up to 180 days.
** Here includes MakerRebate. If needed, let's discuss how to modify it to return in trade. ** ** StartTime and EndTime are inclusive. ** ** StartTime and EndTime cannot exceed 180 days. ** ** StartTime, EndTime, FromTradeId can be used together. ** ** If the `FromTradeId` is passed, and `ToTradeId` is null, then the result is sorted by tradeId in `ascend`. Otherwise, the result is sorted by tradeId in `descend`. **
func (*Exchange) SubmitOrder ¶
type KLine ¶
type KLine struct { // The start timestamp (ms) StartTime types.MillisecondTimestamp `json:"start"` // The end timestamp (ms) EndTime types.MillisecondTimestamp `json:"end"` // Kline interval Interval string `json:"interval"` OpenPrice fixedpoint.Value `json:"open"` ClosePrice fixedpoint.Value `json:"close"` HighPrice fixedpoint.Value `json:"high"` LowPrice fixedpoint.Value `json:"low"` // Trade volume Volume fixedpoint.Value `json:"volume"` // Turnover. Unit of figure: quantity of quota coin Turnover fixedpoint.Value `json:"turnover"` // Weather the tick is ended or not Confirm bool `json:"confirm"` // The timestamp (ms) of the last matched order in the candle Timestamp types.MillisecondTimestamp `json:"timestamp"` }
type KLineEvent ¶
type MarketInfoProvider ¶
type MarketInfoProvider interface { GetAllFeeRates(ctx context.Context) (bybitapi.FeeRates, error) QueryMarkets(ctx context.Context) (types.MarketMap, error) }
MarketInfoProvider calculates trade fees since trading fees are not supported by streaming.
type MarketTradeEvent ¶
type MarketTradeEvent struct { // Timestamp is the timestamp (ms) that the order is filled Timestamp types.MillisecondTimestamp `json:"T"` Symbol string `json:"s"` // Side of taker. Buy,Sell Side bybitapi.Side `json:"S"` // Quantity is the trade size Quantity fixedpoint.Value `json:"v"` // Price is the trade price Price fixedpoint.Value `json:"p"` // L is the direction of price change. Unique field for future Direction string `json:"L"` // trade ID TradeId string `json:"i"` // Whether it is a block trade order or not BlockTrade bool `json:"BT"` }
type OrderEvent ¶
type Stream ¶
type Stream struct { types.StandardStream // contains filtered or unexported fields }
func NewStream ¶
func NewStream(key, secret string, userDataProvider StreamDataProvider) *Stream
func (*Stream) EmitBookEvent ¶
func (*Stream) EmitKLineEvent ¶
func (s *Stream) EmitKLineEvent(e KLineEvent)
func (*Stream) EmitMarketTradeEvent ¶
func (s *Stream) EmitMarketTradeEvent(e []MarketTradeEvent)
func (*Stream) EmitOrderEvent ¶
func (s *Stream) EmitOrderEvent(e []OrderEvent)
func (*Stream) EmitTradeEvent ¶
func (s *Stream) EmitTradeEvent(e []TradeEvent)
func (*Stream) EmitWalletEvent ¶
func (s *Stream) EmitWalletEvent(e []bybitapi.WalletBalances)
func (*Stream) OnBookEvent ¶
func (*Stream) OnKLineEvent ¶
func (s *Stream) OnKLineEvent(cb func(e KLineEvent))
func (*Stream) OnMarketTradeEvent ¶
func (s *Stream) OnMarketTradeEvent(cb func(e []MarketTradeEvent))
func (*Stream) OnOrderEvent ¶
func (s *Stream) OnOrderEvent(cb func(e []OrderEvent))
func (*Stream) OnTradeEvent ¶
func (s *Stream) OnTradeEvent(cb func(e []TradeEvent))
func (*Stream) OnWalletEvent ¶
func (s *Stream) OnWalletEvent(cb func(e []bybitapi.WalletBalances))
func (*Stream) Unsubscribe ¶
func (s *Stream) Unsubscribe()
type StreamDataProvider ¶
type StreamDataProvider interface { MarketInfoProvider AccountBalanceProvider }
type TradeEvent ¶
type TradeEvent struct { // linear and inverse order id format: 42f4f364-82e1-49d3-ad1d-cd8cf9aa308d (UUID format) // spot: 1468264727470772736 (only numbers) // we only use spot trading. OrderId string `json:"orderId"` OrderLinkId string `json:"orderLinkId"` Category bybitapi.Category `json:"category"` Symbol string `json:"symbol"` ExecId string `json:"execId"` ExecPrice fixedpoint.Value `json:"execPrice"` ExecQty fixedpoint.Value `json:"execQty"` // Is maker order. true: maker, false: taker IsMaker bool `json:"isMaker"` // Paradigm block trade ID BlockTradeId string `json:"blockTradeId"` // Order type. Market,Limit OrderType bybitapi.OrderType `json:"orderType"` // Side. Buy,Sell Side bybitapi.Side `json:"side"` // Executed timestamp(ms) ExecTime types.MillisecondTimestamp `json:"execTime"` // Closed position size ClosedSize fixedpoint.Value `json:"closedSize"` /* The following parameters do not support SPOT trading. */ // Executed trading fee. You can get spot fee currency instruction here. Normal spot is not supported ExecFee fixedpoint.Value `json:"execFee"` // Executed type. Normal spot is not supported ExecType string `json:"execType"` // Executed order value. Normal spot is not supported ExecValue fixedpoint.Value `json:"execValue"` // Trading fee rate. Normal spot is not supported FeeRate fixedpoint.Value `json:"feeRate"` // The remaining qty not executed. Normal spot is not supported LeavesQty fixedpoint.Value `json:"leavesQty"` // Order price. Normal spot is not supported OrderPrice fixedpoint.Value `json:"orderPrice"` // Order qty. Normal spot is not supported OrderQty fixedpoint.Value `json:"orderQty"` // Stop order type. If the order is not stop order, any type is not returned. Normal spot is not supported StopOrderType string `json:"stopOrderType"` // Whether to borrow. Unified spot only. 0: false, 1: true. . Normal spot is not supported, always 0 IsLeverage string `json:"isLeverage"` // Implied volatility of mark price. Valid for option MarkIv string `json:"markIv"` // The mark price of the symbol when executing. Valid for option MarkPrice fixedpoint.Value `json:"markPrice"` // The index price of the symbol when executing. Valid for option IndexPrice fixedpoint.Value `json:"indexPrice"` // The underlying price of the symbol when executing. Valid for option UnderlyingPrice fixedpoint.Value `json:"underlyingPrice"` // Implied volatility. Valid for option TradeIv string `json:"tradeIv"` }
type WebSocketOpEvent ¶
type WebSocketOpEvent struct { Success bool `json:"success"` RetMsg string `json:"ret_msg"` ReqId string `json:"req_id,omitempty"` ConnId string `json:"conn_id"` Op WsOpType `json:"op"` Args []string `json:"args"` }
func (*WebSocketOpEvent) IsAuthenticated ¶
func (w *WebSocketOpEvent) IsAuthenticated() bool
func (*WebSocketOpEvent) IsValid ¶
func (w *WebSocketOpEvent) IsValid() error
type WebSocketTopicEvent ¶
type WebSocketTopicEvent struct { Topic string `json:"topic"` Type DataType `json:"type"` // The timestamp (ms) that the system generates the data Ts types.MillisecondTimestamp `json:"ts"` Data json.RawMessage `json:"data"` }
type WebsocketOp ¶
type WsEvent ¶
type WsEvent struct { // "op" and "topic" are exclusive. *WebSocketOpEvent *WebSocketTopicEvent }