diff --git a/pkg/exchange/ftx/exchange.go b/pkg/exchange/ftx/exchange.go index 2cbb14a13..d43bb92b1 100644 --- a/pkg/exchange/ftx/exchange.go +++ b/pkg/exchange/ftx/exchange.go @@ -83,6 +83,7 @@ func NewExchange(key, secret string, subAccount string) *Exchange { } client := ftxapi.NewClient() + client.Auth(key, secret, subAccount) return &Exchange{ client: client, restEndpoint: u, @@ -363,6 +364,7 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type // If the limit is 1, we always get the same data from FTX. return nil, fmt.Errorf("limit can't be 1 which can't be used in pagination") } + limit := options.Limit if limit == 0 { limit = 200 @@ -389,21 +391,22 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type return fills[i].Id < fills[j].Id }) - for _, r := range fills { + for _, fill := range fills { // always update since to avoid infinite loop - since = r.Time + since = fill.Time - if _, ok := tradeIDs[r.Id]; ok { + if _, ok := tradeIDs[fill.Id]; ok { continue } - if r.Id <= lastTradeID || r.Time.Before(since) || r.Time.After(until) || r.Market != toLocalSymbol(symbol) { + if fill.Id <= lastTradeID || fill.Time.Before(since) || fill.Time.After(until) { continue } - tradeIDs[r.Id] = struct{}{} - lastTradeID = r.Id - t, err := toGlobalTrade(r) + tradeIDs[fill.Id] = struct{}{} + lastTradeID = fill.Id + + t, err := toGlobalTrade(fill) if err != nil { return nil, err } diff --git a/pkg/exchange/ftx/websocket_messages.go b/pkg/exchange/ftx/websocket_messages.go index 217a6b90e..830bed7db 100644 --- a/pkg/exchange/ftx/websocket_messages.go +++ b/pkg/exchange/ftx/websocket_messages.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/c9s/bbgo/pkg/exchange/ftx/ftxapi" "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -133,7 +134,7 @@ func (r websocketResponse) toOrderUpdateResponse() (orderUpdateResponse, error) type tradeUpdateResponse struct { mandatoryFields - Data fill `json:"data"` + Data ftxapi.Fill `json:"data"` } func (r websocketResponse) toTradeUpdateResponse() (tradeUpdateResponse, error) {