QuantConnect / Lean.Brokerages.ByBit

ByBit Brokerage Integration to LEAN
4 stars 5 forks source link

Order can not always be canceled #11

Closed arodus closed 7 months ago

arodus commented 7 months ago

Expected Behavior

Orders are being canceled at all times without issues.

Actual Behavior

Some orders can not always be canceled, it happens in multiple occasions but It seems I found one way to reliably reproduce it. (See reproducing the problem)

Potential Solution

Don't raise an error when the status is CancelPending here: https://github.com/QuantConnect/Lean.Brokerages.ByBit/blob/a5b3f02c04838b5bb0a66e496b8ca958f0518a95/QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs#L201-L206

It seems that sometimes the order status is already CancelPending even though the cancel request was never sent to the brokerage.

Reproducing the Problem

20231129 06:56:56.592 ERROR:: Brokerage Warning: Order already canceled or cancellation submitted
20231129 06:56:56.593 ERROR:: Brokerage failed to cancel order with id 1

Checklist

zurpet commented 7 months ago

Hi Arodus, this is really curious behavior which should be further investigated. How does it even happen that a freshly submitted order ends up being in CancelPending state right away? Are you able to trace exactly where it switches to this state?

arodus commented 7 months ago

Hi @zurpet, Martin explained it here: https://github.com/QuantConnect/Lean.Brokerages.ByBit/pull/12#discussion_r1410684480