mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
always sort orders and trades in the batch query
This commit is contained in:
parent
2a8caa3780
commit
eba33329d1
|
@ -2,6 +2,7 @@ package batch
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -69,6 +70,11 @@ func (e ClosedOrderBatchQuery) Query(ctx context.Context, symbol string, startTi
|
|||
}
|
||||
}
|
||||
|
||||
// sort orders by time in ascending order
|
||||
sort.Slice(orders, func(i, j int) bool {
|
||||
return orders[i].CreationTime.Before(time.Time(orders[j].CreationTime))
|
||||
})
|
||||
|
||||
for _, o := range orders {
|
||||
if _, ok := orderIDs[o.OrderID]; ok {
|
||||
continue
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"errors"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
|
@ -22,27 +24,32 @@ type SyncService struct {
|
|||
// 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 {
|
||||
log.Infof("syncing %s %s trades...", exchange.Name(), symbol)
|
||||
if err := s.TradeService.Sync(ctx, exchange, symbol); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("syncing %s %s orders...", exchange.Name(), symbol)
|
||||
if err := s.OrderService.Sync(ctx, exchange, symbol, startTime); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("syncing %s deposit records...", exchange.Name())
|
||||
if err := s.DepositService.Sync(ctx, exchange); err != nil {
|
||||
if err != ErrNotImplemented {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("syncing %s withdraw records...", exchange.Name())
|
||||
if err := s.WithdrawService.Sync(ctx, exchange); err != nil {
|
||||
if err != ErrNotImplemented {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("syncing %s reward records...", exchange.Name())
|
||||
if err := s.RewardService.Sync(ctx, exchange); err != nil {
|
||||
if err != ErrExchangeRewardServiceNotImplemented {
|
||||
return err
|
||||
|
|
|
@ -74,7 +74,7 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
|
|||
}
|
||||
|
||||
|
||||
// records descending ordered
|
||||
// records descending ordered, buffer 50 trades and use the trades ID to scan if the new trades are duplicated
|
||||
records, err := s.QueryLast(exchange.Name(), symbol, isMargin, isFutures, isIsolated, 50)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue
Block a user