From a4ccad9463130897ed46167e6b0a82e02e1e1ce4 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 29 Nov 2023 18:26:01 +0800 Subject: [PATCH] FIX: deactivate exit when position in closing --- pkg/bbgo/exit_cumulated_volume_take_profit.go | 3 +-- pkg/bbgo/exit_hh_ll_stop.go | 2 +- pkg/bbgo/exit_lower_shadow_take_profit.go | 3 +-- pkg/bbgo/exit_roi_stop_loss.go | 2 +- pkg/bbgo/exit_roi_take_profit.go | 2 +- pkg/bbgo/exit_trailing_stop.go | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/bbgo/exit_cumulated_volume_take_profit.go b/pkg/bbgo/exit_cumulated_volume_take_profit.go index 440dedf49..332a09b2a 100644 --- a/pkg/bbgo/exit_cumulated_volume_take_profit.go +++ b/pkg/bbgo/exit_cumulated_volume_take_profit.go @@ -15,7 +15,6 @@ import ( // To query the historical quote volume, use the following query: // // > SELECT start_time, `interval`, quote_volume, open, close FROM binance_klines WHERE symbol = 'ETHUSDT' AND `interval` = '5m' ORDER BY quote_volume DESC LIMIT 20; -// type CumulatedVolumeTakeProfit struct { Symbol string `json:"symbol"` @@ -39,7 +38,7 @@ func (s *CumulatedVolumeTakeProfit) Bind(session *ExchangeSession, orderExecutor session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) { closePrice := kline.Close openPrice := kline.Open - if position.IsClosed() || position.IsDust(closePrice) { + if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() { return } diff --git a/pkg/bbgo/exit_hh_ll_stop.go b/pkg/bbgo/exit_hh_ll_stop.go index 6d6847af5..771a9692b 100644 --- a/pkg/bbgo/exit_hh_ll_stop.go +++ b/pkg/bbgo/exit_hh_ll_stop.go @@ -62,7 +62,7 @@ func (s *HigherHighLowerLowStop) Subscribe(session *ExchangeSession) { // determine whether this stop should be activated func (s *HigherHighLowerLowStop) updateActivated(position *types.Position, closePrice fixedpoint.Value) { // deactivate when no position - if position.IsClosed() || position.IsDust(closePrice) { + if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() { s.activated = false return diff --git a/pkg/bbgo/exit_lower_shadow_take_profit.go b/pkg/bbgo/exit_lower_shadow_take_profit.go index 32ac9928e..954a05b8d 100644 --- a/pkg/bbgo/exit_lower_shadow_take_profit.go +++ b/pkg/bbgo/exit_lower_shadow_take_profit.go @@ -30,11 +30,10 @@ func (s *LowerShadowTakeProfit) Bind(session *ExchangeSession, orderExecutor *Ge stdIndicatorSet := session.StandardIndicatorSet(s.Symbol) ewma := stdIndicatorSet.EWMA(s.IntervalWindow) - position := orderExecutor.Position() session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) { closePrice := kline.Close - if position.IsClosed() || position.IsDust(closePrice) { + if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() { return } diff --git a/pkg/bbgo/exit_roi_stop_loss.go b/pkg/bbgo/exit_roi_stop_loss.go index bdcf6e480..b026ecfa0 100644 --- a/pkg/bbgo/exit_roi_stop_loss.go +++ b/pkg/bbgo/exit_roi_stop_loss.go @@ -45,7 +45,7 @@ func (s *RoiStopLoss) Bind(session *ExchangeSession, orderExecutor *GeneralOrder } func (s *RoiStopLoss) checkStopPrice(closePrice fixedpoint.Value, position *types.Position) { - if position.IsClosed() || position.IsDust(closePrice) { + if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() { return } diff --git a/pkg/bbgo/exit_roi_take_profit.go b/pkg/bbgo/exit_roi_take_profit.go index d0d4e8e72..c5853a0e5 100644 --- a/pkg/bbgo/exit_roi_take_profit.go +++ b/pkg/bbgo/exit_roi_take_profit.go @@ -29,7 +29,7 @@ func (s *RoiTakeProfit) Bind(session *ExchangeSession, orderExecutor *GeneralOrd position := orderExecutor.Position() session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) { closePrice := kline.Close - if position.IsClosed() || position.IsDust(closePrice) { + if position.IsClosed() || position.IsDust(closePrice) || position.IsClosing() { return } diff --git a/pkg/bbgo/exit_trailing_stop.go b/pkg/bbgo/exit_trailing_stop.go index f0db8892b..adfc28ae4 100644 --- a/pkg/bbgo/exit_trailing_stop.go +++ b/pkg/bbgo/exit_trailing_stop.go @@ -93,7 +93,7 @@ func (s *TrailingStop2) getRatio(price fixedpoint.Value, position *types.Positio } func (s *TrailingStop2) checkStopPrice(price fixedpoint.Value, position *types.Position) error { - if position.IsClosed() || position.IsDust(price) { + if position.IsClosed() || position.IsDust(price) || position.IsClosing() { return nil }