mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #934 from c9s/fix/pnl-position
pnl: fix nil position point issue
This commit is contained in:
commit
5db41f4be2
|
@ -12,6 +12,7 @@ import (
|
|||
type AverageCostCalculator struct {
|
||||
TradingFeeCurrency string
|
||||
Market types.Market
|
||||
ExchangeFee *types.ExchangeFee
|
||||
}
|
||||
|
||||
func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, currentPrice fixedpoint.Value) *AverageCostPnLReport {
|
||||
|
@ -22,12 +23,31 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
|
|||
var grossProfit = fixedpoint.Zero
|
||||
var grossLoss = fixedpoint.Zero
|
||||
|
||||
var position = types.NewPositionFromMarket(c.Market)
|
||||
|
||||
if c.ExchangeFee != nil {
|
||||
position.SetFeeRate(*c.ExchangeFee)
|
||||
} else {
|
||||
makerFeeRate := 0.075 * 0.01
|
||||
|
||||
if c.Market.QuoteCurrency == "BUSD" {
|
||||
makerFeeRate = 0
|
||||
}
|
||||
|
||||
position.SetFeeRate(types.ExchangeFee{
|
||||
// binance vip 0 uses 0.075%
|
||||
MakerFeeRate: fixedpoint.NewFromFloat(makerFeeRate),
|
||||
TakerFeeRate: fixedpoint.NewFromFloat(0.075 * 0.01),
|
||||
})
|
||||
}
|
||||
|
||||
if len(trades) == 0 {
|
||||
return &AverageCostPnLReport{
|
||||
Symbol: symbol,
|
||||
Market: c.Market,
|
||||
LastPrice: currentPrice,
|
||||
NumTrades: 0,
|
||||
Position: position,
|
||||
BuyVolume: bidVolume,
|
||||
SellVolume: askVolume,
|
||||
FeeInUSD: feeUSD,
|
||||
|
@ -36,13 +56,6 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
|
|||
|
||||
var currencyFees = map[string]fixedpoint.Value{}
|
||||
|
||||
var position = types.NewPositionFromMarket(c.Market)
|
||||
position.SetFeeRate(types.ExchangeFee{
|
||||
// binance vip 0 uses 0.075%
|
||||
MakerFeeRate: fixedpoint.NewFromFloat(0.075 * 0.01),
|
||||
TakerFeeRate: fixedpoint.NewFromFloat(0.075 * 0.01),
|
||||
})
|
||||
|
||||
// TODO: configure the exchange fee rate here later
|
||||
// position.SetExchangeFeeRate()
|
||||
var totalProfit fixedpoint.Value
|
||||
|
|
Loading…
Reference in New Issue
Block a user