Documentation
¶
Index ¶
- Constants
- func TransformEvent[E any](event Event) (E, error)
- type AsksAndBids
- type AssetBalance
- type Command
- func NewAuthorizeCommand(token string) Command
- func NewDealsCommand(market string, offset int64, limit int64) Command
- func NewDealsUnsubscribe() Command
- func NewDepthUnsubscribe() Command
- func NewKlineCommand(market string, startTime int64, endTime int64, interval int64) Command
- func NewKlineUnsubscribe() Command
- func NewLastPriceCommand(market string) Command
- func NewLastPriceUnsubscribe() Command
- func NewMarginBalanceCommand(assets []string) Command
- func NewMarginBalanceUnsubscribe() Command
- func NewMarketDepthCommand(market string, limit int64, priceInterval string) Command
- func NewMarketStatCommand(market string, period int64) Command
- func NewMarketStatTodayCommand(market string) Command
- func NewMarketStatTodayUnsubscribe() Command
- func NewMarketStatUnsubscribe() Command
- func NewMarketTradesCommand(market string, limit int64, startTradeID int64) Command
- func NewMarketTradesUnsubscribe() Command
- func NewOrdersExecutedCommand(market string, orderTypes []int64, limit int64, offset int64) Command
- func NewOrdersExecutedUnsubscribe() Command
- func NewOrdersPendingUnsubscribe() Command
- func NewPendingOrdersCommand(market string, offset int64, limit int64) Command
- func NewPingCommand() Command
- func NewSpotBalanceCommand(assets []string) Command
- func NewSpotBalanceUnsubscribe() Command
- func NewStreamCommand(id int64, method string, params []any) Command
- func NewTimeCommand() Command
- func NewUnsubscribeCommand(method string) Command
- type CommandHandler
- type CommandReply
- type Deal
- type Deals
- type DealsResult
- type DealsUpdateEvent
- type Event
- type ExecutedOrders
- type Kline
- type KlineResult
- type KlineUpdateEvent
- type LastPrice
- type LastPriceUpdateEvent
- type MarginBalance
- type MarginBalanceEventInfo
- type MarginBalanceQueryInfo
- type MarginBalanceResponse
- type MarginBalanceUpdateEvent
- type MarketDepth
- type MarketDepthUpdateEvent
- type MarketStat
- type MarketStatResult
- type MarketStatTodayUpdateEvent
- type MarketStatUpdateEvent
- type MarketTrades
- type MarketTradesResult
- type MarketTradesUpdateEvent
- type OrderExecutedUpdateEvent
- type Orders
- type OrdersExecuted
- type OrdersRecords
- type Pair
- type Pending
- type PendingOrders
- type PendingOrdersUpdateEvent
- type Ping
- type Response
- type ResponsePagination
- type SpotBalance
- type SpotBalanceUpdateEvent
- type Stream
- type Subscription
- func NewDealsSubscription(handle func(event DealsUpdateEvent), market []string) *Subscription
- func NewKlineSubscription(handle func(event KlineUpdateEvent), market string, interval int64) *Subscription
- func NewLastPriceSubscription(handle func(event LastPriceUpdateEvent), market []string) *Subscription
- func NewMarginBalanceSubscription(handle func(event MarginBalanceUpdateEvent), assets ...string) *Subscription
- func NewMarketDepthSubscription(handle func(MarketDepthUpdateEvent), market string, limit int64, ...) *Subscription
- func NewMarketStatSubscription(handle func(MarketStatUpdateEvent), market []string) *Subscription
- func NewMarketStatTodaySubscription(handle func(MarketStatTodayUpdateEvent), market []string) *Subscription
- func NewMarketTradesSubscription(handle func(MarketTradesUpdateEvent), market []string) *Subscription
- func NewOrderExecutedSubscription(handle func(event OrderExecutedUpdateEvent), market []string, filter int64) *Subscription
- func NewPendingOrdersSubscription(handle func(event PendingOrdersUpdateEvent), market ...string) *Subscription
- func NewSpotBalanceSubscription(handle func(event SpotBalanceUpdateEvent), assets ...string) *Subscription
- type Time
Constants ¶
const ( TypeLimit = 1 TypeMarket = 2 TypeStopLimit = 3 TypeStopMarket = 4 TypeConditionalLimit = 5 TypeConditionalMarket = 6 TypeMarginMarket = 8 TypeMarginStopLimit = 9 TypeMarginTriggerStopMarket = 10 TypeCollateralNormalization = 14 TypeMarketStock = 202 )
Order type constants.
const ( PingRequest = "ping" TimeRequest = "time" KlineRequest = "candles_request" KlineSubscribe = "candles_subscribe" KlineUpdate = "candles_update" KlineUnsubscribe = "candles_unsubscribe" DepthRequest = "depth_request" DepthSubscribe = "depth_subscribe" DepthUpdate = "depth_update" DepthUnsubscribe = "depth_unsubscribe" LastPriceRequest = "lastprice_request" LastPriceSubscribe = "lastprice_subscribe" LastPriceUpdate = "lastprice_update" LastPriceUnsubscribe = "lastprice_unsubscribe" MarketStatRequest = "market_request" MarketStatSubscribe = "market_subscribe" MarketStatUpdate = "market_update" MarketStatUnsubscribe = "market_unsubscribe" MarketStatTodayRequest = "marketToday_query" MarketStatTodaySubscribe = "marketToday_subscribe" MarketStatTodayUpdate = "marketToday_update" MarketStatTodayUnsubscribe = "marketToday_unsubscribe" TradesRequest = "trades_request" TradesSubscribe = "trades_subscribe" TradesUpdate = "trades_update" TradesUnsubscribe = "trades_unsubscribe" OrderPendingRequest = "ordersPending_request" OrdersPendingSubscribe = "ordersPending_subscribe" OrdersPendingUpdate = "ordersPending_update" OrdersPendingUnsubscribe = "ordersPending_unsubscribe" DealsRequest = "deals_request" DealsSubscribe = "deals_subscribe" DealsUpdate = "deals_update" DealsUnsubscribe = "deals_unsubscribe" SpotBalanceRequest = "balanceSpot_request" SpotBalanceSubscribe = "balanceSpot_subscribe" SpotBalanceUpdate = "balanceSpot_update" SpotBalanceUnsubscribe = "balanceSpot_unsubscribe" OrdersExecutedRequest = "ordersExecuted_request" OrdersExecutedSubscribe = "ordersExecuted_subscribe" OrdersExecutedUpdate = "ordersExecuted_update" OrdersExecutedUnsubscribe = "ordersExecuted_unsubscribe" MarginBalanceRequest = "balanceMargin_request" MarginBalanceSubscribe = "balanceMargin_subscribe" MarginBalanceUpdate = "balanceMargin_update" MarginBalanceUnsubscribe = "balanceMargin_unsubscribe" WsTypeQuery = true WsTypeSubscribe = false )
WebSocket method constants.
const ( // ReadTimeout is the maximum duration for read operations on the WebSocket connection. ReadTimeout = 60 * time.Second // WriteTimeout is the maximum duration for write operations on the WebSocket connection. WriteTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func TransformEvent ¶
TransformEvent converts a generic Event into a typed event struct.
Types ¶
type AsksAndBids ¶
AsksAndBids contains asks and bids from the order book.
type AssetBalance ¶
AssetBalance represents the balance of an asset.
type Command ¶
type Command struct {
ID int64 `json:"id"`
Method string `json:"method"`
Params []any `json:"params"`
IsQuery bool `json:"-"`
}
Command represents a WebSocket command to send to the server.
func NewAuthorizeCommand ¶
NewAuthorizeCommand creates an authorization command with the given token.
func NewDealsCommand ¶
NewDealsCommand creates a deals query command.
func NewDealsUnsubscribe ¶
func NewDealsUnsubscribe() Command
NewDealsUnsubscribe creates a deals unsubscribe command.
func NewDepthUnsubscribe ¶
func NewDepthUnsubscribe() Command
NewDepthUnsubscribe creates a market depth unsubscribe command.
func NewKlineCommand ¶
NewKlineCommand creates a kline query command.
func NewKlineUnsubscribe ¶
func NewKlineUnsubscribe() Command
NewKlineUnsubscribe creates a kline unsubscribe command.
func NewLastPriceCommand ¶
NewLastPriceCommand creates a last price query command.
func NewLastPriceUnsubscribe ¶
func NewLastPriceUnsubscribe() Command
NewLastPriceUnsubscribe creates a last price unsubscribe command.
func NewMarginBalanceCommand ¶
NewMarginBalanceCommand creates a margin balance query command.
func NewMarginBalanceUnsubscribe ¶
func NewMarginBalanceUnsubscribe() Command
NewMarginBalanceUnsubscribe creates a margin balance unsubscribe command.
func NewMarketDepthCommand ¶
NewMarketDepthCommand creates a market depth query command.
func NewMarketStatCommand ¶
NewMarketStatCommand creates a market statistics query command.
func NewMarketStatTodayCommand ¶
NewMarketStatTodayCommand creates a market statistics today query command.
func NewMarketStatTodayUnsubscribe ¶
func NewMarketStatTodayUnsubscribe() Command
NewMarketStatTodayUnsubscribe creates a market statistics today unsubscribe command.
func NewMarketStatUnsubscribe ¶
func NewMarketStatUnsubscribe() Command
NewMarketStatUnsubscribe creates a market statistics unsubscribe command.
func NewMarketTradesCommand ¶
NewMarketTradesCommand creates a market trades query command.
func NewMarketTradesUnsubscribe ¶
func NewMarketTradesUnsubscribe() Command
NewMarketTradesUnsubscribe creates a market trades unsubscribe command.
func NewOrdersExecutedCommand ¶
NewOrdersExecutedCommand creates an executed orders query command.
func NewOrdersExecutedUnsubscribe ¶
func NewOrdersExecutedUnsubscribe() Command
NewOrdersExecutedUnsubscribe creates an executed orders unsubscribe command.
func NewOrdersPendingUnsubscribe ¶
func NewOrdersPendingUnsubscribe() Command
NewOrdersPendingUnsubscribe creates a pending orders unsubscribe command.
func NewPendingOrdersCommand ¶
NewPendingOrdersCommand creates a pending orders query command.
func NewSpotBalanceCommand ¶
NewSpotBalanceCommand creates a spot balance query command.
func NewSpotBalanceUnsubscribe ¶
func NewSpotBalanceUnsubscribe() Command
NewSpotBalanceUnsubscribe creates a spot balance unsubscribe command.
func NewStreamCommand ¶
NewStreamCommand creates a generic stream command.
func NewTimeCommand ¶
func NewTimeCommand() Command
NewTimeCommand creates a server time query command.
func NewUnsubscribeCommand ¶
NewUnsubscribeCommand creates a generic unsubscribe command.
type CommandHandler ¶
CommandHandler associates a Command with its response handler callback.
type CommandReply ¶
CommandReply represents a response to a Command from the server.
type Deal ¶
type Deal struct {
Time float64 `json:"time"`
ID int `json:"id"`
Side int `json:"side"`
Role int `json:"role"`
Price string `json:"price"`
Amount string `json:"amount"`
Deal string `json:"deal"`
Fee string `json:"fee"`
Market string `json:"market"`
DealOrderID int64 `json:"deal_order_id"`
}
Deal represents a single deal/trade.
type Deals ¶
type Deals struct {
Response
Result DealsResult `json:"result"`
}
Deals represents a deals response.
type DealsResult ¶
type DealsResult struct {
ResponsePagination
Records []Deal `json:"records"`
}
DealsResult contains a paginated list of deals.
type DealsUpdateEvent ¶
type DealsUpdateEvent struct {
Params []any `json:"params"`
}
DealsUpdateEvent represents a deals update event.
type Event ¶
type Event struct {
Method string `json:"method"`
Params []any `json:"params"`
ID int64 `json:"id"`
}
Event represents a WebSocket event received from the server.
type ExecutedOrders ¶
ExecutedOrders represents an executed orders response.
type Kline ¶
type Kline struct {
Response
Result []KlineResult `json:"result"`
}
Kline represents a kline response.
type KlineResult ¶
type KlineResult struct {
Time int64
Open string
Close string
Highest string
Lowest string
StockVolume string
DealVolume string
Market string
}
KlineResult represents a single kline/candlestick data point.
type KlineUpdateEvent ¶
type KlineUpdateEvent struct {
Params []any `json:"params"`
}
KlineUpdateEvent represents a kline update event.
type LastPriceUpdateEvent ¶
type LastPriceUpdateEvent struct {
Params any `json:"params"`
}
LastPriceUpdateEvent represents a last price update event.
type MarginBalance ¶
type MarginBalance map[string]MarginBalanceQueryInfo
MarginBalance is a map of asset name to margin balance info.
type MarginBalanceEventInfo ¶
type MarginBalanceEventInfo struct {
Balance string `json:"B"`
Asset string `json:"a"`
AvailableWithBorrow string `json:"ab"`
AvailableWithoutBorrow string `json:"av"`
Borrow string `json:"b"`
}
MarginBalanceEventInfo contains margin balance event details.
type MarginBalanceQueryInfo ¶
type MarginBalanceQueryInfo struct {
AvailableWithBorrow string `json:"available_with_borrow"`
AvailableWithoutBorrow string `json:"available_without_borrow"`
Balance string `json:"balance"`
Borrow string `json:"borrow"`
}
MarginBalanceQueryInfo contains margin balance query details.
type MarginBalanceResponse ¶
MarginBalanceResponse represents a margin balance response.
type MarginBalanceUpdateEvent ¶
type MarginBalanceUpdateEvent struct {
Balances []MarginBalanceEventInfo `json:"params"`
}
MarginBalanceUpdateEvent represents a margin balance update event.
type MarketDepth ¶
type MarketDepth struct {
Response
Result []AsksAndBids `json:"result"`
}
MarketDepth represents a market depth response.
type MarketDepthUpdateEvent ¶
type MarketDepthUpdateEvent struct {
Params []any `json:"params"`
}
MarketDepthUpdateEvent represents a market depth update event.
type MarketStat ¶
type MarketStat struct {
Response
Result MarketStatResult `json:"result"`
}
MarketStat represents a market statistics response.
type MarketStatResult ¶
type MarketStatResult struct {
Period int `json:"period"`
Last string `json:"last"`
Open string `json:"open"`
Close string `json:"close"`
High string `json:"high"`
Low string `json:"low"`
Volume string `json:"volume"`
Deal string `json:"deal"`
}
MarketStatResult contains market statistics data.
type MarketStatTodayUpdateEvent ¶
type MarketStatTodayUpdateEvent struct {
Params []any `json:"params"`
}
MarketStatTodayUpdateEvent represents a market statistics today update event.
type MarketStatUpdateEvent ¶
type MarketStatUpdateEvent struct {
Params []any `json:"params"`
}
MarketStatUpdateEvent represents a market statistics update event.
type MarketTrades ¶
type MarketTrades struct {
Response
Result MarketTradesResult `json:"result"`
}
MarketTrades represents a market trades response.
type MarketTradesResult ¶
type MarketTradesResult struct {
ID int `json:"id"`
Time float64 `json:"time"`
Price string `json:"price"`
Amount string `json:"amount"`
Type string `json:"type"`
}
MarketTradesResult contains a single market trade.
type MarketTradesUpdateEvent ¶
type MarketTradesUpdateEvent struct {
Params []any `json:"params"`
}
MarketTradesUpdateEvent represents a market trades update event.
type OrderExecutedUpdateEvent ¶
type OrderExecutedUpdateEvent struct {
Params []OrdersRecords `json:"params"`
}
OrderExecutedUpdateEvent represents an executed order update event.
type Orders ¶
type Orders struct {
ResponsePagination
Records []OrdersRecords `json:"records"`
}
Orders contains a paginated list of order records.
type OrdersExecuted ¶
type OrdersExecuted struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Records []OrdersRecords `json:"records"`
}
OrdersExecuted contains executed order records with pagination.
type OrdersRecords ¶
type OrdersRecords struct {
ID int `json:"id"`
Market string `json:"market"`
Type int `json:"type"`
Side int `json:"side"`
PostOnly bool `json:"post_only"`
IOC bool `json:"ioc"`
Ctime float64 `json:"ctime"`
Mtime float64 `json:"mtime"`
Price string `json:"price"`
Amount string `json:"amount"`
Left string `json:"left"`
DealStock string `json:"deal_stock"`
DealMoney string `json:"deal_money"`
DealFee string `json:"deal_fee"`
ClientOrderID string `json:"client_order_id"`
}
OrdersRecords contains order details.
type Pending ¶
type Pending struct {
ID int64
PendingOrdersRecords OrdersRecords
}
Pending represents a pending order.
type PendingOrders ¶
PendingOrders represents a pending orders response.
type PendingOrdersUpdateEvent ¶
type PendingOrdersUpdateEvent struct {
Balances []any `json:"params"`
}
PendingOrdersUpdateEvent represents a pending orders update event.
type ResponsePagination ¶
type ResponsePagination struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Total int `json:"total"`
}
ResponsePagination contains pagination info from paginated responses.
type SpotBalance ¶
type SpotBalance struct {
Response
Result map[string]AssetBalance
}
SpotBalance represents a spot balance response.
type SpotBalanceUpdateEvent ¶
type SpotBalanceUpdateEvent struct {
Balances []map[string]AssetBalance `json:"params"`
}
SpotBalanceUpdateEvent represents a spot balance update event.
type Stream ¶
type Stream struct {
URL string
// contains filtered or unexported fields
}
Stream manages a WebSocket connection to the WhiteBit API, handling subscriptions, queries, automatic reconnection, and keepalive pings.
func NewStream ¶
NewStream creates a new WebSocket stream connection to the WhiteBit API. If token is non-empty, the connection will be authorized. The errorHandler is called for any asynchronous errors and must not be nil. The provided context controls the lifetime of the connection.
func (*Stream) Subscribe ¶
func (stream *Stream) Subscribe(command *Subscription) error
Subscribe sends a subscription command and registers the event handler.
func (*Stream) Unsubscribe ¶
func (stream *Stream) Unsubscribe(sub *Subscription) error
Unsubscribe sends an unsubscribe command and removes the subscription from the stream.
type Subscription ¶
type Subscription struct {
Command
EventMethod string
OnEvent func(event Event)
UnsubscribeMethod Command
// contains filtered or unexported fields
}
Subscription represents a WebSocket subscription with an event handler.
func NewDealsSubscription ¶
func NewDealsSubscription(handle func(event DealsUpdateEvent), market []string) *Subscription
NewDealsSubscription creates a subscription for deal updates.
func NewKlineSubscription ¶
func NewKlineSubscription(handle func(event KlineUpdateEvent), market string, interval int64) *Subscription
NewKlineSubscription creates a subscription for kline/candlestick updates.
func NewLastPriceSubscription ¶
func NewLastPriceSubscription(handle func(event LastPriceUpdateEvent), market []string) *Subscription
NewLastPriceSubscription creates a subscription for last price updates.
func NewMarginBalanceSubscription ¶
func NewMarginBalanceSubscription(handle func(event MarginBalanceUpdateEvent), assets ...string) *Subscription
NewMarginBalanceSubscription creates a subscription for margin balance updates.
func NewMarketDepthSubscription ¶
func NewMarketDepthSubscription(handle func(MarketDepthUpdateEvent), market string, limit int64, priceInterval string, multiSubscription bool) *Subscription
NewMarketDepthSubscription creates a subscription for market depth updates.
func NewMarketStatSubscription ¶
func NewMarketStatSubscription(handle func(MarketStatUpdateEvent), market []string) *Subscription
NewMarketStatSubscription creates a subscription for market statistics updates.
func NewMarketStatTodaySubscription ¶
func NewMarketStatTodaySubscription(handle func(MarketStatTodayUpdateEvent), market []string) *Subscription
NewMarketStatTodaySubscription creates a subscription for today's market statistics updates.
func NewMarketTradesSubscription ¶
func NewMarketTradesSubscription(handle func(MarketTradesUpdateEvent), market []string) *Subscription
NewMarketTradesSubscription creates a subscription for market trade updates.
func NewOrderExecutedSubscription ¶
func NewOrderExecutedSubscription(handle func(event OrderExecutedUpdateEvent), market []string, filter int64) *Subscription
NewOrderExecutedSubscription creates a subscription for executed order updates.
func NewPendingOrdersSubscription ¶
func NewPendingOrdersSubscription(handle func(event PendingOrdersUpdateEvent), market ...string) *Subscription
NewPendingOrdersSubscription creates a subscription for pending order updates.
func NewSpotBalanceSubscription ¶
func NewSpotBalanceSubscription(handle func(event SpotBalanceUpdateEvent), assets ...string) *Subscription
NewSpotBalanceSubscription creates a subscription for spot balance updates.