schedule: graceful cancel orders before the next submission

This commit is contained in:
c9s 2023-06-07 16:30:54 +08:00
parent f6a300a7c4
commit e0e27e75bb
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -183,7 +183,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
}
if quoteBalance.Available.Compare(quoteQuantity) < 0 {
bbgo.Notify("Can not place scheduled %s order: quote balance %s is not enough: %v < %v", s.Symbol, s.Market.QuoteCurrency, quoteBalance.Available, quoteQuantity)
log.Errorf("can not place scheduled %s order: quote balance %s is not enough: %v < %v", s.Symbol, s.Market.QuoteCurrency, quoteBalance.Available, quoteQuantity)
return
}
@ -220,6 +219,10 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
submitOrder.Price = closePrice
}
if err := s.orderExecutor.GracefulCancel(ctx); err != nil {
log.WithError(err).Errorf("cancel order error")
}
bbgo.Notify("Submitting scheduled %s order with quantity %s at price %s", s.Symbol, quantity.String(), closePrice.String())
_, err := s.orderExecutor.SubmitOrders(ctx, submitOrder)
if err != nil {