mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
improve/profitTracker: subscribe kline in strategy Subscribe()
This commit is contained in:
parent
80170e0397
commit
bcbb27de79
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user