mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
add binance buyer, maker label
This commit is contained in:
parent
ea33db5aa1
commit
9288b6801f
|
@ -251,8 +251,27 @@ func (e *BinanceExchange) QueryTrades(ctx context.Context, symbol string, startT
|
|||
break
|
||||
}
|
||||
|
||||
buyerOrSellerLabel := func(trade *binance.TradeV3) (o string) {
|
||||
if trade.IsBuyer {
|
||||
o = "BUYER"
|
||||
} else {
|
||||
o = "SELLER"
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
makerOrTakerLabel := func(trade *binance.TradeV3) (o string) {
|
||||
if trade.IsMaker {
|
||||
o += "MAKER"
|
||||
} else {
|
||||
o += "TAKER"
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
for _, t := range bnTrades {
|
||||
// skip trade ID that is the same
|
||||
// skip trade ID that is the same. however this should not happen
|
||||
if t.ID == lastTradeID {
|
||||
continue
|
||||
}
|
||||
|
@ -267,7 +286,7 @@ func (e *BinanceExchange) QueryTrades(ctx context.Context, symbol string, startT
|
|||
// trade time
|
||||
tt := time.Unix(0, t.Time*1000000)
|
||||
|
||||
log.Infof("trade: %d %4s Price: % 13s Volume: % 13s %s", t.ID, side, t.Price, t.Quantity, tt)
|
||||
log.Infof("[binance] trade: %d %s % 4s price: % 13s volume: % 11s %6s % 5s %s", t.ID, t.Symbol, side, t.Price, t.Quantity, buyerOrSellerLabel(t), makerOrTakerLabel(t), tt)
|
||||
|
||||
price, err := strconv.ParseFloat(t.Price, 64)
|
||||
if err != nil {
|
||||
|
@ -288,6 +307,7 @@ func (e *BinanceExchange) QueryTrades(ctx context.Context, symbol string, startT
|
|||
ID: t.ID,
|
||||
Price: price,
|
||||
Volume: quantity,
|
||||
Side: side,
|
||||
IsBuyer: t.IsBuyer,
|
||||
IsMaker: t.IsMaker,
|
||||
Fee: fee,
|
||||
|
|
18
bbgo/pnl.go
18
bbgo/pnl.go
|
@ -2,6 +2,7 @@ package bbgo
|
|||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -27,12 +28,22 @@ type ProfitAndLossCalculator struct {
|
|||
StartTime time.Time
|
||||
CurrentPrice float64
|
||||
Trades []Trade
|
||||
|
||||
CurrencyPrice map[string]float64
|
||||
}
|
||||
|
||||
func (c *ProfitAndLossCalculator) AddTrade(trade Trade) {
|
||||
c.Trades = append(c.Trades, trade)
|
||||
}
|
||||
|
||||
func (c *ProfitAndLossCalculator) SetCurrencyPrice(symbol string, price float64) {
|
||||
if c.CurrencyPrice == nil {
|
||||
c.CurrencyPrice = map[string]float64{}
|
||||
}
|
||||
|
||||
c.CurrencyPrice[symbol] = price
|
||||
}
|
||||
|
||||
func (c *ProfitAndLossCalculator) SetCurrentPrice(price float64) {
|
||||
c.CurrentPrice = price
|
||||
}
|
||||
|
@ -61,9 +72,12 @@ func (c *ProfitAndLossCalculator) Calculate() *ProfitAndLossReport {
|
|||
if t.IsBuyer {
|
||||
bidVolume += t.Volume
|
||||
bidAmount += t.Price * t.Volume
|
||||
switch t.FeeCurrency {
|
||||
case "BTC":
|
||||
|
||||
// since we use USDT as the quote currency, we simply check if it matches the currency symbol
|
||||
if strings.HasPrefix(t.Symbol, t.FeeCurrency) {
|
||||
bidFee += t.Price * t.Fee
|
||||
} else if t.FeeCurrency == "USDT" {
|
||||
bidFee += t.Fee
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ type Trade struct {
|
|||
ID int64
|
||||
Price float64
|
||||
Volume float64
|
||||
Side string
|
||||
IsBuyer bool
|
||||
IsMaker bool
|
||||
Time time.Time
|
||||
|
|
Loading…
Reference in New Issue
Block a user