client_id and safe retries
Say you send POST /orders/ and the connection drops or times out. You do not know whether the order was created. If you blindly send it again, you might buy twice.
client_id solves this.
What is client_id?
An ID that you generate for each order and send with the request:
- 1–64 characters of
[A-Za-z0-9_-] - Unique per user, across all spot and limit orders
- Examples: a UUID, or
bot-2026-11-07-000123
The three outcomes
| Request | Response |
|---|---|
New client_id | 201, a new order |
Same client_id with the same quote_id, base_amount and endpoint | 200, the existing order unchanged. No second order is created, even if both requests arrive at the same time |
Same client_id with anything different | 409 client_id_conflict |
The same rules apply to POST /limit-orders/. client_ids are shared across spot and limit orders: one used for a spot order gets 409 on a limit order.
Recovering after a timeout
POST /orders/ (client_id = X)
│
├── response 201/200 → done
│
└── no response (timeout / connection error)
│
GET /orders/by-client-id/X/
├── 200 → the order exists, use it (do NOT resend)
└── 404 → it was never created; resend the same POST (same X)
Both approaches are safe:
- Resend the same request with the same
client_id. If the order exists, you get200and that order. - Look it up with
GET /orders/by-client-id/{client_id}/. If you get404, the order was not created and you can send it.
curl -s -H "X-API-Key: $TALANO_API_KEY" \
https://service.talano.ir/api/public/v1/orders/by-client-id/bot-2026-11-07-000123/
Quotes are valid for 30 seconds
If recovery takes longer than 30 seconds and the order was not created, resending gets quote_expired. Request a new quote then, and generate a new client_id: tie each client_id to one quote.
Python example
idempotent_order.py
"""Safe retries with client_id and recovery with GET /orders/by-client-id/.
If the connection drops after you POST an order, you cannot know whether it was created.
Never just resend without a client_id. With one, either:
* resend the same body (same client_id + quote_id + base_amount) -> 200 with the existing order, or
* look it up by client_id -> 200 if it exists, 404 if it was never created.
"""
import os
import uuid
import requests
BASE = os.environ.get("TALANO_BASE_URL", "https://service.talano.ir/api/public/v1")
s = requests.Session()
s.headers["X-API-Key"] = os.environ["TALANO_API_KEY"]
def place_order_safely(quote: dict, client_id: str, attempts: int = 3) -> dict:
body = {
"quote_id": quote["quote_id"],
"base_amount": int(quote["base_amount"]), # response numbers are strings
"client_id": client_id,
}
for attempt in range(1, attempts + 1):
try:
r = s.post(f"{BASE}/orders/", json=body, timeout=10)
except (requests.ConnectionError, requests.Timeout):
print(f"attempt {attempt}: no response, checking whether the order exists")
found = s.get(f"{BASE}/orders/by-client-id/{client_id}/", timeout=10)
if found.status_code == 200:
return found.json() # it was created; do not send again
continue # 404: never created; resending is safe
if r.status_code in (200, 201): # 201 new, 200 = same client_id replayed
return r.json()
r.raise_for_status()
raise RuntimeError("could not place order")
market = next(m for m in s.get(f"{BASE}/markets/", timeout=10).json() if m["symbol"] == "MLG/TMN")
quote = s.post(f"{BASE}/quotes/", json={
"market_id": market["id"], "side": "buy", "base_amount": 1000,
}, timeout=10).json()
client_id = f"bot-{uuid.uuid4()}" # 1-64 chars of [A-Za-z0-9_-], unique per user
order = place_order_safely(quote, client_id)
print("order", order["id"], order["status"], "client_id", order["client_id"])
What is safe without client_id?
| Request | Without client_id |
|---|---|
All GETs | Always safe |
POST /quotes/ | Safe; an extra quote is harmless and expires after 30 s |
POST /limit-orders/{order_id}/cancel/ | Safe; a second cancel gets order_not_cancellable, and GET /orders/{order_id}/ shows it is cancelled |
POST /orders/ and POST /limit-orders/ | Not safe. Always send a client_id |