use the time of the first trade as the report start time

This commit is contained in:
c9s 2020-10-23 14:09:05 +08:00
parent c9f5d51556
commit 6e033461bb
3 changed files with 13 additions and 14 deletions

View File

@ -82,14 +82,16 @@ var runCmd = &cobra.Command{
trader.AttachCrossExchangeStrategy(strategy) trader.AttachCrossExchangeStrategy(strategy)
} }
// TODO: load these from config file for _, report := range userConfig.PnLReporters {
trader.ReportPnL(notifier). if len(report.AverageCostBySymbols) > 0 {
AverageCostBySymbols("BTCUSDT", "BNBUSDT"). trader.ReportPnL(notifier).
Of("binance").When("@daily", "@hourly") AverageCostBySymbols(report.AverageCostBySymbols...).
Of(report.Of...).
trader.ReportPnL(notifier). When(report.When...)
AverageCostBySymbols("MAXUSDT"). } else {
Of("max").When("@daily", "@hourly") return errors.Errorf("unsupported PnL reporter: %+v", report)
}
}
err = trader.Run(ctx) err = trader.Run(ctx)
if err != nil { if err != nil {

View File

@ -35,5 +35,5 @@ exchangeStrategies:
buyandhold: buyandhold:
symbol: "BTCUSDT" symbol: "BTCUSDT"
interval: "1m" interval: "1m"
baseQuantity: 0.1 baseQuantity: 0.01
minDropPercentage: -0.05 minDropPercentage: -0.02

View File

@ -2,7 +2,6 @@ package pnl
import ( import (
"strings" "strings"
"time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -10,8 +9,6 @@ import (
) )
type AverageCostCalculator struct { type AverageCostCalculator struct {
Symbol string
StartTime time.Time
TradingFeeCurrency string TradingFeeCurrency string
} }
@ -89,9 +86,9 @@ func (c *AverageCostCalculator) Calculate(symbol string, trades []types.Trade, c
return &AverageCostPnlReport{ return &AverageCostPnlReport{
Symbol: symbol, Symbol: symbol,
StartTime: c.StartTime,
CurrentPrice: currentPrice, CurrentPrice: currentPrice,
NumTrades: len(trades), NumTrades: len(trades),
StartTime: trades[0].Time,
BidVolume: bidVolume, BidVolume: bidVolume,
AskVolume: askVolume, AskVolume: askVolume,