You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.1 KiB
66 lines
2.1 KiB
package okx |
|
|
|
// 交易频道 channel: trades |
|
// 获取最近的成交数据,有成交数据就推送,每次推送可能聚合多条成交数据。 |
|
// 根据每个taker订单的不同成交价格推送消息,并使用count字段表示聚合的订单匹配数量。 |
|
|
|
type TradesData struct { |
|
InstId string `json:"instId"` // 产品ID,如 DOGE-USDT-SWAP |
|
TradeId string `json:"tradeId"` // 聚合的多笔交易中最新一笔交易的成交ID |
|
Px string `json:"px"` // 成交价格 |
|
Sz string `json:"sz"` // 成交数量 |
|
Side TradeSide `json:"side"` // 成交方向buy/sell |
|
Ts string `json:"ts"` // 成交时间,Unix时间戳的毫秒数格式,如 1597026383085 |
|
Count string `json:"count"` // 聚合的订单匹配数量 |
|
} |
|
|
|
// ChannelTrades 交易频道 |
|
type ChannelTrades struct { |
|
cfg wsChannelConfig[*[]TradesData, *ChannelData[*[]TradesData]] |
|
wsChannel *wsChannel[*[]TradesData, *ChannelData[*[]TradesData]] |
|
} |
|
|
|
func NewChannelTrades( |
|
traceId string, |
|
httpProxy string, |
|
) *ChannelTrades { |
|
cfg := wsChannelConfig[*[]TradesData, *ChannelData[*[]TradesData]]{ |
|
channelId: traceId, |
|
httpProxy: httpProxy, |
|
wsUrl: "/ws/v5/public", |
|
subscribeChannels: []string{"trades"}, |
|
dataInstanceFunc: func() *[]TradesData { |
|
var d []TradesData |
|
return &d |
|
}, |
|
dataMappingFunc: func(data *ChannelData[*[]TradesData]) (*ChannelData[*[]TradesData], error) { |
|
return data, nil |
|
}, |
|
} |
|
return &ChannelTrades{cfg: cfg} |
|
} |
|
|
|
func (c *ChannelTrades) Init() (err error) { |
|
c.wsChannel = newWsChannel(c.cfg) |
|
return c.wsChannel.Init() |
|
} |
|
|
|
func (c *ChannelTrades) Consumer() <-chan *ChannelData[*[]TradesData] { |
|
return c.wsChannel.Consumer() |
|
} |
|
|
|
func (c *ChannelTrades) Subscribe(instIds ...string) (err error) { |
|
return c.wsChannel.Subscribe(instIds...) |
|
} |
|
|
|
func (c *ChannelTrades) Unsubscribe(instIds ...string) (err error) { |
|
return c.wsChannel.Unsubscribe(instIds...) |
|
} |
|
|
|
func (c *ChannelTrades) IsSubscribe(instId string) bool { |
|
return c.wsChannel.IsSubscribed(instId) |
|
} |
|
|
|
func (c *ChannelTrades) GetSubscribes() (instIds []string) { |
|
return c.wsChannel.GetSubscribes() |
|
}
|
|
|