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.
 
 

71 lines
1.7 KiB

package okx
import (
"sig-pub/api/pb"
"sig-pub/pkg/config"
"sig-pub/pkg/types"
)
var subscribeCandles = map[types.Interval]string{
// "3M", "1M", "1W", "1D", "2D", "3D", "5D",
// "12H", "6H", "4H", "2H", "1H",
// "30m", "15m", "5m", "3m", "1m",
// "1s",
types.Interval1s: "1s",
types.Interval1m: "1m",
types.Interval3m: "3m",
types.Interval5m: "5m",
types.Interval15m: "15m",
types.Interval30m: "30m",
types.Interval1h: "1H",
types.Interval2h: "2H",
types.Interval4h: "4H",
types.Interval6h: "6H",
types.Interval12h: "12H",
types.Interval1d: "1D",
types.Interval2d: "2D",
types.Interval3d: "3D",
types.Interval5d: "5D",
types.Interval1w: "1W",
types.Interval1mo: "1M",
types.Interval3mo: "3M",
}
// kline
type OkxSubscriber struct {
conf config.OkxExchange
channelCandle *ChannelCandle // K线频道
}
func NewOkxSubscriber(conf config.OkxExchange) *OkxSubscriber {
return &OkxSubscriber{
conf: conf,
}
}
func (okx *OkxSubscriber) Init() (err error) {
// TODO 多个 ChannelCandle 实例 OkxAggregate
okx.channelCandle = NewChannelCandle("candle-0", okx.conf.HttpProxy)
if err = okx.channelCandle.Init(); err != nil {
return
}
return
}
func (okx *OkxSubscriber) ExhcangeType() pb.ExchangeType {
return pb.ExchangeType_OKX
}
func (okx *OkxSubscriber) ConsumerKline() <-chan *types.ChannelKline {
return okx.channelCandle.Consumer()
}
// 订阅产品k线行情
func (okx *OkxSubscriber) SubscribeKline(instIds ...string) (err error) {
return okx.channelCandle.Subscribe(instIds...)
}
// 取消订阅产品k线行情
func (okx *OkxSubscriber) UnsubscribeKline(instIds ...string) (err error) {
return okx.channelCandle.Unsubscribe(instIds...)
}