mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
fix max websocket subscription
This commit is contained in:
parent
73cb80ee96
commit
507586b560
|
@ -14,6 +14,11 @@ var WebSocketURL = "wss://max-stream.maicoin.com/ws"
|
|||
|
||||
var ErrMessageTypeNotSupported = errors.New("message type currently not supported")
|
||||
|
||||
type SubscribeOptions struct {
|
||||
Depth int `json:"depth,omitempty"`
|
||||
Resolution string `json:"resolution,omitempty"`
|
||||
}
|
||||
|
||||
// Subscription is used for presenting the subscription metadata.
|
||||
// This is used for sending subscribe and unsubscribe requests
|
||||
type Subscription struct {
|
||||
|
@ -212,10 +217,12 @@ func (s *WebSocketService) Reconnect() {
|
|||
|
||||
// Subscribe is a helper method for building subscription request from the internal mapping types.
|
||||
// (Internal public method)
|
||||
func (s *WebSocketService) Subscribe(channel, market string) {
|
||||
func (s *WebSocketService) Subscribe(channel, market string, options SubscribeOptions) {
|
||||
s.AddSubscription(Subscription{
|
||||
Channel: channel,
|
||||
Market: market,
|
||||
Depth: options.Depth,
|
||||
Resolution: options.Resolution,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,21 @@ func (s *Stream) SetPublicOnly() {
|
|||
}
|
||||
|
||||
func (s *Stream) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) {
|
||||
s.websocketService.Subscribe(string(channel), toLocalSymbol(symbol))
|
||||
opt := max.SubscribeOptions{}
|
||||
|
||||
if len(options.Depth) > 0 {
|
||||
depth, err := strconv.Atoi(options.Depth)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
opt.Depth = depth
|
||||
}
|
||||
|
||||
if len(options.Interval) > 0 {
|
||||
opt.Resolution = options.Interval
|
||||
}
|
||||
|
||||
s.websocketService.Subscribe(string(channel), toLocalSymbol(symbol), opt)
|
||||
}
|
||||
|
||||
func (s *Stream) Connect(ctx context.Context) error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user