From ad7605e7b210febe61c9ede97364dac9c713ab1c Mon Sep 17 00:00:00 2001 From: Andy Cheng Date: Mon, 14 Mar 2022 11:45:24 +0800 Subject: [PATCH] strategy: do not submit order if current position < market.MinQuantity --- pkg/strategy/support/strategy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/support/strategy.go b/pkg/strategy/support/strategy.go index 8fe151a20..d58050276 100644 --- a/pkg/strategy/support/strategy.go +++ b/pkg/strategy/support/strategy.go @@ -408,7 +408,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se if !s.TrailingStopTarget.TrailingStopCallbackRatio.IsZero() { // Update trailing stop when the position changes s.tradeCollector.OnPositionUpdate(func(position *types.Position) { - if position.Base.Sign() > 0 { // Update order if we have a position + if position.Base.Compare(s.Market.MinQuantity) > 0 { // Update order if we have a position // Cancel the original order if err := s.cancelOrder(s.trailingStopControl.OrderID, ctx, session); err != nil { log.WithError(err).Errorf("Can not cancel the original trailing stop order!") @@ -459,7 +459,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se highPrice := kline.GetHigh() if s.TrailingStopTarget.TrailingStopCallbackRatio.Sign() > 0 { - if s.state.Position.Base.Sign() <= 0 { // Without a position + if s.state.Position.Base.Compare(s.Market.MinQuantity) <= 0 { // Without a position // Update trailing orders with current high price s.trailingStopControl.CurrentHighestPrice = highPrice } else if s.trailingStopControl.CurrentHighestPrice.Compare(highPrice) < 0 { // With a position