improve/db: query futures kilne if session 'futures' is true when sync

This commit is contained in:
Andy Cheng 2023-12-21 15:47:24 +08:00
parent d5cbcc3fb2
commit 5b0b5428fb
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -25,13 +25,26 @@ type BacktestService struct {
func (s *BacktestService) SyncKLineByInterval(ctx context.Context, exchange types.Exchange, symbol string, interval types.Interval, startTime, endTime time.Time) error {
log.Infof("synchronizing %s klines with interval %s: %s <=> %s", exchange.Name(), interval, startTime, endTime)
// TODO: use isFutures here
_, _, isIsolated, isolatedSymbol := exchange2.GetSessionAttributes(exchange)
_, isFutures, isIsolated, isolatedSymbol := exchange2.GetSessionAttributes(exchange)
// override symbol if isolatedSymbol is not empty
if isIsolated && len(isolatedSymbol) > 0 {
symbol = isolatedSymbol
}
if isFutures {
futuresExchange, ok := exchange.(types.FuturesExchange)
if !ok {
return fmt.Errorf("exchange %s does not support futures", exchange.Name())
}
if isIsolated {
futuresExchange.UseIsolatedFutures(symbol)
} else {
futuresExchange.UseFutures()
}
}
if s.DB.DriverName() == "sqlite3" {
_, _ = s.DB.Exec("PRAGMA journal_mode = WAL")
_, _ = s.DB.Exec("PRAGMA synchronous = NORMAL")