Merge pull request #1716 from c9s/c9s/xmaker/stb-improvements

FIX: [xmaker] profit object can be nil
This commit is contained in:
c9s 2024-08-26 18:39:29 +08:00 committed by GitHub
commit ea93bf959a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -928,15 +928,18 @@ func (s *Strategy) CrossRun(
} }
}) })
// TODO: remove this nil value behavior, check all OnProfit usage and remove the EmitProfit call with nil profit
s.tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) { s.tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) {
if s.CircuitBreaker != nil { if profit != nil {
s.CircuitBreaker.RecordProfit(profit.Profit, trade.Time.Time()) 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) { s.tradeCollector.OnPositionUpdate(func(position *types.Position) {