diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 600f9df19..be6c8d728 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -293,7 +293,7 @@ func (session *ExchangeSession) InitSymbol(ctx context.Context, environ *Environ var trades []types.Trade if environ.TradeSync != nil { log.Infof("syncing trades from %s for symbol %s...", session.Exchange.Name(), symbol) - if err := environ.TradeSync.SyncTrades(ctx, session.Exchange, symbol, environ.tradeScanTime); err != nil { + if err := environ.TradeSync.SyncTrades(ctx, session.Exchange, symbol); err != nil { return err } diff --git a/pkg/bbgo/sync.go b/pkg/bbgo/sync.go deleted file mode 100644 index 920078f66..000000000 --- a/pkg/bbgo/sync.go +++ /dev/null @@ -1,2 +0,0 @@ -package bbgo - diff --git a/pkg/exchange/batch/batch.go b/pkg/exchange/batch/batch.go index 4b175386f..8f6773002 100644 --- a/pkg/exchange/batch/batch.go +++ b/pkg/exchange/batch/batch.go @@ -118,12 +118,6 @@ func (e ExchangeBatchProcessor) BatchQueryTrades(ctx context.Context, symbol str var lastTradeID = options.LastTradeID - // last 7 days - var startTime = time.Now().Add(-7 * 24 * time.Hour) - if options.StartTime != nil { - startTime = *options.StartTime - } - go func() { limiter := rate.NewLimiter(rate.Every(5*time.Second), 2) // from binance (original 1200, use 1000 for safety) @@ -137,13 +131,12 @@ func (e ExchangeBatchProcessor) BatchQueryTrades(ctx context.Context, symbol str logrus.WithError(err).Error("rate limit error") } - logrus.Infof("querying %s trades from %s, limit=%d", symbol, startTime, options.Limit) + logrus.Debugf("querying %s trades from id=%d limit=%d", symbol, lastTradeID, options.Limit) var err error var trades []types.Trade trades, err = e.Exchange.QueryTrades(ctx, symbol, &types.TradeQueryOptions{ - StartTime: &startTime, Limit: options.Limit, LastTradeID: lastTradeID, }) @@ -164,8 +157,6 @@ func (e ExchangeBatchProcessor) BatchQueryTrades(ctx context.Context, symbol str logrus.Debugf("returned %d trades", len(trades)) - // increase the window to the next time frame by adding 1 millisecond - startTime = time.Time(trades[len(trades)-1].Time) for _, t := range trades { key := t.Key() if _, ok := tradeKeys[key]; ok { diff --git a/pkg/service/sync.go b/pkg/service/sync.go index 018af5fb4..ba6b2edc0 100644 --- a/pkg/service/sync.go +++ b/pkg/service/sync.go @@ -65,7 +65,7 @@ func (s *SyncService) SyncOrders(ctx context.Context, exchange types.Exchange, s return <-errC } -func (s *SyncService) SyncTrades(ctx context.Context, exchange types.Exchange, symbol string, startTime time.Time) error { +func (s *SyncService) SyncTrades(ctx context.Context, exchange types.Exchange, symbol string) error { isMargin := false isIsolated := false if marginExchange, ok := exchange.(types.MarginExchange); ok { @@ -83,7 +83,7 @@ func (s *SyncService) SyncTrades(ctx context.Context, exchange types.Exchange, s } var tradeKeys = map[types.TradeKey]struct{}{} - var lastTradeID int64 = 0 + var lastTradeID int64 = 1 if len(lastTrades) > 0 { for _, t := range lastTrades { tradeKeys[t.Key()] = struct{}{} @@ -91,14 +91,11 @@ func (s *SyncService) SyncTrades(ctx context.Context, exchange types.Exchange, s lastTrade := lastTrades[len(lastTrades)-1] lastTradeID = lastTrade.ID - - startTime = time.Time(lastTrade.Time) - logrus.Debugf("found last trade, start from lastID = %d since %s", lastTrade.ID, startTime) + logrus.Debugf("found last trade, start from lastID = %d", lastTrade.ID) } b := &batch.ExchangeBatchProcessor{Exchange: exchange} tradeC, errC := b.BatchQueryTrades(ctx, symbol, &types.TradeQueryOptions{ - StartTime: &startTime, LastTradeID: lastTradeID, }) @@ -135,7 +132,7 @@ func (s *SyncService) SyncTrades(ctx context.Context, exchange types.Exchange, s // SyncSessionSymbols syncs the trades from the given exchange session func (s *SyncService) SyncSessionSymbols(ctx context.Context, exchange types.Exchange, startTime time.Time, symbols ...string) error { for _, symbol := range symbols { - if err := s.SyncTrades(ctx, exchange, symbol, startTime); err != nil { + if err := s.SyncTrades(ctx, exchange, symbol); err != nil { return err }