diff --git a/pkg/fixedpoint/count.go b/pkg/fixedpoint/count.go new file mode 100644 index 000000000..84a3d1c8c --- /dev/null +++ b/pkg/fixedpoint/count.go @@ -0,0 +1,13 @@ +package fixedpoint + +type Counter func(a Value) bool + +func Count(values []Value, counter Counter) int { + var c = 0 + for _, value := range values { + if counter(value) { + c++ + } + } + return c +} diff --git a/pkg/types/trade_stats.go b/pkg/types/trade_stats.go index 6e923c85b..7be5d0390 100644 --- a/pkg/types/trade_stats.go +++ b/pkg/types/trade_stats.go @@ -291,6 +291,12 @@ func (s *TradeStats) update() { netProfitsByOrder = append(netProfitsByOrder, sumNetProfit) } + s.NumOfProfitTrade = fixedpoint.Count(profitsByOrder, func(a fixedpoint.Value) bool { + return a.Sign() > 0 + }) + s.NumOfLossTrade = fixedpoint.Count(profitsByOrder, func(a fixedpoint.Value) bool { + return a.Sign() < 0 + }) s.TotalNetProfit = fixedpoint.Reduce(profitsByOrder, fixedpoint.SumReducer) s.GrossProfit = fixedpoint.Reduce(profitsByOrder, grossProfitReducer) s.GrossLoss = fixedpoint.Reduce(profitsByOrder, grossLossReducer)