mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix: pull out time.now variable
This commit is contained in:
parent
32095e2741
commit
a7bd9239f2
|
@ -662,6 +662,7 @@ func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service
|
|||
supportIntervals = types.SupportedIntervals
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for interval := range supportIntervals {
|
||||
// if err := s.SyncKLineByInterval(ctx, exchange, symbol, interval, startTime, endTime); err != nil {
|
||||
// return err
|
||||
|
@ -674,11 +675,13 @@ func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service
|
|||
// if we don't have klines before the start time endpoint, the back-test will fail.
|
||||
// because the last price will be missing.
|
||||
if firstKLine != nil {
|
||||
if err := backtestService.SyncExist(ctx, sourceExchange, symbol, syncFromTime, time.Now(), interval); err != nil {
|
||||
log.Debugf("found existing kline data using partial sync...")
|
||||
if err := backtestService.SyncExist(ctx, sourceExchange, symbol, syncFromTime, now, interval); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := backtestService.Sync(ctx, sourceExchange, symbol, syncFromTime, time.Now(), interval); err != nil {
|
||||
log.Debugf("starting a fresh kline data sync...")
|
||||
if err := backtestService.Sync(ctx, sourceExchange, symbol, syncFromTime, now, interval); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,25 +289,14 @@ func (s *BacktestService) scanRows(rows *sqlx.Rows) (klines []types.KLine, err e
|
|||
}
|
||||
|
||||
func (s *BacktestService) _targetKlineTable(exchangeName types.ExchangeName) string {
|
||||
switch exchangeName {
|
||||
case types.ExchangeBinance:
|
||||
return "binance_klines"
|
||||
case types.ExchangeFTX:
|
||||
return "ftx_klines"
|
||||
case types.ExchangeMax:
|
||||
return "max_klines"
|
||||
case types.ExchangeOKEx:
|
||||
return "okex_klines"
|
||||
case types.ExchangeKucoin:
|
||||
return "kucoin_klines"
|
||||
default:
|
||||
return "klines"
|
||||
}
|
||||
return strings.ToLower(exchangeName.String()) + "_klines"
|
||||
}
|
||||
|
||||
var errExchangeFieldIsUnset = errors.New("kline.Exchange field should not be empty")
|
||||
|
||||
func (s *BacktestService) Insert(kline types.KLine) error {
|
||||
if len(kline.Exchange) == 0 {
|
||||
return errors.New("kline.Exchange field should not be empty")
|
||||
return errExchangeFieldIsUnset
|
||||
}
|
||||
|
||||
tableName := s._targetKlineTable(kline.Exchange)
|
||||
|
|
|
@ -19,12 +19,16 @@ type SyncTask struct {
|
|||
Type interface{}
|
||||
|
||||
// ID is a function that returns the unique identity of the object
|
||||
// This function will be used for detecting duplicated objects.
|
||||
ID func(obj interface{}) string
|
||||
|
||||
// Time is a function that returns the time of the object
|
||||
// This function will be used for sorting records
|
||||
Time func(obj interface{}) time.Time
|
||||
|
||||
// Select is the select query builder for querying db records
|
||||
// Select is the select query builder for querying existing db records
|
||||
// The built SQL will be used for querying existing db records.
|
||||
// And then the ID function will be used for filtering duplicated object.
|
||||
Select squirrel.SelectBuilder
|
||||
|
||||
// OnLoad is an optional field, which is called when the records are loaded from the database
|
||||
|
@ -79,7 +83,8 @@ func (sel SyncTask) execute(ctx context.Context, db *sqlx.DB, startTime time.Tim
|
|||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
logrus.Warnf("context is cancelled, stop syncing")
|
||||
return ctx.Err()
|
||||
|
||||
case err := <-errC:
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue
Block a user