Handle System Errors
Problem
Under high concurrency, both the create order and cancel order requests could fail due to system errors (i.e. 500 status code) occasionally. We want to make sure the requests are processed successfully.
Solution
For 500 status code, we just retry creating or cancelling the order. First, check the status of the order using /api/v1/open-order endpoint.
For create order request, we can query the order status by client-request-id
from the request; for cancel order request, we can query the order status by order-id
. Depending on the query result,
we can decide whether to retry the request or not.
Recommendations
We recommend waiting for a reasonable amount of time (e.g. 10 seconds) before querying the order status. This will leave enough time for the order to be processed.
In rare cases where the order status is still pending
upon querying, we recommend waiting until the status changes to active
before proceeding. If the order gets stuck
in pending
status for too long (e.g. 2 minutes), we recommend cancelling the order and retrying the request.