From 7367ea73b8d3d6ec770e481b150a92788ea398a5 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 26 Aug 2024 18:35:10 +0800 Subject: [PATCH] xmaker: profit object can be nil --- pkg/strategy/xmaker/strategy.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 4449e519c..3c43bec9c 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -929,14 +929,16 @@ func (s *Strategy) CrossRun( }) s.tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) { - if s.CircuitBreaker != nil { - s.CircuitBreaker.RecordProfit(profit.Profit, trade.Time.Time()) + if profit != nil { + if s.CircuitBreaker != nil { + s.CircuitBreaker.RecordProfit(profit.Profit, trade.Time.Time()) + } + + bbgo.Notify(profit) + + s.ProfitStats.AddProfit(*profit) + s.Environment.RecordPosition(s.Position, trade, profit) } - - bbgo.Notify(profit) - - s.ProfitStats.AddProfit(*profit) - s.Environment.RecordPosition(s.Position, trade, profit) }) s.tradeCollector.OnPositionUpdate(func(position *types.Position) {