From 770efeed4f378f3df98cc15c9d27ecc84d3a48df Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 10 Nov 2020 14:18:27 +0800 Subject: [PATCH] pnl format improve --- pkg/accounting/pnl/avg_cost.go | 15 ++++++--------- pkg/accounting/pnl/report.go | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/pkg/accounting/pnl/avg_cost.go b/pkg/accounting/pnl/avg_cost.go index 764e9624f..f05f49533 100644 --- a/pkg/accounting/pnl/avg_cost.go +++ b/pkg/accounting/pnl/avg_cost.go @@ -3,8 +3,6 @@ package pnl import ( "strings" - "github.com/sirupsen/logrus" - "github.com/c9s/bbgo/pkg/types" ) @@ -28,9 +26,9 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c Symbol: symbol, CurrentPrice: currentPrice, NumTrades: 0, - BidVolume: bidVolume, - AskVolume: askVolume, - FeeUSD: feeUSD, + BuyVolume: bidVolume, + SellVolume: askVolume, + FeeInUSD: feeUSD, } } @@ -69,7 +67,6 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c currencyFees[trade.FeeCurrency] += trade.Fee } - logrus.Infof("average bid price = (total amount %f + total feeUSD %f) / volume %f", bidAmount, bidFeeUSD, bidVolume) profit := 0.0 averageCost := (bidAmount + bidFeeUSD) / bidVolume @@ -101,14 +98,14 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c NumTrades: len(trades), StartTime: trades[0].Time, - BidVolume: bidVolume, - AskVolume: askVolume, + BuyVolume: bidVolume, + SellVolume: askVolume, Stock: stock, Profit: profit, UnrealizedProfit: unrealizedProfit, AverageBidCost: averageCost, - FeeUSD: feeUSD, + FeeInUSD: feeUSD, CurrencyFees: currencyFees, } } diff --git a/pkg/accounting/pnl/report.go b/pkg/accounting/pnl/report.go index 06efe0f56..cc3bcfd3d 100644 --- a/pkg/accounting/pnl/report.go +++ b/pkg/accounting/pnl/report.go @@ -20,27 +20,28 @@ type AverageCostPnlReport struct { Profit float64 UnrealizedProfit float64 AverageBidCost float64 - BidVolume float64 - AskVolume float64 - FeeUSD float64 + BuyVolume float64 + SellVolume float64 + FeeInUSD float64 Stock float64 CurrencyFees map[string]float64 } func (report AverageCostPnlReport) Print() { - log.Infof("trades since: %v", report.StartTime) - log.Infof("average bid cost: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost)) - log.Infof("total bid volume: %f", report.BidVolume) - log.Infof("total ask volume: %f", report.AskVolume) - log.Infof("stock: %f", report.Stock) - log.Infof("fee (USD): %f", report.FeeUSD) - log.Infof("current price: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice)) - log.Infof("profit: %s", types.USD.FormatMoneyFloat64(report.Profit)) - log.Infof("unrealized profit: %s", types.USD.FormatMoneyFloat64(report.UnrealizedProfit)) - log.Infof("currency fees:") + log.Infof("TRADES SINCE: %v", report.StartTime) + log.Infof("NUMBER OF TRADES: %d", report.NumTrades) + log.Infof("AVERAGE COST: %s", types.USD.FormatMoneyFloat64(report.AverageBidCost)) + log.Infof("TOTAL BUY VOLUME: %f", report.BuyVolume) + log.Infof("TOTAL SELL VOLUME: %f", report.SellVolume) + log.Infof("STOCK: %f", report.Stock) + log.Infof("FEE (USD): %f", report.FeeInUSD) + log.Infof("CURRENT PRICE: %s", types.USD.FormatMoneyFloat64(report.CurrentPrice)) + log.Infof("CURRENCY FEES:") for currency, fee := range report.CurrencyFees { 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 { @@ -66,7 +67,7 @@ func (report AverageCostPnlReport) SlackAttachment() slack.Attachment { {Title: "Unrealized Profit", Value: types.USD.FormatMoney(report.UnrealizedProfit)}, {Title: "Current Price", Value: market.FormatPrice(report.CurrentPrice), 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: "Number of Trades", Value: strconv.Itoa(report.NumTrades), Short: true}, },