diff --git a/pkg/exchange/ftx/exchange.go b/pkg/exchange/ftx/exchange.go index 23daa0390..6a2f6f3f2 100644 --- a/pkg/exchange/ftx/exchange.go +++ b/pkg/exchange/ftx/exchange.go @@ -87,7 +87,7 @@ func (e *Exchange) PlatformFeeCurrency() string { } func (e *Exchange) NewStream() types.Stream { - return NewStream(e.key, e.secret, e) + return NewStream(e.key, e.secret, e.subAccount, e) } func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { diff --git a/pkg/exchange/ftx/stream.go b/pkg/exchange/ftx/stream.go index 383e3a2c6..b184dc050 100644 --- a/pkg/exchange/ftx/stream.go +++ b/pkg/exchange/ftx/stream.go @@ -28,12 +28,13 @@ type Stream struct { key string secret string + subAccount string // subscriptions are only accessed in single goroutine environment, so I don't use mutex to protect them subscriptions []websocketRequest } -func NewStream(key, secret string, e *Exchange) *Stream { +func NewStream(key, secret string, subAccount string, e *Exchange) *Stream { s := &Stream{ exchange: e, isConnected: false, @@ -47,7 +48,7 @@ func NewStream(key, secret string, e *Exchange) *Stream { s.ws.OnMessage((&messageHandler{StandardStream: s.StandardStream}).handleMessage) s.ws.OnConnected(func(conn *websocket.Conn) { - subs := []websocketRequest{newLoginRequest(s.key, s.secret, time.Now())} + subs := []websocketRequest{newLoginRequest(s.key, s.secret, time.Now(), s.subAccount)} subs = append(subs, s.subscriptions...) for _, sub := range subs { if err := conn.WriteJSON(sub); err != nil { diff --git a/pkg/exchange/ftx/websocket_messages.go b/pkg/exchange/ftx/websocket_messages.go index 6ae213f7f..08fd64c15 100644 --- a/pkg/exchange/ftx/websocket_messages.go +++ b/pkg/exchange/ftx/websocket_messages.go @@ -61,14 +61,15 @@ type loginArgs struct { SubAccount string `json:"subaccount"` } -func newLoginRequest(key, secret string, t time.Time) websocketRequest { +func newLoginRequest(key, secret string, t time.Time, subsaccount string) websocketRequest { millis := t.UnixNano() / int64(time.Millisecond) return websocketRequest{ Operation: login, Login: loginArgs{ - Key: key, - Signature: sign(secret, loginBody(millis)), - Time: millis, + Key: key, + Signature: sign(secret, loginBody(millis)), + Time: millis, + SubAccount: subsaccount, }, } } diff --git a/pkg/exchange/ftx/websocket_messages_test.go b/pkg/exchange/ftx/websocket_messages_test.go index 2212b2072..96a20c5cc 100644 --- a/pkg/exchange/ftx/websocket_messages_test.go +++ b/pkg/exchange/ftx/websocket_messages_test.go @@ -180,7 +180,7 @@ func Test_insertAt(t *testing.T) { func Test_newLoginRequest(t *testing.T) { // From API doc: https://docs.ftx.com/?javascript#authentication-2 - r := newLoginRequest("", "Y2QTHI23f23f23jfjas23f23To0RfUwX3H42fvN-", time.Unix(0, 1557246346499*int64(time.Millisecond))) + r := newLoginRequest("", "Y2QTHI23f23f23jfjas23f23To0RfUwX3H42fvN-", time.Unix(0, 1557246346499*int64(time.Millisecond)), "") expectedSignature := "d10b5a67a1a941ae9463a60b285ae845cdeac1b11edc7da9977bef0228b96de9" assert.Equal(t, expectedSignature, r.Login.Signature) jsonStr, err := json.Marshal(r)