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 {
|
type AverageCostCalculator struct {
|
||||||
TradingFeeCurrency string
|
TradingFeeCurrency string
|
||||||
Market types.Market
|
Market types.Market
|
||||||
|
ExchangeFee *types.ExchangeFee
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, currentPrice fixedpoint.Value) *AverageCostPnLReport {
|
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 grossProfit = fixedpoint.Zero
|
||||||
var grossLoss = 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 {
|
if len(trades) == 0 {
|
||||||
return &AverageCostPnLReport{
|
return &AverageCostPnLReport{
|
||||||
Symbol: symbol,
|
Symbol: symbol,
|
||||||
Market: c.Market,
|
Market: c.Market,
|
||||||
LastPrice: currentPrice,
|
LastPrice: currentPrice,
|
||||||
NumTrades: 0,
|
NumTrades: 0,
|
||||||
|
Position: position,
|
||||||
BuyVolume: bidVolume,
|
BuyVolume: bidVolume,
|
||||||
SellVolume: askVolume,
|
SellVolume: askVolume,
|
||||||
FeeInUSD: feeUSD,
|
FeeInUSD: feeUSD,
|
||||||
|
@ -36,13 +56,6 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
|
||||||
|
|
||||||
var currencyFees = map[string]fixedpoint.Value{}
|
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
|
// TODO: configure the exchange fee rate here later
|
||||||
// position.SetExchangeFeeRate()
|
// position.SetExchangeFeeRate()
|
||||||
var totalProfit fixedpoint.Value
|
var totalProfit fixedpoint.Value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user