ignore selling trades from the beginning

This commit is contained in:
c9s 2020-06-10 10:26:14 +08:00
parent 062fe55b43
commit 35bb5bda06

View File

@ -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