mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 17:13:51 +00:00
fix(ftx): support subaccount in websocket
This commit is contained in:
parent
05bde543b7
commit
fb47a4882f
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user