From 35bb5bda06b6d92e25a7bf32be51fdbf75881c62 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 10 Jun 2020 10:26:14 +0800 Subject: [PATCH] ignore selling trades from the beginning --- bbgo/pnl.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bbgo/pnl.go b/bbgo/pnl.go index 900f72dee..1e040cb7a 100644 --- a/bbgo/pnl.go +++ b/bbgo/pnl.go @@ -23,6 +23,19 @@ func CalculateCostAndProfit(trades []Trade, currentPrice float64) (averageBidPri var bidVolume = 0.0 var bidAmount = 0.0 var bidFee = 0.0 + + // find the first buy trade + var firstBidIndex = -1 + for idx, t := range trades { + if t.IsBuyer { + firstBidIndex = idx + break + } + } + if firstBidIndex > 0 { + trades = trades[firstBidIndex:] + } + for _, t := range trades { if t.IsBuyer { bidVolume += t.Volume