cmd: skip reports for session has no trade

This commit is contained in:
c9s 2023-11-01 15:22:53 +08:00
parent 3d4a128bab
commit 470eb7dc09
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -528,6 +528,11 @@ var BacktestCmd = &cobra.Command{
for _, session := range environ.Sessions() {
for symbol, trades := range session.Trades {
if len(trades.Trades) == 0 {
log.Warnf("session has no %s trades", symbol)
continue
}
tradeState := sessionTradeStats[session.Name][symbol]
profitFactor := tradeState.ProfitFactor
winningRatio := tradeState.WinningRatio
@ -598,8 +603,11 @@ var BacktestCmd = &cobra.Command{
},
}
func createSymbolReport(userConfig *bbgo.Config, session *bbgo.ExchangeSession, symbol string, trades []types.Trade, intervalProfit *types.IntervalProfitCollector,
profitFactor, winningRatio fixedpoint.Value) (
func createSymbolReport(
userConfig *bbgo.Config, session *bbgo.ExchangeSession, symbol string, trades []types.Trade,
intervalProfit *types.IntervalProfitCollector,
profitFactor, winningRatio fixedpoint.Value,
) (
*backtest.SessionSymbolReport,
error,
) {
@ -669,7 +677,10 @@ func createSymbolReport(userConfig *bbgo.Config, session *bbgo.ExchangeSession,
return &symbolReport, nil
}
func verify(userConfig *bbgo.Config, backtestService *service.BacktestService, sourceExchanges map[types.ExchangeName]types.Exchange, startTime, endTime time.Time) error {
func verify(
userConfig *bbgo.Config, backtestService *service.BacktestService,
sourceExchanges map[types.ExchangeName]types.Exchange, startTime, endTime time.Time,
) error {
for _, sourceExchange := range sourceExchanges {
err := backtestService.Verify(sourceExchange, userConfig.Backtest.Symbols, startTime, endTime)
if err != nil {
@ -709,7 +720,10 @@ func getExchangeIntervals(ex types.Exchange) types.IntervalMap {
return types.SupportedIntervals
}
func sync(ctx context.Context, userConfig *bbgo.Config, backtestService *service.BacktestService, sourceExchanges map[types.ExchangeName]types.Exchange, syncFrom, syncTo time.Time) error {
func sync(
ctx context.Context, userConfig *bbgo.Config, backtestService *service.BacktestService,
sourceExchanges map[types.ExchangeName]types.Exchange, syncFrom, syncTo time.Time,
) error {
for _, symbol := range userConfig.Backtest.Symbols {
for _, sourceExchange := range sourceExchanges {
var supportIntervals = getExchangeIntervals(sourceExchange)