From 3aebb5809141838dd78da4a5f50eba4e06c1a3c7 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 8 Sep 2022 16:37:47 +0800 Subject: [PATCH] types/tradeStats: use tester --- pkg/types/trade_stats.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/types/trade_stats.go b/pkg/types/trade_stats.go index a33565d44..4bbb688fa 100644 --- a/pkg/types/trade_stats.go +++ b/pkg/types/trade_stats.go @@ -297,12 +297,8 @@ func (s *TradeStats) Recalculate() { 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.NumOfProfitTrade = fixedpoint.Count(profitsByOrder, fixedpoint.PositiveTester) + s.NumOfLossTrade = fixedpoint.Count(profitsByOrder, fixedpoint.NegativeTester) s.TotalNetProfit = fixedpoint.Reduce(profitsByOrder, fixedpoint.SumReducer) s.GrossProfit = fixedpoint.Reduce(profitsByOrder, grossProfitReducer) s.GrossLoss = fixedpoint.Reduce(profitsByOrder, grossLossReducer) @@ -310,8 +306,8 @@ func (s *TradeStats) Recalculate() { sort.Sort(fixedpoint.Descending(profitsByOrder)) sort.Sort(fixedpoint.Descending(netProfitsByOrder)) - s.Losses = fixedpoint.Filter(profitsByOrder, fixedpoint.NegativeTester) s.Profits = fixedpoint.Filter(profitsByOrder, fixedpoint.PositiveTester) + s.Losses = fixedpoint.Filter(profitsByOrder, fixedpoint.NegativeTester) s.LargestProfitTrade = profitsByOrder[0] s.LargestLossTrade = profitsByOrder[len(profitsByOrder)-1] if s.LargestLossTrade.Sign() > 0 {