improve/profitTracker: subscribe kline in strategy Subscribe()

This commit is contained in:
Andy Cheng 2023-07-10 15:26:57 +08:00
parent 80170e0397
commit bcbb27de79
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28
2 changed files with 9 additions and 2 deletions

View File

@ -20,6 +20,10 @@ type ProfitTracker struct {
tradeStats *types.TradeStats
}
func (p *ProfitTracker) Subscribe(session *bbgo.ExchangeSession) {
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
func (p *ProfitTracker) InitOld(market types.Market, ps **types.ProfitStats, ts *types.TradeStats) {
p.Market = market
@ -45,8 +49,6 @@ func (p *ProfitTracker) Init(market types.Market, ts *types.TradeStats) {
}
func (p *ProfitTracker) Bind(session *bbgo.ExchangeSession, tradeCollector *bbgo.TradeCollector) {
session.Subscribe(types.KLineChannel, p.Market.Symbol, types.SubscribeOptions{Interval: p.Interval})
tradeCollector.OnProfit(func(trade types.Trade, profit *types.Profit) {
if profit == nil {
return

View File

@ -130,6 +130,11 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LinearRegression.Interval})
s.ExitMethods.SetAndSubscribe(session, s)
// Profit tracker
if s.ProfitTracker != nil {
s.ProfitTracker.Subscribe(session)
}
}
// Position control