mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: trigger price check when kline is updated (not just closed)
This commit is contained in:
parent
fdf2a91604
commit
ac1b5aa0e2
|
@ -124,14 +124,17 @@ func (s *ProtectiveStopLoss) Bind(session *ExchangeSession, orderExecutor *Gener
|
||||||
})
|
})
|
||||||
|
|
||||||
position := orderExecutor.Position()
|
position := orderExecutor.Position()
|
||||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
|
|
||||||
|
f := func(kline types.KLine) {
|
||||||
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
|
||||||
}
|
}
|
||||||
}))
|
}
|
||||||
|
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||||
|
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||||
|
|
||||||
if !IsBackTesting && enableMarketTradeStop {
|
if !IsBackTesting && enableMarketTradeStop {
|
||||||
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
||||||
|
|
|
@ -26,9 +26,12 @@ func (s *RoiStopLoss) Bind(session *ExchangeSession, orderExecutor *GeneralOrder
|
||||||
s.orderExecutor = orderExecutor
|
s.orderExecutor = orderExecutor
|
||||||
|
|
||||||
position := orderExecutor.Position()
|
position := orderExecutor.Position()
|
||||||
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) {
|
f := func(kline types.KLine) {
|
||||||
s.checkStopPrice(kline.Close, position)
|
s.checkStopPrice(kline.Close, position)
|
||||||
}))
|
}
|
||||||
|
|
||||||
|
session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||||
|
session.MarketDataStream.OnKLine(types.KLineWith(s.Symbol, types.Interval1m, f))
|
||||||
|
|
||||||
if !IsBackTesting && enableMarketTradeStop {
|
if !IsBackTesting && enableMarketTradeStop {
|
||||||
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
session.MarketDataStream.OnMarketTrade(func(trade types.Trade) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user