ftxapi: replace fill implementation

This commit is contained in:
c9s 2022-03-02 14:35:35 +08:00
parent 833354e553
commit 883f0ed83a
2 changed files with 12 additions and 8 deletions

View File

@ -83,6 +83,7 @@ func NewExchange(key, secret string, subAccount string) *Exchange {
} }
client := ftxapi.NewClient() client := ftxapi.NewClient()
client.Auth(key, secret, subAccount)
return &Exchange{ return &Exchange{
client: client, client: client,
restEndpoint: u, 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. // 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") return nil, fmt.Errorf("limit can't be 1 which can't be used in pagination")
} }
limit := options.Limit limit := options.Limit
if limit == 0 { if limit == 0 {
limit = 200 limit = 200
@ -389,21 +391,22 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
return fills[i].Id < fills[j].Id return fills[i].Id < fills[j].Id
}) })
for _, r := range fills { for _, fill := range fills {
// always update since to avoid infinite loop // 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 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 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/c9s/bbgo/pkg/exchange/ftx/ftxapi"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
@ -133,7 +134,7 @@ func (r websocketResponse) toOrderUpdateResponse() (orderUpdateResponse, error)
type tradeUpdateResponse struct { type tradeUpdateResponse struct {
mandatoryFields mandatoryFields
Data fill `json:"data"` Data ftxapi.Fill `json:"data"`
} }
func (r websocketResponse) toTradeUpdateResponse() (tradeUpdateResponse, error) { func (r websocketResponse) toTradeUpdateResponse() (tradeUpdateResponse, error) {