Skip to content

Commit

Permalink
xmaker: simplify notify checking condition
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 27, 2024
1 parent fc515ec commit 2395163
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/strategy/xmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,18 +2135,24 @@ func (s *Strategy) CrossRun(
}
})

// TODO: remove this nil value behavior, check all OnProfit usage and remove the EmitProfit call with nil profit
shouldNotifyProfit := func(trade types.Trade, profit *types.Profit) bool {
amountThreshold := s.NotifyIgnoreSmallAmountProfitTrade
if amountThreshold.IsZero() {
return true
} else if trade.QuoteQuantity.Compare(amountThreshold) >= 0 {
return true
}

return false
}

s.tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) {
if profit != nil {
if s.CircuitBreaker != nil {
s.CircuitBreaker.RecordProfit(profit.Profit, trade.Time.Time())
}

if amount := s.NotifyIgnoreSmallAmountProfitTrade; amount.Sign() > 0 {
if profit.QuoteQuantity.Compare(amount) > 0 {
bbgo.Notify(profit)
}
} else {
if shouldNotifyProfit(trade, profit) {
bbgo.Notify(profit)
}

Expand Down

0 comments on commit 2395163

Please sign in to comment.