pnl format improve

This commit is contained in:
c9s 2020-11-10 14:18:27 +08:00
parent 69a33b6400
commit 770efeed4f
2 changed files with 21 additions and 23 deletions

View File

@ -3,8 +3,6 @@ package pnl
import ( import (
"strings" "strings"
"github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
@ -28,9 +26,9 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
Symbol: symbol, Symbol: symbol,
CurrentPrice: currentPrice, CurrentPrice: currentPrice,
NumTrades: 0, NumTrades: 0,
BidVolume: bidVolume, BuyVolume: bidVolume,
AskVolume: askVolume, SellVolume: askVolume,
FeeUSD: feeUSD, FeeInUSD: feeUSD,
} }
} }
@ -69,7 +67,6 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
currencyFees[trade.FeeCurrency] += trade.Fee currencyFees[trade.FeeCurrency] += trade.Fee
} }
logrus.Infof("average bid price = (total amount %f + total feeUSD %f) / volume %f", bidAmount, bidFeeUSD, bidVolume)
profit := 0.0 profit := 0.0
averageCost := (bidAmount + bidFeeUSD) / bidVolume averageCost := (bidAmount + bidFeeUSD) / bidVolume
@ -101,14 +98,14 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
NumTrades: len(trades), NumTrades: len(trades),
StartTime: trades[0].Time, StartTime: trades[0].Time,
BidVolume: bidVolume, BuyVolume: bidVolume,
AskVolume: askVolume, SellVolume: askVolume,
Stock: stock, Stock: stock,
Profit: profit, Profit: profit,
UnrealizedProfit: unrealizedProfit, UnrealizedProfit: unrealizedProfit,
AverageBidCost: averageCost, AverageBidCost: averageCost,
FeeUSD: feeUSD, FeeInUSD: feeUSD,
CurrencyFees: currencyFees, CurrencyFees: currencyFees,
} }
} }

View File

@ -20,27 +20,28 @@ type AverageCostPnlReport struct {
Profit float64 Profit float64
UnrealizedProfit float64 UnrealizedProfit float64
AverageBidCost float64 AverageBidCost float64
BidVolume float64 BuyVolume float64
AskVolume float64 SellVolume float64
FeeUSD float64 FeeInUSD float64
Stock float64 Stock float64
CurrencyFees map[string]float64 CurrencyFees map[string]float64
} }
func (report AverageCostPnlReport) Print() { func (report AverageCostPnlReport) Print() {
log.Infof("trades since: %v", report.StartTime) log.Infof("TRADES SINCE: %v", report.StartTime)
log.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost)) log.Infof("NUMBER OF TRADES: %d", report.NumTrades)
log.Infof("total bid volume: %f", report.BidVolume) log.Infof("AVERAGE COST: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost))
log.Infof("total ask volume: %f", report.AskVolume) log.Infof("TOTAL BUY VOLUME: %f", report.BuyVolume)
log.Infof("stock: %f", report.Stock) log.Infof("TOTAL SELL VOLUME: %f", report.SellVolume)
log.Infof("fee (USD): %f", report.FeeUSD) log.Infof("STOCK: %f", report.Stock)
log.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice)) log.Infof("FEE (USD): %f", report.FeeInUSD)
log.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit)) log.Infof("CURRENT PRICE: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice))
log.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit)) log.Infof("CURRENCY FEES:")
log.Infof("currency fees:")
for currency, fee := range report.CurrencyFees { for currency, fee := range report.CurrencyFees {
log.Infof(" - %s: %f", currency, fee) log.Infof(" - %s: %f", currency, fee)
} }
log.Infof("PROFIT: %s", types.USD.FormatMoneyFloat64(report.Profit))
log.Infof("UNREALIZED PROFIT: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit))
} }
func (report AverageCostPnlReport) SlackAttachment() slack.Attachment { func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
@ -66,7 +67,7 @@ func (report AverageCostPnlReport) SlackAttachment() slack.Attachment {
{Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)}, {Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)},
{Title: "Current Price", Value: market.FormatPrice(report.CurrentPrice), Short: true}, {Title: "Current Price", Value: market.FormatPrice(report.CurrentPrice), Short: true},
{Title: "Average Cost", Value: market.FormatPrice(report.AverageBidCost), Short: true}, {Title: "Average Cost", Value: market.FormatPrice(report.AverageBidCost), Short: true},
{Title: "Fee (USD)", Value: types.USD.FormatMoney(report.FeeUSD), Short: true}, {Title: "Fee (USD)", Value: types.USD.FormatMoney(report.FeeInUSD), Short: true},
{Title: "Stock", Value: strconv.FormatFloat(report.Stock, 'f', 8, 64), Short: true}, {Title: "Stock", Value: strconv.FormatFloat(report.Stock, 'f', 8, 64), Short: true},
{Title: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true}, {Title: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true},
}, },