improve/backtest: backtest with futures klines

This commit is contained in:
Andy Cheng 2023-12-22 11:55:11 +08:00
parent 66718e0d37
commit 0ac720c4cb
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28
2 changed files with 10 additions and 2 deletions

View File

@ -30,6 +30,7 @@ package backtest
import ( import (
"context" "context"
"fmt" "fmt"
exchange2 "github.com/c9s/bbgo/pkg/exchange"
"strconv" "strconv"
"sync" "sync"
"time" "time"
@ -381,7 +382,13 @@ func (e *Exchange) SubscribeMarketData(
intervals = append(intervals, interval) intervals = append(intervals, interval)
} }
log.Infof("querying klines from database with exchange: %v symbols: %v and intervals: %v for back-testing", e.Name(), symbols, intervals) _, isFutures, _, _ := exchange2.GetSessionAttributes(e.publicExchange)
if isFutures {
log.Infof("querying futures klines from database with exchange: %v symbols: %v and intervals: %v for back-testing", e.Name(), symbols, intervals)
} else {
log.Infof("querying klines from database with exchange: %v symbols: %v and intervals: %v for back-testing", e.Name(), symbols, intervals)
}
if len(symbols) == 0 { if len(symbols) == 0 {
log.Warnf("empty symbols, will not query kline data from the database") log.Warnf("empty symbols, will not query kline data from the database")
@ -390,7 +397,7 @@ func (e *Exchange) SubscribeMarketData(
return c, nil return c, nil
} }
klineC, errC := e.srv.QueryKLinesCh(startTime, endTime, e, symbols, intervals) klineC, errC := e.srv.QueryKLinesCh(startTime, endTime, e.publicExchange, symbols, intervals)
go func() { go func() {
if err := <-errC; err != nil { if err := <-errC; err != nil {
log.WithError(err).Error("backtest data feed error") log.WithError(err).Error("backtest data feed error")

View File

@ -279,6 +279,7 @@ var BacktestCmd = &cobra.Command{
exchangeFromConfig := userConfig.Sessions[name.String()] exchangeFromConfig := userConfig.Sessions[name.String()]
if exchangeFromConfig != nil { if exchangeFromConfig != nil {
session.UseHeikinAshi = exchangeFromConfig.UseHeikinAshi session.UseHeikinAshi = exchangeFromConfig.UseHeikinAshi
session.Futures = exchangeFromConfig.Futures
} }
} }