From 916b3b0ecab0f6c97efd00353d917dc3c3d2c3c1 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 24 Oct 2020 16:32:54 +0800 Subject: [PATCH] early return if len of trades == 0 --- pkg/accounting/pnl/avg_cost.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/accounting/pnl/avg_cost.go b/pkg/accounting/pnl/avg_cost.go index bc7c51382..764e9624f 100644 --- a/pkg/accounting/pnl/avg_cost.go +++ b/pkg/accounting/pnl/avg_cost.go @@ -23,6 +23,17 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c var bidFeeUSD = 0.0 var feeRate = 0.0015 + if len(trades) == 0 { + return &AverageCostPnlReport{ + Symbol: symbol, + CurrentPrice: currentPrice, + NumTrades: 0, + BidVolume: bidVolume, + AskVolume: askVolume, + FeeUSD: feeUSD, + } + } + var currencyFees = map[string]float64{} for _, trade := range trades {