mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: refactor trailing stop using position interface
This commit is contained in:
parent
a5e1ae4867
commit
ae17e0ddbe
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user