improve/profitStatsTracker: rename ProfitTracker to ProfitStatsTracker

This commit is contained in:
Andy Cheng 2023-07-10 15:37:19 +08:00
parent e13115737b
commit 5a8a2e8631
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28
3 changed files with 29 additions and 29 deletions

View File

@ -113,7 +113,7 @@ exchangeStrategies:
# higher highs in long position and lower lows in short position # higher highs in long position and lower lows in short position
oppositeDirectionAsPosition: false oppositeDirectionAsPosition: false
profitTracker: profitStatsTracker:
interval: 1d interval: 1d
window: 30 window: 30
accumulatedProfitReport: accumulatedProfitReport:

View File

@ -6,7 +6,7 @@ import (
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
type ProfitTracker struct { type ProfitStatsTracker struct {
types.IntervalWindow types.IntervalWindow
// Accumulated profit report // Accumulated profit report
@ -20,12 +20,12 @@ type ProfitTracker struct {
tradeStats *types.TradeStats tradeStats *types.TradeStats
} }
func (p *ProfitTracker) Subscribe(session *bbgo.ExchangeSession) { func (p *ProfitStatsTracker) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, p.Market.Symbol, types.SubscribeOptions{Interval: p.Interval}) session.Subscribe(types.KLineChannel, p.Market.Symbol, types.SubscribeOptions{Interval: p.Interval})
} }
// InitOld is for backward capability. ps is the ProfitStats of the strategy, Market is the strategy Market // InitOld is for backward capability. ps is the ProfitStats of the strategy, Market is the strategy Market
func (p *ProfitTracker) InitOld(market types.Market, ps **types.ProfitStats, ts *types.TradeStats) { func (p *ProfitStatsTracker) InitOld(market types.Market, ps **types.ProfitStats, ts *types.TradeStats) {
p.Market = market p.Market = market
if *ps == nil { if *ps == nil {
@ -43,12 +43,12 @@ func (p *ProfitTracker) InitOld(market types.Market, ps **types.ProfitStats, ts
} }
// Init initialize the tracker with the given Market // Init initialize the tracker with the given Market
func (p *ProfitTracker) Init(market types.Market, ts *types.TradeStats) { func (p *ProfitStatsTracker) Init(market types.Market, ts *types.TradeStats) {
ps := types.NewProfitStats(p.Market) ps := types.NewProfitStats(p.Market)
p.InitOld(market, &ps, ts) p.InitOld(market, &ps, ts)
} }
func (p *ProfitTracker) Bind(session *bbgo.ExchangeSession, tradeCollector *bbgo.TradeCollector) { func (p *ProfitStatsTracker) Bind(session *bbgo.ExchangeSession, tradeCollector *bbgo.TradeCollector) {
tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) { tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) {
if profit == nil { if profit == nil {
return return
@ -68,7 +68,7 @@ func (p *ProfitTracker) Bind(session *bbgo.ExchangeSession, tradeCollector *bbgo
} }
// Rotate the tracker to make a new ProfitStats to record the profits // Rotate the tracker to make a new ProfitStats to record the profits
func (p *ProfitTracker) Rotate() { func (p *ProfitStatsTracker) Rotate() {
// Update report // Update report
if p.AccumulatedProfitReport != nil { if p.AccumulatedProfitReport != nil {
p.AccumulatedProfitReport.Rotate(*p.CurrentProfitStats, p.tradeStats) p.AccumulatedProfitReport.Rotate(*p.CurrentProfitStats, p.tradeStats)
@ -82,11 +82,11 @@ func (p *ProfitTracker) Rotate() {
} }
} }
func (p *ProfitTracker) AddProfit(profit types.Profit) { func (p *ProfitStatsTracker) AddProfit(profit types.Profit) {
(*p.CurrentProfitStats).AddProfit(profit) (*p.CurrentProfitStats).AddProfit(profit)
} }
func (p *ProfitTracker) AddTrade(trade types.Trade) { func (p *ProfitStatsTracker) AddTrade(trade types.Trade) {
(*p.CurrentProfitStats).AddTrade(trade) (*p.CurrentProfitStats).AddTrade(trade)
if p.AccumulatedProfitReport != nil { if p.AccumulatedProfitReport != nil {

View File

@ -39,7 +39,7 @@ type Strategy struct {
ProfitStats *types.ProfitStats `persistence:"profit_stats"` ProfitStats *types.ProfitStats `persistence:"profit_stats"`
TradeStats *types.TradeStats `persistence:"trade_stats"` TradeStats *types.TradeStats `persistence:"trade_stats"`
ProfitTracker *report.ProfitTracker `json:"profitTracker"` ProfitStatsTracker *report.ProfitStatsTracker `json:"profitStatsTracker"`
// Symbol is the market symbol you want to trade // Symbol is the market symbol you want to trade
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
@ -132,8 +132,8 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
s.ExitMethods.SetAndSubscribe(session, s) s.ExitMethods.SetAndSubscribe(session, s)
// Profit tracker // Profit tracker
if s.ProfitTracker != nil { if s.ProfitStatsTracker != nil {
s.ProfitTracker.Subscribe(session) s.ProfitStatsTracker.Subscribe(session)
} }
} }
@ -356,25 +356,25 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.orderExecutor.Bind() s.orderExecutor.Bind()
// Setup profit tracker // Setup profit tracker
if s.ProfitTracker != nil { if s.ProfitStatsTracker != nil {
if s.ProfitTracker.CurrentProfitStats == nil { if s.ProfitStatsTracker.CurrentProfitStats == nil {
s.ProfitTracker.InitOld(s.Market, &s.ProfitStats, s.TradeStats) s.ProfitStatsTracker.InitOld(s.Market, &s.ProfitStats, s.TradeStats)
} }
// Add strategy parameters to report // Add strategy parameters to report
if s.ProfitTracker.AccumulatedProfitReport != nil { if s.ProfitStatsTracker.AccumulatedProfitReport != nil {
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("window", fmt.Sprintf("%d", s.Window)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("window", fmt.Sprintf("%d", s.Window))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("multiplier", fmt.Sprintf("%f", s.SupertrendMultiplier)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("multiplier", fmt.Sprintf("%f", s.SupertrendMultiplier))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("fastDEMA", fmt.Sprintf("%d", s.FastDEMAWindow)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("fastDEMA", fmt.Sprintf("%d", s.FastDEMAWindow))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("slowDEMA", fmt.Sprintf("%d", s.SlowDEMAWindow)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("slowDEMA", fmt.Sprintf("%d", s.SlowDEMAWindow))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("takeProfitAtrMultiplier", fmt.Sprintf("%f", s.TakeProfitAtrMultiplier)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("takeProfitAtrMultiplier", fmt.Sprintf("%f", s.TakeProfitAtrMultiplier))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("stopLossByTriggeringK", fmt.Sprintf("%t", s.StopLossByTriggeringK)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("stopLossByTriggeringK", fmt.Sprintf("%t", s.StopLossByTriggeringK))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedSupertrend", fmt.Sprintf("%t", s.StopByReversedSupertrend)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedSupertrend", fmt.Sprintf("%t", s.StopByReversedSupertrend))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedDema", fmt.Sprintf("%t", s.StopByReversedDema)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedDema", fmt.Sprintf("%t", s.StopByReversedDema))
s.ProfitTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedLinGre", fmt.Sprintf("%t", s.StopByReversedLinGre)) s.ProfitStatsTracker.AccumulatedProfitReport.AddStrategyParameter("stopByReversedLinGre", fmt.Sprintf("%t", s.StopByReversedLinGre))
} }
s.ProfitTracker.Bind(s.session, s.orderExecutor.TradeCollector()) s.ProfitStatsTracker.Bind(s.session, s.orderExecutor.TradeCollector())
} }
// AccountValueCalculator // AccountValueCalculator
@ -528,9 +528,9 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
defer wg.Done() defer wg.Done()
// Output profit report // Output profit report
if s.ProfitTracker != nil { if s.ProfitStatsTracker != nil {
if s.ProfitTracker.AccumulatedProfitReport != nil { if s.ProfitStatsTracker.AccumulatedProfitReport != nil {
s.ProfitTracker.AccumulatedProfitReport.Output() s.ProfitStatsTracker.AccumulatedProfitReport.Output()
} }
} }