Skip to main content

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_enabled or trading.sell_enabled is true for your side (these flags already include trading.enabled).
  • Your amount is between limits.spot.min_buy and limits.spot.max_buy (or min_sell / max_sell).

2. The quote​

Give the amount with one of:

FieldMeaningExample
base_amountHow many milligrams of gold1000 = 1 g
quote_amountHow many Toman worth5000000 = "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_id must 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 available TMN is less than total, you get insufficient_balance.
  • For sells, if available MLG is less than base_amount, you get insufficient_balance.
  • In both cases no order is created, and the quote stays usable until it expires.
ResponseMeaning
201New order, settled immediately (status: "done"). The body is an Order object
200Same client_id + same quote_id + same base_amount as an earlier spot order; the existing order, unchanged
409 client_id_conflictThe client_id was already used for a different request

Handling errors​

CodeWhat to do
quote_expiredGet a fresh quote and send the order once more with a new client_id
quote_usedThe 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_foundThe quote is not yours or was not created by POST /quotes/ (app price locks are not accepted)
insufficient_balanceNo order was created. Do not retry until the wallet is topped up. Check GET /balances/
min_amount / max_amountAdjust the amount to the market's limits.spot
side_disabled / market_inactiveTrading 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
}
FieldDescription
client_idnull when none was sent or the order was placed in the Talano app
priceUnit price the order trades at (Toman per mg). Equals target_price for limit orders
target_priceSet for limit orders, null for spot
totalBuy: base_amount × price + fee. Sell: base_amount × price − fee
execution_priceMarket price when a limit order executed (null otherwise)
locked_amountFunds locked by an active limit order (Toman for buys, mg for sells)
traded_at / expires_atnull 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):

ParamValues
market_idUUID
sidebuy, sell
order_typeordinary, limit
statuspending, active, done, failed, cancelled, expired
client_idexact match
created_afterISO 8601, inclusive (>=)
created_beforeISO 8601, exclusive (<)
limit, offsetpagination

An invalid filter value gives 400 invalid with attr set to the parameter name.