Errors
Error format
All errors use one format:
{
"type": "validation_error",
"errors": [
{ "code": "min_amount", "detail": "مقدار سفارش کمتر از حداقل مجاز خرید است", "attr": "base_amount" }
]
}
| Field | Description |
|---|---|
type | validation_error (400), client_error (401/403/404/409/429) or server_error (5xx) |
errors[].code | Stable, English, machine-readable. Base your logic on this only. |
errors[].detail | Human message, in Persian. It may change at any time; do not parse it. |
errors[].attr | The request field (or query parameter) the error is about; "non_field_errors" for errors about a combination of fields (e.g. amount_conflict); null for errors not tied to a field (auth, insufficient_balance, …) |
errorscan have more than one item (for example several invalid fields).401responses carryWWW-Authenticate: X-API-Key, and429responses carryRetry-After.
Error code catalog
| HTTP | code | When |
|---|---|---|
| 401 | not_authenticated | No X-API-Key header (a JWT alone counts as no key) |
| 401 | invalid_api_key | Unknown or malformed key |
| 401 | api_key_revoked | Key revoked (by user, admin, or password change/reset) |
| 401 | api_key_expired | Key past its expiry |
| 401 | user_inactive | The key owner's account is deactivated |
| 403 | ip_not_allowed | Key has an IP allow-list and the request IP is not in it |
| 403 | api_disabled | Public API turned off globally (maintenance) |
| 403 | api_blocked | API access blocked for this user by an admin |
| 403 | kyc_required | The user's KYC is no longer valid |
| 403 | insufficient_scope | read key on a trade endpoint |
| 403 | trade_blocked | Trading blocked for this user |
| 404 | not_found | Unknown resource, or not visible to this user |
| 409 | client_id_conflict | client_id reused with a different request |
| 429 | throttled | Rate limit exceeded (Rate limits) |
| 400 | required, null, invalid, invalid_choice, min_value, max_digits, max_whole_digits, max_decimal_places | Field input validation, standard codes (attr names the field or parameter) |
| 400 | amount_required, amount_conflict | Neither or both of base_amount / quote_amount sent (attr: "non_field_errors") |
| 400 | market_inactive, side_disabled, limit_disabled | Market, side or limit trading switched off |
| 400 | min_amount, max_amount | Amount outside market limits |
| 400 | insufficient_balance | Not enough available balance |
| 400 | quote_not_found | Quote does not exist, is not yours, or was not created by POST /quotes/ |
| 400 | quote_expired | More than 30 s since the quote |
| 400 | quote_used | Quote already used for another order |
| 400 | quote_kind_mismatch | Limit quote sent to /orders/, or spot quote to /limit-orders/ |
| 400 | invalid_target_price | Target price on the wrong side of the current price (re-checked when the limit order is placed) |
| 400 | invalid_expires_at | Limit-order expiry in the past or beyond the maximum |
| 400 | order_not_cancellable | Cancel on a non-active limit order |
| 500 | order_failed | Settlement failed and the whole order was rolled back; nothing was created and no funds moved |
| 503 | price_unavailable | No reliable price right now, retry shortly |
| 500 | error | Unexpected server error |
Handling tips
- Branch on
code, not ondetailand not only on the HTTP status. New codes may be added; have a default branch for unknown ones. quote_expired/quote_used: get a new quote and try once more, with a newclient_id. Ifquote_expiredkeeps happening, shorten the time between quote and order.insufficient_balance: no order was created. Do not retry until the wallet is topped up. ReadGET /balances/; part of the balance may be locked (locked) in active limit orders.min_amount/max_amount: readlimitsfromGET /markets/and adjust the amount.market_inactive/side_disabled/limit_disabled/api_disabled: temporary. Check again every few minutes; do not hammer.401s,ip_not_allowed,insufficient_scope,api_blocked,kyc_required: retrying will not fix these. Stop the bot and alert.order_failed: nothing was created and no funds moved. You can resend the same request while the quote is still valid.- Field errors (
required,invalid,min_value, …): checkattr; retrying without fixing the input will not help. - Connection drop or timeout on
POST /orders/: you do not know whether the order was created. See safe retries.
try:
order = place_order(...)
except TalanoError as e:
if e.code == "quote_expired":
... # new quote, retry once
elif e.code == "insufficient_balance":
... # stop, alert
elif e.status == 429:
... # sleep Retry-After seconds
else:
raise