bbgo: refactor trailing stop using position interface

This commit is contained in:
austin362667 2022-05-30 15:16:52 +08:00
parent a5e1ae4867
commit ae17e0ddbe

View File

@ -58,13 +58,13 @@ func (c *TrailingStopController) Subscribe(session *ExchangeSession) {
func (c *TrailingStopController) Run(ctx context.Context, session *ExchangeSession, tradeCollector *TradeCollector) {
// store the position
c.position = tradeCollector.Position()
c.position = tradeCollector.Position().(*types.Position)
c.averageCost = c.position.AverageCost
// Use trade collector to get the position update event
tradeCollector.OnPositionUpdate(func(position *types.Position) {
tradeCollector.OnPositionUpdate(func(position types.PositionInterface) {
// update average cost if we have it.
c.averageCost = position.AverageCost
c.averageCost = position.(*types.Position).AverageCost
})
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {