diff --git a/pkg/exchange/max/maxapi/websocket.go b/pkg/exchange/max/maxapi/websocket.go index dcdf7143c..19e9acb5b 100644 --- a/pkg/exchange/max/maxapi/websocket.go +++ b/pkg/exchange/max/maxapi/websocket.go @@ -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, }) } diff --git a/pkg/exchange/max/stream.go b/pkg/exchange/max/stream.go index a34c971da..e5d06797c 100644 --- a/pkg/exchange/max/stream.go +++ b/pkg/exchange/max/stream.go @@ -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 {