diff --git a/pkg/bbgo/order_executor_general.go b/pkg/bbgo/order_executor_general.go index b3d3bdf13..6c95b6495 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -203,9 +203,10 @@ func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders .. orderCreateCallback := func(createdOrder types.Order) { e.orderStore.Add(createdOrder) e.activeMakerOrders.Add(createdOrder) - e.tradeCollector.Process() } + defer e.tradeCollector.Process() + if e.maxRetries == 0 { createdOrders, _, err := BatchPlaceOrder(ctx, e.session.Exchange, orderCreateCallback, formattedOrders...) return createdOrders, err diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 0b9961ec6..6a361a9d5 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -385,9 +385,11 @@ func (session *ExchangeSession) initSymbol(ctx context.Context, environ *Environ session.Trades[symbol] = &types.TradeSlice{Trades: trades} session.UserDataStream.OnTradeUpdate(func(trade types.Trade) { - if trade.Symbol == symbol { - session.Trades[symbol].Append(trade) + if trade.Symbol != symbol { + return } + + session.Trades[symbol].Append(trade) }) position := &types.Position{ diff --git a/pkg/cmd/backtest.go b/pkg/cmd/backtest.go index 025bec020..6dbfb8d1e 100644 --- a/pkg/cmd/backtest.go +++ b/pkg/cmd/backtest.go @@ -529,7 +529,8 @@ var BacktestCmd = &cobra.Command{ profitFactor := tradeState.ProfitFactor winningRatio := tradeState.WinningRatio intervalProfits := tradeState.IntervalProfits[types.Interval1d] - symbolReport, err := createSymbolReport(userConfig, session, symbol, trades.Trades, intervalProfits, profitFactor, winningRatio) + + symbolReport, err := createSymbolReport(userConfig, session, symbol, trades.Copy(), intervalProfits, profitFactor, winningRatio) if err != nil { return err } diff --git a/pkg/core/tradecollector.go b/pkg/core/tradecollector.go index 29eb60f4c..4bf1ddaa6 100644 --- a/pkg/core/tradecollector.go +++ b/pkg/core/tradecollector.go @@ -117,6 +117,7 @@ func (c *TradeCollector) setDone(key types.TradeKey) { // if we have the order in the order store, then the trade will be considered for the position. // profit will also be calculated. func (c *TradeCollector) Process() bool { + logrus.Debugf("TradeCollector.Process()") positionChanged := false c.tradeStore.Filter(func(trade types.Trade) bool {