fix max websocket subscription

This commit is contained in:
c9s 2021-02-22 17:36:23 +08:00
parent 73cb80ee96
commit 507586b560
2 changed files with 23 additions and 2 deletions

View File

@ -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,
})
}

View File

@ -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 {