Quote → spot order
A spot order always has two steps: a quote (POST /quotes/) and an order (POST /orders/). The quote locks the price for 30 seconds and the order executes it.
GET /markets/ → POST /quotes/ → (≤ 30 s) → POST /orders/ → status: done
1. The market and its state
curl -s -H "X-API-Key: $TALANO_API_KEY" https://service.talano.ir/api/public/v1/markets/
Before trading, check that:
trading.buy_enabledortrading.sell_enabledistruefor your side (these flags already includetrading.enabled).- Your amount is between
limits.spot.min_buyandlimits.spot.max_buy(ormin_sell/max_sell).
2. The quote
Give the amount with one of:
| Field | Meaning | Example |
|---|---|---|
base_amount | How many milligrams of gold | 1000 = 1 g |
quote_amount | How many Toman worth | 5000000 = "buy 5 million Toman of gold" |
curl -s -X POST \
-H "X-API-Key: $TALANO_API_KEY" -H "Content-Type: application/json" \
-d '{"market_id":"3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10","side":"sell","quote_amount":5000000}' \
https://service.talano.ir/api/public/v1/quotes/
With quote_amount, the server computes base_amount. In the response, total is quote_amount + fee for a buy (what you pay) and quote_amount - fee for a sell (what you receive).
3. The order
curl -s -X POST \
-H "X-API-Key: $TALANO_API_KEY" -H "Content-Type: application/json" \
-d '{"quote_id":"<QUOTE_ID>","base_amount":<BASE_AMOUNT_FROM_QUOTE>,"client_id":"bot-2026-11-07-000123"}' \
https://service.talano.ir/api/public/v1/orders/
quote_idmust be a spot quote of yours (kind: "spot") that is unexpired and unused.- Market and side come from the quote.
- Send the quote's
base_amount, converting the response string to an integer ("1000"→1000). Limits and balance are checked again, and the fee is calculated for this amount at the quoted price. - Buys are paid from the Toman wallet only: if
availableTMN is less thantotal, you getinsufficient_balance. - For sells, if
availableMLG is less thanbase_amount, you getinsufficient_balance. - In both cases no order is created, and the quote stays usable until it expires.
| Response | Meaning |
|---|---|
201 | New order, settled immediately (status: "done"). The body is an Order object |
200 | Same client_id + same quote_id + same base_amount as an earlier spot order; the existing order, unchanged |
409 client_id_conflict | The client_id was already used for a different request |
Handling errors
| Code | What to do |
|---|---|
quote_expired | Get a fresh quote and send the order once more with a new client_id |
quote_used | The quote was already used. If you may have placed the order yourself, look it up by the old client_id first; otherwise get a fresh quote and a new client_id |
quote_not_found | The quote is not yours or was not created by POST /quotes/ (app price locks are not accepted) |
insufficient_balance | No order was created. Do not retry until the wallet is topped up. Check GET /balances/ |
min_amount / max_amount | Adjust the amount to the market's limits.spot |
side_disabled / market_inactive | Trading on that side is closed for now. Check again in a few minutes |
price_unavailable (503) | Wait a few seconds and request a new quote |
order_failed (500) | Settlement failed and everything was rolled back; nothing was created. Resend the same request while the quote is still valid |
A complete Python example covering all of the above:
spot_order.py
"""Quote -> spot order with error handling.
Handles the errors every bot meets:
* quote_expired / quote_used -> get a new quote and try once more, with a NEW client_id
* order_failed -> nothing was created; the same quote may be retried while valid
* insufficient_balance -> not enough available Toman (buy) or gold (sell): stop, no gateway exists
Every number in a response is a string: parse with Decimal, convert base_amount to int to send it back.
"""
import os
import uuid
from decimal import Decimal
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"]
class TalanoError(Exception):
def __init__(self, status: int, body: dict):
first = (body.get("errors") or [{}])[0]
self.status = status
self.code = first.get("code", "error") # branch on this, never on `detail`
self.detail = first.get("detail") # Persian, human-readable
self.attr = first.get("attr")
super().__init__(f"{status} {self.code}")
def call(method: str, path: str, **kwargs) -> dict:
r = s.request(method, f"{BASE}{path}", timeout=10, **kwargs)
if r.status_code >= 400:
try:
body = r.json()
except ValueError:
body = {}
raise TalanoError(r.status_code, body)
return r.json()
def find_market(symbol: str = "MLG/TMN") -> dict:
return next(m for m in call("GET", "/markets/") if m["symbol"] == symbol)
def spot_order(market_id: str, side: str, base_amount: int) -> dict:
for attempt in (1, 2):
quote = call("POST", "/quotes/", json={
"market_id": market_id, "side": side, "base_amount": base_amount,
})
print(f"quote: {quote['base_amount']} mg at {Decimal(quote['price'])} "
f"-> total {Decimal(quote['total'])} Toman")
# One client_id per quote: retries of THIS request are safe, a new quote gets a new one.
body = {
"quote_id": quote["quote_id"],
"base_amount": int(quote["base_amount"]), # response numbers are strings
"client_id": str(uuid.uuid4()),
}
try:
return call("POST", "/orders/", json=body)
except TalanoError as e:
if e.code == "order_failed":
# Rolled back, nothing created: the same quote can be retried while it is valid.
return call("POST", "/orders/", json=body)
if e.code in ("quote_expired", "quote_used") and attempt == 1:
print(f"{e.code}, requesting a new quote")
continue
raise
raise RuntimeError("unreachable")
if __name__ == "__main__":
market = find_market()
try:
order = spot_order(market["id"], "buy", 1000)
print("order", order["id"], order["status"], "total", order["total"])
except TalanoError as e:
if e.code == "insufficient_balance":
balances = {b["asset"]: b for b in call("GET", "/balances/")}
print("not enough balance, available TMN:", balances["TMN"]["available"])
elif e.code in ("min_amount", "max_amount"):
print("amount outside market limits:", market["limits"]["spot"])
elif e.code in ("market_inactive", "side_disabled"):
print("trading is switched off right now, try later")
else:
raise
Order object
Spot and limit orders use the same shape:
{
"id": "e2b7c1d4-9f3a-4b8e-8c21-5d6f7a8b9c0d",
"client_id": "bot-2026-11-07-000123",
"market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
"market_symbol": "MLG/TMN",
"order_type": "ordinary",
"side": "buy",
"status": "done",
"base_amount": "1000",
"price": "10512",
"target_price": null,
"execution_price": null,
"fee": "52560",
"total": "10564560",
"locked_amount": "0",
"created_at": "2026-11-07T08:54:11.180266Z",
"traded_at": "2026-11-07T08:54:11.866001Z",
"expires_at": null
}
| Field | Description |
|---|---|
client_id | null when none was sent or the order was placed in the Talano app |
price | Unit price the order trades at (Toman per mg). Equals target_price for limit orders |
target_price | Set for limit orders, null for spot |
total | Buy: base_amount × price + fee. Sell: base_amount × price − fee |
execution_price | Market price when a limit order executed (null otherwise) |
locked_amount | Funds locked by an active limit order (Toman for buys, mg for sells) |
traded_at / expires_at | null when not applicable |
Tracking orders
# one order
curl -s -H "X-API-Key: $TALANO_API_KEY" https://service.talano.ir/api/public/v1/orders/<ORDER_ID>/
# history, filtered and paginated (newest first)
curl -s -H "X-API-Key: $TALANO_API_KEY" \
"https://service.talano.ir/api/public/v1/orders/?side=buy&status=done&created_after=2026-11-01T00:00:00Z&limit=50"
GET /orders/ shows all your spot and limit orders, including ones placed in the app. Filters (all optional):
| Param | Values |
|---|---|
market_id | UUID |
side | buy, sell |
order_type | ordinary, limit |
status | pending, active, done, failed, cancelled, expired |
client_id | exact match |
created_after | ISO 8601, inclusive (>=) |
created_before | ISO 8601, exclusive (<) |
limit, offset | pagination |
An invalid filter value gives 400 invalid with attr set to the parameter name.