diff --git a/pkg/bbgo/profitstats.go b/pkg/bbgo/profitstats.go index 6fa125b0a..be0eab6c4 100644 --- a/pkg/bbgo/profitstats.go +++ b/pkg/bbgo/profitstats.go @@ -38,19 +38,19 @@ type ProfitStats struct { TodaySince int64 `json:"todaySince,omitempty"` } -func (s *ProfitStats) AddProfit(profit, netProfit fixedpoint.Value) { - s.AccumulatedPnL += profit - s.AccumulatedNetProfit += netProfit +func (s *ProfitStats) AddProfit(profit Profit) { + s.AccumulatedPnL += profit.Profit + s.AccumulatedNetProfit += profit.NetProfit - s.TodayPnL += profit - s.TodayNetProfit += netProfit + s.TodayPnL += profit.Profit + s.TodayNetProfit += profit.NetProfit - if profit < 0 { - s.AccumulatedLoss += profit - s.TodayLoss += profit - } else if profit > 0 { - s.AccumulatedProfit += profit - s.TodayProfit += profit + if profit.Profit < 0 { + s.AccumulatedLoss += profit.Profit + s.TodayLoss += profit.Profit + } else if profit.Profit > 0 { + s.AccumulatedProfit += profit.Profit + s.TodayProfit += profit.Profit } } diff --git a/pkg/strategy/xmaker/strategy.go b/pkg/strategy/xmaker/strategy.go index 0f740ad75..2c241bd0e 100644 --- a/pkg/strategy/xmaker/strategy.go +++ b/pkg/strategy/xmaker/strategy.go @@ -41,8 +41,8 @@ func init() { type State struct { HedgePosition fixedpoint.Value `json:"hedgePosition"` CoveredPosition fixedpoint.Value `json:"coveredPosition,omitempty"` - Position *bbgo.Position `json:"position,omitempty"` - ProfitStats bbgo.ProfitStats `json:"profitStats,omitempty"` + Position *bbgo.Position `json:"position,omitempty"` + ProfitStats ProfitStats `json:"profitStats,omitempty"` } type ProfitStats struct { @@ -623,7 +623,10 @@ func (s *Strategy) processTrade(trade types.Trade) { s.state.ProfitStats.AddTrade(trade) if profit, netProfit, madeProfit := s.state.Position.AddTrade(trade); madeProfit { - s.state.ProfitStats.AddProfit(profit, netProfit) + s.state.ProfitStats.AddProfit(bbgo.Profit{ + Profit: profit, + NetProfit: netProfit, + }) profitMargin := profit.DivFloat64(trade.QuoteQuantity) netProfitMargin := netProfit.DivFloat64(trade.QuoteQuantity)