feature/profitTracker: add AddTrade()

This commit is contained in:
Andy Cheng 2023-06-16 15:06:58 +08:00
parent d5e194ca80
commit 57cdbb1d77
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -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)
}