From c81af9ce91b3e090fc7ab3d8bcc7abdc97fa2e3b Mon Sep 17 00:00:00 2001 From: zenix Date: Mon, 9 May 2022 15:04:51 +0900 Subject: [PATCH] fix: binance futures sync issue --- pkg/cmd/sync.go | 2 +- pkg/exchange/binance/exchange.go | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/sync.go b/pkg/cmd/sync.go index d3bb001db..aa56cbb4f 100644 --- a/pkg/cmd/sync.go +++ b/pkg/cmd/sync.go @@ -20,7 +20,7 @@ func init() { } var SyncCmd = &cobra.Command{ - Use: "sync --session=[exchange_name] --symbol=[pair_name] [--since=yyyy/mm/dd]", + Use: "sync [--session=[exchange_name]] [--symbol=[pair_name]] [[--since=yyyy/mm/dd]]", Short: "sync trades and orders history", SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/pkg/exchange/binance/exchange.go b/pkg/exchange/binance/exchange.go index 8c2d1788a..0a977d416 100644 --- a/pkg/exchange/binance/exchange.go +++ b/pkg/exchange/binance/exchange.go @@ -1347,17 +1347,19 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type req.FromID(int64(options.LastTradeID)) } - if options.StartTime != nil && options.EndTime != nil { - if options.EndTime.Sub(*options.StartTime) < 24*time.Hour { - req.StartTime(options.StartTime.UnixMilli()) + // The parameter fromId cannot be sent with startTime or endTime. + // Mentioned in binance futures docs + if options.LastTradeID <= 0 { + if options.StartTime != nil && options.EndTime != nil { + if options.EndTime.Sub(*options.StartTime) < 24*time.Hour { + req.StartTime(options.StartTime.UnixMilli()) + req.EndTime(options.EndTime.UnixMilli()) + } else { + req.StartTime(options.StartTime.UnixMilli()) + } + } else if options.EndTime != nil { req.EndTime(options.EndTime.UnixMilli()) - } else { - req.StartTime(options.StartTime.UnixMilli()) } - } else if options.StartTime != nil { - req.StartTime(options.StartTime.UnixMilli()) - } else if options.EndTime != nil { - req.EndTime(options.EndTime.UnixMilli()) } remoteTrades, err = req.Do(ctx)