The rule
Retry with the sameclient_order_id and the same body. Choose a new client_order_id only for a new order.
- If the first request placed the order, the retry returns that order with
200and the headerIdempotent-Replayed: true. Nothing new is placed. - If the first request placed nothing, the retry places the order now, with
201.
When to retry
An error response always means that nothing was recorded. The one exception is
503 and 500, where the order may have been recorded before the failure, which is exactly the case a retry with the same client_order_id handles.
A retrying client
client_order_id once, before the first attempt, and reuse it for every retry of that order. If your program can restart mid-order, save the ID before sending, so the restarted program retries the same order instead of placing a new one.
Looking an order up
To check whether a request was recorded without retrying it, look the order up by itsclient_order_id:
404 order_not_found means no order was recorded under that ID, so nothing traded. Retrying the original request is still the simplest way to finish: it covers both outcomes in one call.
Reusing an ID for a different order
Aclient_order_id belongs to one order forever. Sending it with a different body returns 409 client_order_id_reused. The error names the existing order and lists the fields that differ:
client_order_id too. To try again after a rejection, use a new one.
Pending orders
Apending order is recorded and may already be at the exchange. Don’t place it again. Read it until it is final:
pending after a minute is waiting for the exchange to confirm what happened. It becomes final on its own, and we never guess the outcome.