mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
Merge pull request #1437 from anywhy/fix_exit_check
FIX: deactivate exit when position in closing
This commit is contained in:
commit
11a8b8b6ee
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ func (s *TrailingStop2) checkStopPrice(price fixedpoint.Value, position *types.P
|
|||
// check if we have the minimal profit
|
||||
roi := position.ROI(price)
|
||||
if roi.Compare(s.MinProfit) >= 0 {
|
||||
Notify("[trailingStop] activated: %s ROI %s > minimal profit ratio %f", s.Symbol, roi.Percentage(), s.MinProfit.Float64())
|
||||
Notify("[trailingStop] activated: %s ROI %s > minimal profit ratio %s", s.Symbol, roi.Percentage(), s.MinProfit.Percentage())
|
||||
s.activated = true
|
||||
}
|
||||
} else if !s.ActivationRatio.IsZero() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user