Merge pull request #1437 from anywhy/fix_exit_check

FIX: deactivate exit when position in closing
This commit is contained in:
c9s 2023-11-30 10:48:21 +08:00 committed by GitHub
commit 11a8b8b6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7 additions and 9 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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() {