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)
}
// TODO: load these from config file
trader.ReportPnL(notifier).
AverageCostBySymbols("BTCUSDT", "BNBUSDT").
Of("binance").When("@daily", "@hourly")
trader.ReportPnL(notifier).
AverageCostBySymbols("MAXUSDT").
Of("max").When("@daily", "@hourly")
for _, report := range userConfig.PnLReporters {
if len(report.AverageCostBySymbols) > 0 {
trader.ReportPnL(notifier).
AverageCostBySymbols(report.AverageCostBySymbols...).
Of(report.Of...).
When(report.When...)
} else {
return errors.Errorf("unsupported PnL reporter: %+v", report)
}
}
err = trader.Run(ctx)
if err != nil {

View File

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

View File

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