From b38b65ce83f8c7e1a9f717fa6d120d510f6b8f53 Mon Sep 17 00:00:00 2001 From: Jui-Nan Lin Date: Sat, 6 Feb 2021 17:34:13 +0800 Subject: [PATCH] fix(pnl): do not calculate the "self" trade --- pkg/accounting/pnl/avg_cost.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/accounting/pnl/avg_cost.go b/pkg/accounting/pnl/avg_cost.go index 2ae0accc3..7b1290424 100644 --- a/pkg/accounting/pnl/avg_cost.go +++ b/pkg/accounting/pnl/avg_cost.go @@ -37,7 +37,7 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c for _, trade := range trades { if trade.Symbol == symbol { - if trade.Side == types.SideTypeBuy { + if trade.IsBuyer && trade.Side != types.SideTypeSelf { bidVolume += trade.Quantity bidAmount += trade.Price * trade.Quantity } @@ -76,7 +76,7 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c continue } - if t.Side == types.SideTypeBuy { + if t.IsBuyer || t.Side == types.SideTypeSelf { continue }