fix: binance futures sync issue

This commit is contained in:
zenix 2022-05-09 15:04:51 +09:00
parent 3af08abef2
commit c81af9ce91
2 changed files with 12 additions and 10 deletions

View File

@ -20,7 +20,7 @@ func init() {
} }
var SyncCmd = &cobra.Command{ 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", Short: "sync trades and orders history",
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View File

@ -1347,17 +1347,19 @@ func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *type
req.FromID(int64(options.LastTradeID)) req.FromID(int64(options.LastTradeID))
} }
if options.StartTime != nil && options.EndTime != nil { // The parameter fromId cannot be sent with startTime or endTime.
if options.EndTime.Sub(*options.StartTime) < 24*time.Hour { // Mentioned in binance futures docs
req.StartTime(options.StartTime.UnixMilli()) 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()) 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) remoteTrades, err = req.Do(ctx)