From 57cdbb1d773287237881495b98ffbe8502c52844 Mon Sep 17 00:00:00 2001 From: Andy Cheng Date: Fri, 16 Jun 2023 15:06:58 +0800 Subject: [PATCH] feature/profitTracker: add AddTrade() --- pkg/report/profit_tracker.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/report/profit_tracker.go b/pkg/report/profit_tracker.go index 04f67acae..85b7972d7 100644 --- a/pkg/report/profit_tracker.go +++ b/pkg/report/profit_tracker.go @@ -34,17 +34,17 @@ func (p *ProfitTracker) Init(market types.Market) { } func (p *ProfitTracker) Bind(tradeCollector *bbgo.TradeCollector, session *bbgo.ExchangeSession) { - // TODO: Register kline close callback tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) { p.AddProfit(*profit) }) tradeCollector.OnTrade(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) { - + p.AddTrade(trade) }) + // Rotate profitStats slice session.MarketDataStream.OnKLineClosed(types.KLineWith(p.market.Symbol, p.Interval, func(kline types.KLine) { - + p.Rotate() })) } @@ -61,3 +61,7 @@ func (p *ProfitTracker) Rotate() { func (p *ProfitTracker) AddProfit(profit types.Profit) { (*p.currentProfitStats).AddProfit(profit) } + +func (p *ProfitTracker) AddTrade(trade types.Trade) { + (*p.currentProfitStats).AddTrade(trade) +}