bbgo/exit_protective_stop_loss: use types.KLineWith

This commit is contained in:
c9s 2022-09-16 11:20:39 +08:00
parent 2f575488c2
commit d4f74822ad
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -123,18 +123,14 @@ func (s *ProtectiveStopLoss) Bind(session *ExchangeSession, orderExecutor *Gener
}) })
position := orderExecutor.Position() position := orderExecutor.Position()
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) { session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
if kline.Symbol != position.Symbol || kline.Interval != types.Interval1m {
return
}
isPositionOpened := !position.IsClosed() && !position.IsDust(kline.Close) isPositionOpened := !position.IsClosed() && !position.IsDust(kline.Close)
if isPositionOpened { if isPositionOpened {
s.handleChange(context.Background(), position, kline.Close, s.orderExecutor) s.handleChange(context.Background(), position, kline.Close, s.orderExecutor)
} else { } else {
s.stopLossPrice = fixedpoint.Zero s.stopLossPrice = fixedpoint.Zero
} }
}) }))
if !IsBackTesting && enableMarketTradeStop { if !IsBackTesting && enableMarketTradeStop {
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) { session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {