strategy: do not submit order if current position < market.MinQuantity

This commit is contained in:
Andy Cheng 2022-03-14 11:45:24 +08:00
parent a6a4eb94f0
commit ad7605e7b2
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -408,7 +408,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
if !s.TrailingStopTarget.TrailingStopCallbackRatio.IsZero() { if !s.TrailingStopTarget.TrailingStopCallbackRatio.IsZero() {
// Update trailing stop when the position changes // Update trailing stop when the position changes
s.tradeCollector.OnPositionUpdate(func(position *types.Position) { 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 // Cancel the original order
if err := s.cancelOrder(s.trailingStopControl.OrderID, ctx, session); err != nil { if err := s.cancelOrder(s.trailingStopControl.OrderID, ctx, session); err != nil {
log.WithError(err).Errorf("Can not cancel the original trailing stop order!") 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() highPrice := kline.GetHigh()
if s.TrailingStopTarget.TrailingStopCallbackRatio.Sign() > 0 { 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 // Update trailing orders with current high price
s.trailingStopControl.CurrentHighestPrice = highPrice s.trailingStopControl.CurrentHighestPrice = highPrice
} else if s.trailingStopControl.CurrentHighestPrice.Compare(highPrice) < 0 { // With a position } else if s.trailingStopControl.CurrentHighestPrice.Compare(highPrice) < 0 { // With a position