fix(ftx): subscribe channel first to avoid losing order update

This commit is contained in:
Jui-Nan Lin 2021-05-24 09:21:49 +08:00
parent 14abd1436b
commit 02912f362c

View File

@ -48,8 +48,6 @@ func NewStream(key, secret string, subAccount string, e *Exchange) *Stream {
s.ws.OnMessage((&messageHandler{StandardStream: s.StandardStream}).handleMessage) s.ws.OnMessage((&messageHandler{StandardStream: s.StandardStream}).handleMessage)
s.ws.OnConnected(func(conn *websocket.Conn) { s.ws.OnConnected(func(conn *websocket.Conn) {
s.EmitConnect()
subs := []websocketRequest{newLoginRequest(s.key, s.secret, time.Now(), s.subAccount)} subs := []websocketRequest{newLoginRequest(s.key, s.secret, time.Now(), s.subAccount)}
subs = append(subs, s.subscriptions...) subs = append(subs, s.subscriptions...)
for _, sub := range subs { for _, sub := range subs {
@ -57,6 +55,8 @@ func NewStream(key, secret string, subAccount string, e *Exchange) *Stream {
s.ws.EmitError(fmt.Errorf("failed to send subscription: %+v", sub)) s.ws.EmitError(fmt.Errorf("failed to send subscription: %+v", sub))
} }
} }
s.EmitConnect()
}) })
go s.handleChannelKlineMessage() go s.handleChannelKlineMessage()