{
  "openapi": "3.0.3",
  "info": {
    "title": "Talano Public API",
    "version": "1.0.0",
    "description": "Public, versioned REST API of Talano, the gold-trading platform.\nTrade gold (MLG, milligrams) against Toman (TMN) on the MLG/TMN market with a personal API key.\n\n- Every number in a response is a JSON string (prices, fees, totals, amounts, balances),\n  without exponent or trailing zeros, e.g. `\"10512\"`, `\"2500.123\"`. Parse them as decimals, never floats.\n- Request amounts (`base_amount`, `quote_amount`) are JSON integers. `target_price` is a number or string with at most 2 decimals.\n- Timestamps are ISO 8601 in UTC with a `Z` suffix. Request timestamps should include an offset (no offset = UTC).\n- Authenticate every request with the `X-API-Key` header. Every response has `Cache-Control: no-store`.\n- Request checks run in this order and the first failure is returned: key present, key valid, not revoked,\n  not expired, owner active, IP allowed, public API enabled, user not blocked, KYC, access level, rate limit,\n  then the endpoint's own validation.\n",
    "contact": {
      "name": "Talano developer support",
      "url": "https://developers.talano.ir"
    }
  },
  "servers": [
    {
      "url": "https://service.talano.ir/api/public/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Account",
      "description": "Information about the calling API key."
    },
    {
      "name": "Markets",
      "description": "Markets, trading switches, fees, limits and live prices."
    },
    {
      "name": "Balances",
      "description": "Main (tradable) wallet balances."
    },
    {
      "name": "Quotes",
      "description": "30-second price locks used to place orders."
    },
    {
      "name": "Orders",
      "description": "Spot (market) orders and order history."
    },
    {
      "name": "Limit Orders",
      "description": "Orders that execute when the market reaches a target price."
    }
  ],
  "paths": {
    "/key/": {
      "get": {
        "operationId": "get_key_info",
        "tags": [
          "Account"
        ],
        "summary": "Get API key info",
        "description": "Returns information about the API key used for this request. `allowed_ips` is `[]` when the key has no IP\nwhitelist. `rate_limits` are the limits in force right now (integers; admins can change them).\n",
        "responses": {
          "200": {
            "description": "Key info",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/KeyInfo"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/markets/": {
      "get": {
        "operationId": "list_markets",
        "tags": [
          "Markets"
        ],
        "summary": "List markets",
        "description": "Lists active markets. Not paginated. Never hard-code a market ID; discover it here.",
        "responses": {
          "200": {
            "description": "Active markets",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Market"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/markets/{market_id}/": {
      "parameters": [
        {
          "$ref": "#/components/parameters/MarketId"
        }
      ],
      "get": {
        "operationId": "get_market",
        "tags": [
          "Markets"
        ],
        "summary": "Get a market",
        "description": "Returns one active market. Unknown or inactive markets return `404 not_found`.",
        "responses": {
          "200": {
            "description": "Market",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Market"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/markets/{market_id}/price/": {
      "parameters": [
        {
          "$ref": "#/components/parameters/MarketId"
        }
      ],
      "get": {
        "operationId": "get_market_price",
        "tags": [
          "Markets"
        ],
        "summary": "Get live price",
        "description": "Indicative live buy and sell prices. Does not lock anything; use `POST /quotes/` to trade.\n`fee` is the fee for a minimum-size order on that side. `404` for unknown or inactive markets.\n",
        "responses": {
          "200": {
            "description": "Live price",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MarketPrice"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          },
          "503": {
            "$ref": "#/components/responses/PriceUnavailable"
          }
        }
      }
    },
    "/balances/": {
      "get": {
        "operationId": "list_balances",
        "tags": [
          "Balances"
        ],
        "summary": "List balances",
        "description": "Main (tradable) wallets only. `available = balance - locked`; locked funds belong to active limit orders.\nMLG values are milligrams floored to 3 decimals, TMN values are whole Toman (floored). Every asset traded on\nan active market appears, with `\"0\"` when the user has no wallet yet.\n",
        "responses": {
          "200": {
            "description": "Balances",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Balance"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/quotes/": {
      "post": {
        "operationId": "create_quote",
        "tags": [
          "Quotes"
        ],
        "summary": "Create a quote",
        "description": "Locks a price for 30 seconds. Send exactly one of `base_amount` or `quote_amount`.\nSet `target_price` only for a limit-order quote (`kind: limit`, priced at the limit fee rate).\nA quote backs one order only (`quote_used`); if an order using it is rejected, nothing was created and the\nquote can be retried while it is valid. `expires_at` = `created_at` + 30 seconds.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Quote created",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          },
          "503": {
            "$ref": "#/components/responses/PriceUnavailable"
          }
        }
      }
    },
    "/orders/": {
      "post": {
        "operationId": "create_order",
        "tags": [
          "Orders"
        ],
        "summary": "Place a spot order",
        "description": "Executes a spot quote immediately against your wallet. Buys are paid from the Toman wallet,\nsells from the gold wallet; there is no payment gateway. Market and side come from the quote.\nA new order is settled immediately (`201`, `status: done`). Repeating a request with the same `client_id`,\n`quote_id` and `base_amount` returns the existing order with `200`. On `insufficient_balance` or\n`order_failed` nothing is created and no funds move; the quote can be retried while it is valid.\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OrderCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing order with the same `client_id` (idempotent replay)",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "201": {
            "description": "Order created",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          },
          "500": {
            "$ref": "#/components/responses/OrderFailed"
          }
        }
      },
      "get": {
        "operationId": "list_orders",
        "tags": [
          "Orders"
        ],
        "summary": "List orders",
        "description": "All your spot (`ordinary`) and `limit` orders, including ones placed in the Talano app (`client_id: null`),\nnewest first. Paginated with `limit` and `offset`. An invalid filter value gives `400 invalid` with `attr`\nset to the parameter name.\n",
        "parameters": [
          {
            "name": "market_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "side",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/Side"
            }
          },
          {
            "name": "order_type",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/OrderType"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/OrderStatus"
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "created_after",
            "in": "query",
            "description": "Inclusive (`>=`). ISO 8601 with offset.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "created_before",
            "in": "query",
            "description": "Exclusive (`<`). ISO 8601 with offset.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Offset"
          }
        ],
        "responses": {
          "200": {
            "description": "Page of orders",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PaginatedOrderList"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/orders/{order_id}/": {
      "parameters": [
        {
          "$ref": "#/components/parameters/OrderId"
        }
      ],
      "get": {
        "operationId": "get_order",
        "tags": [
          "Orders"
        ],
        "summary": "Get an order",
        "description": "Returns one of your orders. `404 not_found` if it does not exist, belongs to another user, or is a loan order.",
        "responses": {
          "200": {
            "description": "Order",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/orders/by-client-id/{client_id}/": {
      "parameters": [
        {
          "name": "client_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{1,64}$"
          }
        }
      ],
      "get": {
        "operationId": "get_order_by_client_id",
        "tags": [
          "Orders"
        ],
        "summary": "Get an order by client_id",
        "description": "Looks up an order by your own `client_id`. Use it to recover after a timeout when you do not know whether the order was created.",
        "responses": {
          "200": {
            "description": "Order",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/limit-orders/": {
      "post": {
        "operationId": "create_limit_order",
        "tags": [
          "Limit Orders"
        ],
        "summary": "Place a limit order",
        "description": "Places a limit order from a limit quote (a quote created with `target_price`), within 30 seconds of the quote.\nRequired funds are locked immediately (buy locks Toman `total`, sell locks `base_amount` mg) and the order becomes `active`.\nThe target price is checked again against the live price; if the market moved past it, you get `invalid_target_price`.\nA `client_id` already used for a spot order can't be reused here (`409`).\n",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LimitOrderCreateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing order with the same `client_id` (idempotent replay)",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                },
                "example": {
                  "id": "7c1e2d3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
                  "client_id": "bot-limit-000045",
                  "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
                  "market_symbol": "MLG/TMN",
                  "order_type": "limit",
                  "side": "buy",
                  "status": "active",
                  "base_amount": "1000",
                  "price": "10300",
                  "target_price": "10300",
                  "execution_price": null,
                  "fee": "41200",
                  "total": "10341200",
                  "locked_amount": "10341200",
                  "created_at": "2026-11-07T10:20:05.412870Z",
                  "traded_at": null,
                  "expires_at": "2026-11-14T10:00:00Z"
                }
              }
            }
          },
          "201": {
            "description": "Limit order created",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                },
                "example": {
                  "id": "7c1e2d3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
                  "client_id": "bot-limit-000045",
                  "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
                  "market_symbol": "MLG/TMN",
                  "order_type": "limit",
                  "side": "buy",
                  "status": "active",
                  "base_amount": "1000",
                  "price": "10300",
                  "target_price": "10300",
                  "execution_price": null,
                  "fee": "41200",
                  "total": "10341200",
                  "locked_amount": "10341200",
                  "created_at": "2026-11-07T10:20:05.412870Z",
                  "traded_at": null,
                  "expires_at": "2026-11-14T10:00:00Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    },
    "/limit-orders/{order_id}/cancel/": {
      "parameters": [
        {
          "$ref": "#/components/parameters/OrderId"
        }
      ],
      "post": {
        "operationId": "cancel_limit_order",
        "tags": [
          "Limit Orders"
        ],
        "summary": "Cancel a limit order",
        "description": "No body. Only `active` limit orders can be cancelled, including ones placed in the Talano app; locked funds\nare released. `400 order_not_cancellable` if the order isn't active, `404 not_found` if there is no such\nlimit order for you (also for spot orders).\n",
        "responses": {
          "200": {
            "description": "Cancelled order",
            "headers": {
              "X-RateLimit-Limit": {
                "$ref": "#/components/headers/X-RateLimit-Limit"
              },
              "X-RateLimit-Remaining": {
                "$ref": "#/components/headers/X-RateLimit-Remaining"
              },
              "X-RateLimit-Reset": {
                "$ref": "#/components/headers/X-RateLimit-Reset"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Order"
                },
                "example": {
                  "id": "7c1e2d3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f",
                  "client_id": "bot-limit-000045",
                  "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
                  "market_symbol": "MLG/TMN",
                  "order_type": "limit",
                  "side": "buy",
                  "status": "cancelled",
                  "base_amount": "1000",
                  "price": "10300",
                  "target_price": "10300",
                  "execution_price": null,
                  "fee": "41200",
                  "total": "10341200",
                  "locked_amount": "0",
                  "created_at": "2026-11-07T10:20:05.412870Z",
                  "traded_at": null,
                  "expires_at": "2026-11-14T10:00:00Z"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/Throttled"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Personal API key created in the Talano app, e.g. `tln_7KQ2M9XA_...`."
      }
    },
    "headers": {
      "X-RateLimit-Limit": {
        "description": "Requests allowed per minute in this bucket (read or trade).",
        "schema": {
          "type": "integer",
          "example": 60
        }
      },
      "X-RateLimit-Remaining": {
        "description": "Requests left in the current window.",
        "schema": {
          "type": "integer",
          "example": 57
        }
      },
      "X-RateLimit-Reset": {
        "description": "Unix time (seconds) when the window resets.",
        "schema": {
          "type": "integer",
          "example": 1762510560
        }
      },
      "Retry-After": {
        "description": "Seconds to wait before retrying.",
        "schema": {
          "type": "integer",
          "example": 12
        }
      }
    },
    "parameters": {
      "MarketId": {
        "name": "market_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "example": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10"
      },
      "OrderId": {
        "name": "order_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        },
        "example": "e2b7c1d4-9f3a-4b8e-8c21-5d6f7a8b9c0d"
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "description": "Page size (default 20). Values above 100 are capped at 100.",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "default": 20
        }
      },
      "Offset": {
        "name": "offset",
        "in": "query",
        "description": "Number of items to skip.",
        "schema": {
          "type": "integer",
          "minimum": 0,
          "default": 0
        }
      }
    },
    "responses": {
      "ValidationError": {
        "description": "Validation or business-rule error (`type: validation_error`). `attr` is the field or query parameter, `non_field_errors` for combinations of fields, or `null`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "validation_error",
              "errors": [
                {
                  "code": "min_amount",
                  "detail": "مقدار سفارش کمتر از حداقل مجاز خرید است",
                  "attr": "base_amount"
                }
              ]
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, revoked or expired API key, or inactive owner (`not_authenticated`, `invalid_api_key`, `api_key_revoked`, `api_key_expired`, `user_inactive`). No rate-limit headers.",
        "headers": {
          "WWW-Authenticate": {
            "description": "Always `X-API-Key`.",
            "schema": {
              "type": "string",
              "example": "X-API-Key"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "client_error",
              "errors": [
                {
                  "code": "invalid_api_key",
                  "detail": "کلید API نامعتبر است",
                  "attr": null
                }
              ]
            }
          }
        }
      },
      "Forbidden": {
        "description": "Request not allowed (`ip_not_allowed`, `api_disabled`, `api_blocked`, `kyc_required`, `insufficient_scope`, `trade_blocked`). Only `trade_blocked` responses carry rate-limit headers.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "client_error",
              "errors": [
                {
                  "code": "ip_not_allowed",
                  "detail": "درخواست از این IP مجاز نیست",
                  "attr": null
                }
              ]
            }
          }
        }
      },
      "NotFound": {
        "description": "Unknown resource, or not visible to this user (`not_found`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "client_error",
              "errors": [
                {
                  "code": "not_found",
                  "detail": "یافت نشد",
                  "attr": null
                }
              ]
            }
          }
        }
      },
      "Conflict": {
        "description": "`client_id` reused with a different request (`client_id_conflict`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "client_error",
              "errors": [
                {
                  "code": "client_id_conflict",
                  "detail": "این client_id قبلاً با درخواست دیگری استفاده شده است",
                  "attr": "client_id"
                }
              ]
            }
          }
        }
      },
      "Throttled": {
        "description": "Rate limit exceeded (`throttled`). Wait at least `Retry-After` seconds.",
        "headers": {
          "Retry-After": {
            "$ref": "#/components/headers/Retry-After"
          },
          "X-RateLimit-Limit": {
            "$ref": "#/components/headers/X-RateLimit-Limit"
          },
          "X-RateLimit-Remaining": {
            "$ref": "#/components/headers/X-RateLimit-Remaining"
          },
          "X-RateLimit-Reset": {
            "$ref": "#/components/headers/X-RateLimit-Reset"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "client_error",
              "errors": [
                {
                  "code": "throttled",
                  "detail": "تعداد درخواست‌ها بیش از حد مجاز است",
                  "attr": null
                }
              ]
            }
          }
        }
      },
      "OrderFailed": {
        "description": "Settlement failed and the whole order was rolled back (`order_failed`). Nothing was created and no funds moved; the quote can be retried while it is valid.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "server_error",
              "errors": [
                {
                  "code": "order_failed",
                  "detail": "اجرای سفارش ناموفق بود",
                  "attr": null
                }
              ]
            }
          }
        }
      },
      "PriceUnavailable": {
        "description": "No reliable price right now (`price_unavailable`). Retry after a few seconds.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "type": "server_error",
              "errors": [
                {
                  "code": "price_unavailable",
                  "detail": "قیمت در حال حاضر در دسترس نیست",
                  "attr": null
                }
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "Decimal": {
        "type": "string",
        "pattern": "^-?\\d+(\\.\\d+)?$",
        "description": "Decimal number encoded as a string (no exponent, no trailing zeros) to avoid float precision loss.",
        "example": "10512"
      },
      "Side": {
        "type": "string",
        "enum": [
          "buy",
          "sell"
        ]
      },
      "OrderType": {
        "type": "string",
        "enum": [
          "ordinary",
          "limit"
        ],
        "description": "`ordinary` = spot (market) order, `limit` = limit order."
      },
      "OrderStatus": {
        "type": "string",
        "enum": [
          "pending",
          "active",
          "done",
          "failed",
          "cancelled",
          "expired"
        ]
      },
      "Scope": {
        "type": "string",
        "enum": [
          "read",
          "trade"
        ]
      },
      "QuoteKind": {
        "type": "string",
        "enum": [
          "spot",
          "limit"
        ]
      },
      "RateLimits": {
        "type": "object",
        "required": [
          "read_per_minute",
          "trade_per_minute"
        ],
        "properties": {
          "read_per_minute": {
            "type": "integer",
            "example": 60
          },
          "trade_per_minute": {
            "type": "integer",
            "example": 20
          }
        }
      },
      "KeyInfo": {
        "type": "object",
        "required": [
          "name",
          "prefix",
          "scope",
          "allowed_ips",
          "created_at",
          "expires_at",
          "rate_limits"
        ],
        "properties": {
          "name": {
            "type": "string",
            "example": "my-bot"
          },
          "prefix": {
            "type": "string",
            "example": "tln_7KQ2M9XA"
          },
          "scope": {
            "$ref": "#/components/schemas/Scope"
          },
          "allowed_ips": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Empty when the key has no IP whitelist (works from any IP).",
            "example": [
              "203.0.113.10"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "example": "2026-11-01T08:00:00Z"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "example": "2026-12-01T08:00:00Z"
          },
          "rate_limits": {
            "$ref": "#/components/schemas/RateLimits"
          }
        },
        "example": {
          "name": "my-bot",
          "prefix": "tln_7KQ2M9XA",
          "scope": "trade",
          "allowed_ips": [
            "203.0.113.10"
          ],
          "created_at": "2026-11-01T08:00:00Z",
          "expires_at": "2026-12-01T08:00:00Z",
          "rate_limits": {
            "read_per_minute": 60,
            "trade_per_minute": 20
          }
        }
      },
      "Asset": {
        "type": "object",
        "required": [
          "symbol",
          "name_fa",
          "unit"
        ],
        "properties": {
          "symbol": {
            "type": "string",
            "example": "MLG"
          },
          "name_fa": {
            "type": "string",
            "example": "طلا"
          }
        }
      },
      "MarketTrading": {
        "type": "object",
        "description": "`enabled` is the market-wide trade switch; each `*_enabled` already includes it, so check the specific flag.",
        "required": [
          "enabled",
          "buy_enabled",
          "sell_enabled",
          "limit_enabled"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "buy_enabled": {
            "type": "boolean"
          },
          "sell_enabled": {
            "type": "boolean"
          },
          "limit_enabled": {
            "type": "boolean"
          }
        }
      },
      "MarketFees": {
        "type": "object",
        "description": "Fees are percentages (`\"0.5\"` = 0.5%). Fee = max(percent / 100 × base_amount, min_fee_base) × price. Minimum fees are in base units (mg).",
        "required": [
          "buy_percent",
          "sell_percent",
          "limit_buy_percent",
          "limit_sell_percent",
          "min_buy_fee_base",
          "min_sell_fee_base",
          "min_limit_buy_fee_base",
          "min_limit_sell_fee_base"
        ],
        "properties": {
          "buy_percent": {
            "$ref": "#/components/schemas/Decimal"
          },
          "sell_percent": {
            "$ref": "#/components/schemas/Decimal"
          },
          "limit_buy_percent": {
            "$ref": "#/components/schemas/Decimal"
          },
          "limit_sell_percent": {
            "$ref": "#/components/schemas/Decimal"
          },
          "min_buy_fee_base": {
            "$ref": "#/components/schemas/Decimal"
          },
          "min_sell_fee_base": {
            "$ref": "#/components/schemas/Decimal"
          },
          "min_limit_buy_fee_base": {
            "$ref": "#/components/schemas/Decimal"
          },
          "min_limit_sell_fee_base": {
            "$ref": "#/components/schemas/Decimal"
          }
        }
      },
      "MarketLimitSet": {
        "type": "object",
        "description": "Amounts in base units (milligrams). `\"0\"` means no limit.",
        "required": [
          "min_buy",
          "max_buy",
          "min_sell",
          "max_sell"
        ],
        "properties": {
          "min_buy": {
            "$ref": "#/components/schemas/Decimal"
          },
          "max_buy": {
            "$ref": "#/components/schemas/Decimal"
          },
          "min_sell": {
            "$ref": "#/components/schemas/Decimal"
          },
          "max_sell": {
            "$ref": "#/components/schemas/Decimal"
          }
        }
      },
      "MarketLimits": {
        "type": "object",
        "required": [
          "spot",
          "limit"
        ],
        "properties": {
          "spot": {
            "$ref": "#/components/schemas/MarketLimitSet"
          },
          "limit": {
            "$ref": "#/components/schemas/MarketLimitSet"
          }
        }
      },
      "Market": {
        "type": "object",
        "required": [
          "id",
          "symbol",
          "base_asset",
          "quote_asset",
          "trading",
          "fees",
          "limits"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "symbol": {
            "type": "string",
            "example": "MLG/TMN"
          },
          "base_asset": {
            "$ref": "#/components/schemas/Asset"
          },
          "quote_asset": {
            "$ref": "#/components/schemas/Asset"
          },
          "trading": {
            "$ref": "#/components/schemas/MarketTrading"
          },
          "fees": {
            "$ref": "#/components/schemas/MarketFees"
          },
          "limits": {
            "$ref": "#/components/schemas/MarketLimits"
          }
        },
        "example": {
          "id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
          "symbol": "MLG/TMN",
          "base_asset": {
            "symbol": "MLG",
            "name_fa": "طلا"
          },
          "quote_asset": {
            "symbol": "TMN",
            "name_fa": "تومان"
          },
          "trading": {
            "enabled": true,
            "buy_enabled": true,
            "sell_enabled": true,
            "limit_enabled": true
          },
          "fees": {
            "buy_percent": "0.5",
            "sell_percent": "0.5",
            "limit_buy_percent": "0.4",
            "limit_sell_percent": "0.4",
            "min_buy_fee_base": "10",
            "min_sell_fee_base": "10",
            "min_limit_buy_fee_base": "10",
            "min_limit_sell_fee_base": "10"
          },
          "limits": {
            "spot": {
              "min_buy": "100",
              "max_buy": "1000000",
              "min_sell": "100",
              "max_sell": "1000000"
            },
            "limit": {
              "min_buy": "100",
              "max_buy": "1000000",
              "min_sell": "100",
              "max_sell": "1000000"
            }
          }
        }
      },
      "PriceSide": {
        "type": "object",
        "required": [
          "price",
          "fee"
        ],
        "properties": {
          "price": {
            "$ref": "#/components/schemas/Decimal"
          },
          "fee": {
            "$ref": "#/components/schemas/Decimal"
          }
        }
      },
      "MarketPrice": {
        "type": "object",
        "required": [
          "market_id",
          "buy",
          "sell",
          "timestamp"
        ],
        "properties": {
          "market_id": {
            "type": "string",
            "format": "uuid"
          },
          "buy": {
            "$ref": "#/components/schemas/PriceSide"
          },
          "sell": {
            "$ref": "#/components/schemas/PriceSide"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
          "buy": {
            "price": "10512",
            "fee": "52.56"
          },
          "sell": {
            "price": "10388",
            "fee": "51.94"
          },
          "timestamp": "2026-11-07T08:54:11.162172Z"
        }
      },
      "Balance": {
        "type": "object",
        "required": [
          "asset",
          "balance",
          "locked",
          "available"
        ],
        "properties": {
          "asset": {
            "type": "string",
            "example": "MLG"
          },
          "balance": {
            "$ref": "#/components/schemas/Decimal"
          },
          "locked": {
            "$ref": "#/components/schemas/Decimal"
          },
          "available": {
            "$ref": "#/components/schemas/Decimal"
          }
        },
        "example": {
          "asset": "MLG",
          "balance": "25340.125",
          "locked": "1000",
          "available": "24340.125"
        }
      },
      "QuoteRequest": {
        "type": "object",
        "required": [
          "market_id",
          "side"
        ],
        "properties": {
          "market_id": {
            "type": "string",
            "format": "uuid"
          },
          "side": {
            "$ref": "#/components/schemas/Side"
          },
          "base_amount": {
            "type": "integer",
            "minimum": 1,
            "description": "Amount in milligrams. Send exactly one of `base_amount` / `quote_amount` (`amount_required` / `amount_conflict`, with `attr` = `non_field_errors`)."
          },
          "quote_amount": {
            "type": "integer",
            "minimum": 1,
            "description": "Toman worth to buy/sell; the server computes `base_amount`."
          },
          "target_price": {
            "description": "Only for a limit-order quote. Number or string, at most 2 decimals, at least 0.01. Buy target must be below the current buy price; sell target above the current sell price.",
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d+(\\.\\d{1,2})?$",
                "example": "10300"
              },
              {
                "type": "number",
                "minimum": 0.01
              }
            ]
          }
        },
        "example": {
          "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
          "side": "buy",
          "base_amount": 1000
        }
      },
      "Quote": {
        "type": "object",
        "required": [
          "quote_id",
          "market_id",
          "side",
          "kind",
          "price",
          "base_amount",
          "quote_amount",
          "fee",
          "total",
          "created_at",
          "expires_at"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "format": "uuid"
          },
          "market_id": {
            "type": "string",
            "format": "uuid"
          },
          "side": {
            "$ref": "#/components/schemas/Side"
          },
          "kind": {
            "$ref": "#/components/schemas/QuoteKind"
          },
          "price": {
            "$ref": "#/components/schemas/Decimal"
          },
          "base_amount": {
            "$ref": "#/components/schemas/Decimal"
          },
          "quote_amount": {
            "$ref": "#/components/schemas/Decimal"
          },
          "fee": {
            "$ref": "#/components/schemas/Decimal"
          },
          "total": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "description": "Toman you pay (buy: quote_amount + fee) or receive (sell: quote_amount − fee)."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "quote_id": "b6a0d0f4-2c51-4f3a-9d0e-7a3c5b8e1f22",
          "market_id": "3f1c9a52-6a7e-4d6b-9a7e-0b1e7c2d9f10",
          "side": "buy",
          "kind": "spot",
          "price": "10512",
          "base_amount": "1000",
          "quote_amount": "10512000",
          "fee": "52560",
          "total": "10564560",
          "created_at": "2026-11-07T08:54:11.115210Z",
          "expires_at": "2026-11-07T08:54:41.115210Z"
        }
      },
      "ClientId": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64,
        "pattern": "^[A-Za-z0-9_-]{1,64}$",
        "description": "Your own ID for the order, unique per user across spot and limit orders. Makes retries safe."
      },
      "OrderCreateRequest": {
        "type": "object",
        "required": [
          "quote_id",
          "base_amount"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "format": "uuid",
            "description": "An unexpired, unused **spot** quote of yours."
          },
          "base_amount": {
            "type": "integer",
            "minimum": 1,
            "description": "Milligrams. Normally the quote's `base_amount` (convert the string to an integer). The fee is calculated for this amount at the quoted price."
          },
          "client_id": {
            "$ref": "#/components/schemas/ClientId"
          }
        },
        "example": {
          "quote_id": "b6a0d0f4-2c51-4f3a-9d0e-7a3c5b8e1f22",
          "base_amount": 1000,
          "client_id": "bot-2026-11-07-000123"
        }
      },
      "LimitOrderCreateRequest": {
        "type": "object",
        "required": [
          "quote_id",
          "base_amount"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "format": "uuid",
            "description": "A **limit** quote (created with `target_price`)."
          },
          "base_amount": {
            "type": "integer",
            "minimum": 1,
            "description": "Milligrams",
            "checked against the limit min/max.": null
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Future time, no later than the server maximum (default 30 days; admins can change it). If omitted, the server's default expiry applies."
          },
          "client_id": {
            "$ref": "#/components/schemas/ClientId"
          }
        },
        "example": {
          "quote_id": "1d2e3f40-8a9b-4c5d-9e0f-112233445566",
          "base_amount": 1000,
          "expires_at": "2026-11-14T10:00:00Z",
          "client_id": "bot-limit-000045"
        }
      },
      "Order": {
        "type": "object",
        "required": [
          "id",
          "client_id",
          "market_id",
          "market_symbol",
          "order_type",
          "side",
          "status",
          "base_amount",
          "price",
          "target_price",
          "execution_price",
          "fee",
          "total",
          "locked_amount",
          "created_at",
          "traded_at",
          "expires_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "client_id": {
            "type": "string",
            "nullable": true,
            "description": "`null` when none was sent or the order was placed in the Talano app."
          },
          "market_id": {
            "type": "string",
            "format": "uuid"
          },
          "market_symbol": {
            "type": "string",
            "example": "MLG/TMN"
          },
          "order_type": {
            "$ref": "#/components/schemas/OrderType"
          },
          "side": {
            "$ref": "#/components/schemas/Side"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "base_amount": {
            "$ref": "#/components/schemas/Decimal"
          },
          "price": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "description": "Unit price (Toman per mg). Equals `target_price` for limit orders."
          },
          "target_price": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "nullable": true
          },
          "execution_price": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "nullable": true,
            "description": "Market price when a limit order executed."
          },
          "fee": {
            "$ref": "#/components/schemas/Decimal"
          },
          "total": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "description": "Buy: base_amount × price + fee. Sell: base_amount × price − fee."
          },
          "locked_amount": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Decimal"
              }
            ],
            "description": "Funds locked by an active limit order (Toman for buys, mg for sells)."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "traded_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        },
        "example": {
          "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
        }
      },
      "PaginatedOrderList": {
        "type": "object",
        "required": [
          "count",
          "next",
          "previous",
          "results"
        ],
        "properties": {
          "count": {
            "type": "integer",
            "example": 137
          },
          "next": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "previous": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Order"
            }
          }
        }
      },
      "ErrorItem": {
        "type": "object",
        "required": [
          "code",
          "detail",
          "attr"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Stable, English, machine-readable. Branch on this.",
            "example": "min_amount"
          },
          "detail": {
            "type": "string",
            "description": "Human message in Persian. May change at any time; do not parse."
          },
          "attr": {
            "type": "string",
            "nullable": true,
            "description": "Field or query parameter the error is about; `non_field_errors` for combinations of fields; `null` when not tied to a field."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": [
          "type",
          "errors"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "validation_error",
              "client_error",
              "server_error"
            ]
          },
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ErrorItem"
            }
          }
        }
      }
    }
  }
}
