fix pnl calculation

This commit is contained in:
c9s 2020-08-03 16:42:33 +08:00
parent 2e13b67968
commit d79e4f544d
2 changed files with 4 additions and 4 deletions

View File

@ -3,7 +3,6 @@ package binance
import (
"context"
"fmt"
"github.com/prometheus/common/log"
"strconv"
"time"
@ -218,7 +217,7 @@ func (e *Exchange) BatchQueryTrades(ctx context.Context, symbol string, options
logrus.Infof("[binance] querying %s trades from %s", symbol, startTime)
var lastTradeID int64 = 0
var lastTradeID = options.LastTradeID
for {
trades, err := e.QueryTrades(ctx, symbol, &TradeQueryOptions{
StartTime: &startTime,
@ -229,13 +228,13 @@ func (e *Exchange) BatchQueryTrades(ctx context.Context, symbol string, options
return allTrades, err
}
if len(trades) <= 1 {
if len(trades) == 1 && trades[0].ID == lastTradeID {
break
}
for _, t := range trades {
// ignore the first trade if last TradeID is given
if t.ID == lastTradeID {
log.Warn("duplicated trade ID")
continue
}

View File

@ -53,6 +53,7 @@ func (c *ProfitAndLossCalculator) Calculate() *ProfitAndLossReport {
// since we use USDT as the quote currency, we simply check if it matches the currency symbol
if strings.HasPrefix(t.Symbol, t.FeeCurrency) {
bidVolume -= t.Fee
bidFee += t.Price * t.Fee
} else if t.FeeCurrency == "USDT" {
bidFee += t.Fee