mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
fix pnl calculation
This commit is contained in:
parent
2e13b67968
commit
d79e4f544d
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user