mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix empty start time sync issue
This commit is contained in:
parent
25f01b8837
commit
129f44bbcb
|
@ -304,10 +304,10 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
|
||||||
// However, when you query orders in done status, the start and end time range cannot exceed 7* 24 hours.
|
// However, when you query orders in done status, the start and end time range cannot exceed 7* 24 hours.
|
||||||
// An error will occur if the specified time window exceeds the range.
|
// An error will occur if the specified time window exceeds the range.
|
||||||
// If you specify the end time only, the system will automatically calculate the start time as end time minus 7*24 hours, and vice versa.
|
// If you specify the end time only, the system will automatically calculate the start time as end time minus 7*24 hours, and vice versa.
|
||||||
if until.Sub(since) < 7 * 24 * time.Hour {
|
if until.Sub(since) < 7*24*time.Hour {
|
||||||
req.EndAt(until)
|
req.EndAt(until)
|
||||||
} else {
|
} else {
|
||||||
req.EndAt(since.Add(7 * 24 * time.Hour - time.Minute))
|
req.EndAt(since.Add(7*24*time.Hour - time.Minute))
|
||||||
}
|
}
|
||||||
|
|
||||||
orderList, err := req.Do(ctx)
|
orderList, err := req.Do(ctx)
|
||||||
|
@ -323,11 +323,28 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
|
||||||
return orders, err
|
return orders, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var launchDate = time.Date(2017, 9, 0, 0, 0, 0, 0, nil)
|
||||||
|
|
||||||
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error) {
|
func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) (trades []types.Trade, err error) {
|
||||||
req := e.client.TradeService.NewGetFillsRequest()
|
req := e.client.TradeService.NewGetFillsRequest()
|
||||||
req.Symbol(toLocalSymbol(symbol))
|
req.Symbol(toLocalSymbol(symbol))
|
||||||
|
|
||||||
if options.StartTime != nil {
|
// we always sync trades in the ascending order, and kucoin does not support last trade ID query
|
||||||
|
// hence we need to set the start time here
|
||||||
|
if options.StartTime != nil && options.StartTime.Before(launchDate) {
|
||||||
|
// copy the time data object
|
||||||
|
t := launchDate
|
||||||
|
options.StartTime = &t
|
||||||
|
}
|
||||||
|
|
||||||
|
if options.StartTime != nil && options.EndTime != nil {
|
||||||
|
req.StartAt(*options.StartTime)
|
||||||
|
if options.EndTime.Sub(*options.StartTime) < 7*24*time.Hour {
|
||||||
|
req.EndAt(*options.EndTime)
|
||||||
|
} else {
|
||||||
|
req.StartAt(options.StartTime.Add(7*24*time.Hour - time.Minute))
|
||||||
|
}
|
||||||
|
} else if options.StartTime != nil {
|
||||||
req.StartAt(*options.StartTime)
|
req.StartAt(*options.StartTime)
|
||||||
} else if options.EndTime != nil {
|
} else if options.EndTime != nil {
|
||||||
req.EndAt(*options.EndTime)
|
req.EndAt(*options.EndTime)
|
||||||
|
|
|
@ -73,7 +73,6 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// records descending ordered, buffer 50 trades and use the trades ID to scan if the new trades are duplicated
|
// 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)
|
records, err := s.QueryLast(exchange.Name(), symbol, isMargin, isFutures, isIsolated, 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,7 +81,8 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
|
||||||
|
|
||||||
var tradeKeys = map[types.TradeKey]struct{}{}
|
var tradeKeys = map[types.TradeKey]struct{}{}
|
||||||
var lastTradeID uint64 = 1
|
var lastTradeID uint64 = 1
|
||||||
var startTime time.Time
|
var lastTradeTime time.Time
|
||||||
|
var startTime *time.Time
|
||||||
var now = time.Now()
|
var now = time.Now()
|
||||||
if len(records) > 0 {
|
if len(records) > 0 {
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
|
@ -90,13 +90,14 @@ func (s *TradeService) Sync(ctx context.Context, exchange types.Exchange, symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTradeID = records[0].ID
|
lastTradeID = records[0].ID
|
||||||
startTime = time.Time(records[0].Time)
|
lastTradeTime = time.Time(records[0].Time)
|
||||||
|
startTime = &lastTradeTime
|
||||||
}
|
}
|
||||||
|
|
||||||
b := &batch.TradeBatchQuery{Exchange: exchange}
|
b := &batch.TradeBatchQuery{Exchange: exchange}
|
||||||
tradeC, errC := b.Query(ctx, symbol, &types.TradeQueryOptions{
|
tradeC, errC := b.Query(ctx, symbol, &types.TradeQueryOptions{
|
||||||
LastTradeID: lastTradeID,
|
LastTradeID: lastTradeID,
|
||||||
StartTime: &startTime,
|
StartTime: startTime,
|
||||||
EndTime: &now,
|
EndTime: &now,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user