---
updatedAt: 2026-04-26T18:58:54.000Z
agentTools:
  projectIndex: https://docs.kyan.blue/llms.txt
---

# Place limit orders

Submit one or more limit orders to the orderbook. Can be used for both options and perpetual futures.

**Authentication Options:**
- **Signature**: Include `signature` and `signature_deadline` fields in each order (both required)
- **One-click session**: Include `x-one-click` header with session hash (signature fields not required)

**Important Constraints:**
- All orders in a batch must be from the **same maker** (single maker per request)
- All orders in a batch must be for the **same market** (BTC, ETH, or ARB - determined by trading pair)
- When NOT using one-click sessions, both `signature` and `signature_deadline` are **required** fields
- **Order size**: Both options and perpetual orders use `contracts` (base contracts) as the canonical size field. For perpetuals, the legacy `amount` field (USD notional) is still accepted for backward compatibility — supply exactly one of `contracts` or `amount` (prefer `contracts`). **The notional `amount` model is deprecated and will be removed in a future release**; migrate to `contracts`
- The `taker` field must be the zero address (`0x0000000000000000000000000000000000000000`) indicating any taker can fill the order
- There is a **per-pair open order cap** — submitting orders beyond the limit results in rejection with reason `max orders per market exceeded`
- Submitting an **empty array** returns a `400` error
- EIP-712 signature field order must match exactly as shown in the examples
- **Price Increment**: Order `price` must be divisible by the minimum price increment for the base asset (see `GET /api/v1/exchange_info` → `orderConstraints.priceIncrements`). This applies to all orders including liquidation orders.
- **Size Increment**: Order size in `contracts` (canonical for both options and perpetuals; or the legacy `amount` for perpetuals) must be at least the per-asset minimum and a whole multiple of the size increment (see `GET /api/v1/exchange_info` → `orderConstraints.options.sizeIncrements` or `orderConstraints.perpetuals.sizeIncrements`). Perpetual minimum order size equals the size increment, in base contracts: BTC `0.0001`, ETH `0.001`, ARB `1`. This applies to all orders including liquidation orders.

### EIP-712 Signature Example (TypeScript)

```typescript
import { parseUnits, zeroAddress } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';

// Domain parameters for EIP-712 signature
const EIP712Domain = {
  chainId: 421614, // Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)
  name: 'Premia',
  verifyingContract: '0x...', // ClearingHouseProxy address from deployment
  version: '1'
};

// Type definition for limit orders
const UserLimitOrder = [
  { name: 'deadline', type: 'uint256' },
  { name: 'instrumentName', type: 'string' },
  { name: 'size', type: 'uint256' },
  { name: 'price', type: 'uint256' },
  { name: 'taker', type: 'address' },
  { name: 'maker', type: 'address' },
  { name: 'direction', type: 'uint8' },
  { name: 'isLiquidation', type: 'bool' },
  { name: 'isPostOnly', type: 'bool' },
  { name: 'mmp', type: 'bool' }
];

// Example order data (Options)
const optionsOrder = {
  instrument_name: 'BTC_USDC-31OCT25-130000-C',
  type: 'good_til_cancelled',
  contracts: 1.5,
  direction: 'buy',
  price: 1000.5,
  post_only: true,
  mmp: false,
  liquidation: false,
  maker: '0xYourAddress', // Your Ethereum address
  taker: null // Set to a specific address or null for any taker
};

// Example order data (Perpetuals)
const perpsOrder = {
  instrument_name: 'BTC_USDC-PERPETUAL',
  type: 'good_til_cancelled',
  contracts: 0.2,
  direction: 'buy',
  price: 45000,
  post_only: false,
  mmp: false,
  liquidation: false,
  maker: '0xYourAddress', // Your Ethereum address
  taker: null // Set to a specific address or null for any taker
};

// Calculate deadline (30 seconds from now)
const deadline = Math.floor(Date.now() / 1000) + 30;

// Setup wallet
const account = privateKeyToAccount('0xYourPrivateKey');

// Choose which order to use (options or perps)
const order = optionsOrder; // or perpsOrder for perpetuals

// Sign the typed data
const signature = await account.signTypedData({
  domain: EIP712Domain,
  types: { UserLimitOrder },
  primaryType: 'UserLimitOrder',
  message: {
    deadline,
    instrumentName: order.instrument_name,
    size: parseUnits((order.contracts ?? order.amount).toString(), 6), // Canonical `contracts`; legacy notional `amount` still accepted for perps
    price: parseUnits(order.price.toString(), 6),
    taker: order.taker ?? zeroAddress,
    maker: order.maker,
    direction: order.direction === 'buy' ? 0 : 1,
    isLiquidation: order.liquidation,
    isPostOnly: order.post_only,
    mmp: order.mmp
  }
});

// Final request payload
const requestPayload = {
  ...order,
  signature,
  signature_deadline: deadline
};
```

<!-- Python Example
```python
# Python EIP-712 Limit Order Example
from eth_account import Account
from eth_account.messages import encode_structured_data
import time

# Domain parameters for EIP-712 signature
eip712_domain = {
    "chainId": 421614,  # Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)
    "name": "Premia",
    "verifyingContract": "0x...",  # ClearingHouseProxy address from deployment
    "version": "1"
}

# Example order data (Options)
options_order = {
    "instrument_name": "BTC_USDC-31OCT25-130000-C",
    "type": "good_til_cancelled",
    "contracts": 1.5,
    "direction": "buy",
    "price": 1000.5,
    "post_only": True,
    "mmp": False,
    "liquidation": False,
    "maker": "0xYourAddress",  # Your Ethereum address
    "taker": None  # Set to a specific address or None for any taker
}

# Example order data (Perpetuals)
perps_order = {
    "instrument_name": "BTC_USDC-PERPETUAL",
    "type": "good_til_cancelled",
    "contracts": 0.2,
    "direction": "buy",
    "price": 45000,
    "post_only": False,
    "mmp": False,
    "liquidation": False,
    "maker": "0xYourAddress",  # Your Ethereum address
    "taker": None  # Set to a specific address or None for any taker
}

# Choose which order to use
order = options_order  # or perps_order for perpetuals

# Calculate deadline (30 seconds from now)
deadline = int(time.time()) + 30

# Create the typed data structure
typed_data = {
    "types": {
        "EIP712Domain": [
            {"name": "name", "type": "string"},
            {"name": "version", "type": "string"},
            {"name": "chainId", "type": "uint256"},
            {"name": "verifyingContract", "type": "address"}
        ],
        "UserLimitOrder": [
            {"name": "deadline", "type": "uint256"},
            {"name": "instrumentName", "type": "string"},
            {"name": "size", "type": "uint256"},
            {"name": "price", "type": "uint256"},
            {"name": "taker", "type": "address"},
            {"name": "maker", "type": "address"},
            {"name": "direction", "type": "uint8"},
            {"name": "isLiquidation", "type": "bool"},
            {"name": "isPostOnly", "type": "bool"},
            {"name": "mmp", "type": "bool"}
        ]
    },
    "primaryType": "UserLimitOrder",
    "domain": eip712_domain,
    "message": {
        "deadline": deadline,
        "instrumentName": order["instrument_name"],
        "size": int((order.get("contracts") or order.get("amount")) * 10**6),  # Canonical `contracts`; legacy notional `amount` still accepted for perps
        "price": int(order["price"] * 10**6),  # Convert to 6 decimals
        "taker": order["taker"] or "0x0000000000000000000000000000000000000000",
        "maker": order["maker"],
        "direction": 0 if order["direction"] == "buy" else 1,
        "isLiquidation": order["liquidation"],
        "isPostOnly": order["post_only"],
        "mmp": order["mmp"]
    }
}

# Setup wallet
private_key = "0xYourPrivateKey"
account = Account.from_key(private_key)

# Sign the typed data
encoded_data = encode_structured_data(typed_data)
signature = account.sign_message(encoded_data)

# Final request payload
request_payload = {
    **order,
    "signature": signature.signature.hex(),
    "signature_deadline": deadline
}
```
-->

<!-- Rust Example
```rust
// Rust EIP-712 Limit Order Example
use ethers::prelude::*;
use ethers::types::{Address, U256};
use serde_json::json;
use std::time::{SystemTime, UNIX_EPOCH};

#[derive(Debug, Clone, EthAbiType)]
struct UserLimitOrder {
    deadline: U256,
    instrument_name: String,
    size: U256,
    price: U256,
    taker: Address,
    maker: Address,
    direction: u8,
    is_liquidation: bool,
    is_post_only: bool,
    mmp: bool,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Domain parameters for EIP-712 signature
    let domain = eip712::EIP712Domain {
        name: Some("Premia".to_string()),
        version: Some("1".to_string()),
        chain_id: Some(U256::from(421614)), // Arbitrum Sepolia
        verifying_contract: Some("0x...".parse()?), // ClearingHouseProxy address
        salt: None,
    };
    
    // Example order data
    let order_maker = "0xYourAddress".parse::<Address>()?;
    let order_taker = Address::zero(); // Any taker
    let contracts = 1.5;
    let price = 1000.5;
    
    // Calculate deadline (30 seconds from now)
    let deadline = SystemTime::now()
        .duration_since(UNIX_EPOCH)?
        .as_secs() + 30;
    
    // Create the message to sign
    let message = UserLimitOrder {
        deadline: U256::from(deadline),
        instrument_name: "BTC_USDC-31OCT25-130000-C".to_string(),
        size: U256::from((contracts * 1e6) as u64), // Convert to 6 decimals
        price: U256::from((price * 1e6) as u64), // Convert to 6 decimals
        taker: order_taker,
        maker: order_maker,
        direction: 0, // 0 for buy, 1 for sell
        is_liquidation: false,
        is_post_only: true,
        mmp: false,
    };
    
    // Setup wallet
    let wallet = "your_private_key_hex"
        .parse::<LocalWallet>()?
        .with_chain_id(421614u64);
    
    // Sign the typed data
    let signature = wallet.sign_typed_data(&message).await?;
    
    // Final request payload
    let request_payload = json!({
        "instrument_name": "BTC_USDC-31OCT25-130000-C",
        "type": "good_til_cancelled",
        "contracts": contracts,
        "direction": "buy",
        "price": price,
        "post_only": true,
        "mmp": false,
        "liquidation": false,
        "maker": format!("{:?}", order_maker),
        "taker": null,
        "signature": format!("0x{}", signature),
        "signature_deadline": deadline,
    });
    
    println!("Request payload: {}", serde_json::to_string_pretty(&request_payload)?);
    
    Ok(())
}
```
-->


# OpenAPI definition

````json
{
  "openapi": "3.0.3",
  "info": {
    "title": "Premia V4 Public API",
    "description": "Public API for the Premia V4 platform providing traders and developers with programmatic access to options and perpetual futures trading.\nThis comprehensive API enables you to access market data, manage accounts, execute trades, and analyze portfolio risk with appropriate authentication.\n\n## Key Identifier Types\nThe API uses two primary identifier types throughout the trading system:\n- **order_id**: Unique identifier for individual limit orders. Generated as a 32-character hexadecimal string when a limit order is posted to the orderbook. Used for order management operations such as cancellation and status tracking.\n- **trade_id**: Unique identifier for executed trades. Generated as a 32-character hexadecimal string when a market order is filled against limit orders. Used for trade history tracking and settlement records.\n**Relationship**: Multiple trades can reference the same order_id when a single limit order is filled across multiple market orders (partial fills). Each trade execution generates a unique trade_id.\n\nThis document is organized following standard categories to help you integrate with the platform:\n1. Authentication/Session Management - API authentication methods and one-click trading sessions\n2. Market Data - Access real-time information about available instruments and market state\n3. Trading - Execute trades, place orders, and manage your positions \n4. Block RFQ - Request for Quote functionality for larger or custom trades\n5. Wallet - Deposit, withdraw, and transfer funds\n6. Account Management - Manage your trading account and view risk metrics\n",
    "version": "1.0.0",
    "contact": {
      "name": "Premia API Team",
      "url": "https://premia.io"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://premia.io/license"
    }
  },
  "servers": [
    {
      "url": "https://sandbox.kyan.sh",
      "description": "Sandbox server (REST API)"
    },
    {
      "url": "https://staging.kyan.sh",
      "description": "Staging server (REST API)"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "tags": [
    {
      "name": "Trading",
      "description": "Endpoints for executing trades, placing orders, and managing positions"
    }
  ],
  "externalDocs": {
    "description": "Complete API Documentation",
    "url": "https://docs.kyan.blue/reference"
  },
  "paths": {
    "/limit": {
      "post": {
        "tags": [
          "Trading"
        ],
        "summary": "Place limit orders",
        "description": "Submit one or more limit orders to the orderbook. Can be used for both options and perpetual futures.\n\n**Authentication Options:**\n- **Signature**: Include `signature` and `signature_deadline` fields in each order (both required)\n- **One-click session**: Include `x-one-click` header with session hash (signature fields not required)\n\n**Important Constraints:**\n- All orders in a batch must be from the **same maker** (single maker per request)\n- All orders in a batch must be for the **same market** (BTC, ETH, or ARB - determined by trading pair)\n- When NOT using one-click sessions, both `signature` and `signature_deadline` are **required** fields\n- **Order size**: Both options and perpetual orders use `contracts` (base contracts) as the canonical size field. For perpetuals, the legacy `amount` field (USD notional) is still accepted for backward compatibility — supply exactly one of `contracts` or `amount` (prefer `contracts`). **The notional `amount` model is deprecated and will be removed in a future release**; migrate to `contracts`\n- The `taker` field must be the zero address (`0x0000000000000000000000000000000000000000`) indicating any taker can fill the order\n- There is a **per-pair open order cap** — submitting orders beyond the limit results in rejection with reason `max orders per market exceeded`\n- Submitting an **empty array** returns a `400` error\n- EIP-712 signature field order must match exactly as shown in the examples\n- **Price Increment**: Order `price` must be divisible by the minimum price increment for the base asset (see `GET /api/v1/exchange_info` → `orderConstraints.priceIncrements`). This applies to all orders including liquidation orders.\n- **Size Increment**: Order size in `contracts` (canonical for both options and perpetuals; or the legacy `amount` for perpetuals) must be at least the per-asset minimum and a whole multiple of the size increment (see `GET /api/v1/exchange_info` → `orderConstraints.options.sizeIncrements` or `orderConstraints.perpetuals.sizeIncrements`). Perpetual minimum order size equals the size increment, in base contracts: BTC `0.0001`, ETH `0.001`, ARB `1`. This applies to all orders including liquidation orders.\n\n### EIP-712 Signature Example (TypeScript)\n\n```typescript\nimport { parseUnits, zeroAddress } from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\n\n// Domain parameters for EIP-712 signature\nconst EIP712Domain = {\n  chainId: 421614, // Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)\n  name: 'Premia',\n  verifyingContract: '0x...', // ClearingHouseProxy address from deployment\n  version: '1'\n};\n\n// Type definition for limit orders\nconst UserLimitOrder = [\n  { name: 'deadline', type: 'uint256' },\n  { name: 'instrumentName', type: 'string' },\n  { name: 'size', type: 'uint256' },\n  { name: 'price', type: 'uint256' },\n  { name: 'taker', type: 'address' },\n  { name: 'maker', type: 'address' },\n  { name: 'direction', type: 'uint8' },\n  { name: 'isLiquidation', type: 'bool' },\n  { name: 'isPostOnly', type: 'bool' },\n  { name: 'mmp', type: 'bool' }\n];\n\n// Example order data (Options)\nconst optionsOrder = {\n  instrument_name: 'BTC_USDC-31OCT25-130000-C',\n  type: 'good_til_cancelled',\n  contracts: 1.5,\n  direction: 'buy',\n  price: 1000.5,\n  post_only: true,\n  mmp: false,\n  liquidation: false,\n  maker: '0xYourAddress', // Your Ethereum address\n  taker: null // Set to a specific address or null for any taker\n};\n\n// Example order data (Perpetuals)\nconst perpsOrder = {\n  instrument_name: 'BTC_USDC-PERPETUAL',\n  type: 'good_til_cancelled',\n  contracts: 0.2,\n  direction: 'buy',\n  price: 45000,\n  post_only: false,\n  mmp: false,\n  liquidation: false,\n  maker: '0xYourAddress', // Your Ethereum address\n  taker: null // Set to a specific address or null for any taker\n};\n\n// Calculate deadline (30 seconds from now)\nconst deadline = Math.floor(Date.now() / 1000) + 30;\n\n// Setup wallet\nconst account = privateKeyToAccount('0xYourPrivateKey');\n\n// Choose which order to use (options or perps)\nconst order = optionsOrder; // or perpsOrder for perpetuals\n\n// Sign the typed data\nconst signature = await account.signTypedData({\n  domain: EIP712Domain,\n  types: { UserLimitOrder },\n  primaryType: 'UserLimitOrder',\n  message: {\n    deadline,\n    instrumentName: order.instrument_name,\n    size: parseUnits((order.contracts ?? order.amount).toString(), 6), // Canonical `contracts`; legacy notional `amount` still accepted for perps\n    price: parseUnits(order.price.toString(), 6),\n    taker: order.taker ?? zeroAddress,\n    maker: order.maker,\n    direction: order.direction === 'buy' ? 0 : 1,\n    isLiquidation: order.liquidation,\n    isPostOnly: order.post_only,\n    mmp: order.mmp\n  }\n});\n\n// Final request payload\nconst requestPayload = {\n  ...order,\n  signature,\n  signature_deadline: deadline\n};\n```\n\n<!-- Python Example\n```python\n# Python EIP-712 Limit Order Example\nfrom eth_account import Account\nfrom eth_account.messages import encode_structured_data\nimport time\n\n# Domain parameters for EIP-712 signature\neip712_domain = {\n    \"chainId\": 421614,  # Arbitrum Sepolia (use 42161 for Arbitrum One mainnet)\n    \"name\": \"Premia\",\n    \"verifyingContract\": \"0x...\",  # ClearingHouseProxy address from deployment\n    \"version\": \"1\"\n}\n\n# Example order data (Options)\noptions_order = {\n    \"instrument_name\": \"BTC_USDC-31OCT25-130000-C\",\n    \"type\": \"good_til_cancelled\",\n    \"contracts\": 1.5,\n    \"direction\": \"buy\",\n    \"price\": 1000.5,\n    \"post_only\": True,\n    \"mmp\": False,\n    \"liquidation\": False,\n    \"maker\": \"0xYourAddress\",  # Your Ethereum address\n    \"taker\": None  # Set to a specific address or None for any taker\n}\n\n# Example order data (Perpetuals)\nperps_order = {\n    \"instrument_name\": \"BTC_USDC-PERPETUAL\",\n    \"type\": \"good_til_cancelled\",\n    \"contracts\": 0.2,\n    \"direction\": \"buy\",\n    \"price\": 45000,\n    \"post_only\": False,\n    \"mmp\": False,\n    \"liquidation\": False,\n    \"maker\": \"0xYourAddress\",  # Your Ethereum address\n    \"taker\": None  # Set to a specific address or None for any taker\n}\n\n# Choose which order to use\norder = options_order  # or perps_order for perpetuals\n\n# Calculate deadline (30 seconds from now)\ndeadline = int(time.time()) + 30\n\n# Create the typed data structure\ntyped_data = {\n    \"types\": {\n        \"EIP712Domain\": [\n            {\"name\": \"name\", \"type\": \"string\"},\n            {\"name\": \"version\", \"type\": \"string\"},\n            {\"name\": \"chainId\", \"type\": \"uint256\"},\n            {\"name\": \"verifyingContract\", \"type\": \"address\"}\n        ],\n        \"UserLimitOrder\": [\n            {\"name\": \"deadline\", \"type\": \"uint256\"},\n            {\"name\": \"instrumentName\", \"type\": \"string\"},\n            {\"name\": \"size\", \"type\": \"uint256\"},\n            {\"name\": \"price\", \"type\": \"uint256\"},\n            {\"name\": \"taker\", \"type\": \"address\"},\n            {\"name\": \"maker\", \"type\": \"address\"},\n            {\"name\": \"direction\", \"type\": \"uint8\"},\n            {\"name\": \"isLiquidation\", \"type\": \"bool\"},\n            {\"name\": \"isPostOnly\", \"type\": \"bool\"},\n            {\"name\": \"mmp\", \"type\": \"bool\"}\n        ]\n    },\n    \"primaryType\": \"UserLimitOrder\",\n    \"domain\": eip712_domain,\n    \"message\": {\n        \"deadline\": deadline,\n        \"instrumentName\": order[\"instrument_name\"],\n        \"size\": int((order.get(\"contracts\") or order.get(\"amount\")) * 10**6),  # Canonical `contracts`; legacy notional `amount` still accepted for perps\n        \"price\": int(order[\"price\"] * 10**6),  # Convert to 6 decimals\n        \"taker\": order[\"taker\"] or \"0x0000000000000000000000000000000000000000\",\n        \"maker\": order[\"maker\"],\n        \"direction\": 0 if order[\"direction\"] == \"buy\" else 1,\n        \"isLiquidation\": order[\"liquidation\"],\n        \"isPostOnly\": order[\"post_only\"],\n        \"mmp\": order[\"mmp\"]\n    }\n}\n\n# Setup wallet\nprivate_key = \"0xYourPrivateKey\"\naccount = Account.from_key(private_key)\n\n# Sign the typed data\nencoded_data = encode_structured_data(typed_data)\nsignature = account.sign_message(encoded_data)\n\n# Final request payload\nrequest_payload = {\n    **order,\n    \"signature\": signature.signature.hex(),\n    \"signature_deadline\": deadline\n}\n```\n-->\n\n<!-- Rust Example\n```rust\n// Rust EIP-712 Limit Order Example\nuse ethers::prelude::*;\nuse ethers::types::{Address, U256};\nuse serde_json::json;\nuse std::time::{SystemTime, UNIX_EPOCH};\n\n#[derive(Debug, Clone, EthAbiType)]\nstruct UserLimitOrder {\n    deadline: U256,\n    instrument_name: String,\n    size: U256,\n    price: U256,\n    taker: Address,\n    maker: Address,\n    direction: u8,\n    is_liquidation: bool,\n    is_post_only: bool,\n    mmp: bool,\n}\n\n#[tokio::main]\nasync fn main() -> Result<(), Box<dyn std::error::Error>> {\n    // Domain parameters for EIP-712 signature\n    let domain = eip712::EIP712Domain {\n        name: Some(\"Premia\".to_string()),\n        version: Some(\"1\".to_string()),\n        chain_id: Some(U256::from(421614)), // Arbitrum Sepolia\n        verifying_contract: Some(\"0x...\".parse()?), // ClearingHouseProxy address\n        salt: None,\n    };\n    \n    // Example order data\n    let order_maker = \"0xYourAddress\".parse::<Address>()?;\n    let order_taker = Address::zero(); // Any taker\n    let contracts = 1.5;\n    let price = 1000.5;\n    \n    // Calculate deadline (30 seconds from now)\n    let deadline = SystemTime::now()\n        .duration_since(UNIX_EPOCH)?\n        .as_secs() + 30;\n    \n    // Create the message to sign\n    let message = UserLimitOrder {\n        deadline: U256::from(deadline),\n        instrument_name: \"BTC_USDC-31OCT25-130000-C\".to_string(),\n        size: U256::from((contracts * 1e6) as u64), // Convert to 6 decimals\n        price: U256::from((price * 1e6) as u64), // Convert to 6 decimals\n        taker: order_taker,\n        maker: order_maker,\n        direction: 0, // 0 for buy, 1 for sell\n        is_liquidation: false,\n        is_post_only: true,\n        mmp: false,\n    };\n    \n    // Setup wallet\n    let wallet = \"your_private_key_hex\"\n        .parse::<LocalWallet>()?\n        .with_chain_id(421614u64);\n    \n    // Sign the typed data\n    let signature = wallet.sign_typed_data(&message).await?;\n    \n    // Final request payload\n    let request_payload = json!({\n        \"instrument_name\": \"BTC_USDC-31OCT25-130000-C\",\n        \"type\": \"good_til_cancelled\",\n        \"contracts\": contracts,\n        \"direction\": \"buy\",\n        \"price\": price,\n        \"post_only\": true,\n        \"mmp\": false,\n        \"liquidation\": false,\n        \"maker\": format!(\"{:?}\", order_maker),\n        \"taker\": null,\n        \"signature\": format!(\"0x{}\", signature),\n        \"signature_deadline\": deadline,\n    });\n    \n    println!(\"Request payload: {}\", serde_json::to_string_pretty(&request_payload)?);\n    \n    Ok(())\n}\n```\n-->\n",
        "operationId": "postLimitOrders",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/PostLimitOrderRequest"
                },
                "minItems": 1,
                "maxItems": 1000
              },
              "examples": {
                "validBatch": {
                  "summary": "Valid batch - same maker, same market",
                  "value": [
                    {
                      "instrument_name": "BTC_USDC-31OCT25-130000-C",
                      "type": "good_til_cancelled",
                      "contracts": 1.5,
                      "direction": "buy",
                      "price": 1000.5,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x1234567890123456789012345678901234567890",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    },
                    {
                      "instrument_name": "BTC_USDC-31OCT25-108000-C",
                      "type": "good_til_cancelled",
                      "contracts": 2,
                      "direction": "sell",
                      "price": 950,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x1234567890123456789012345678901234567890",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    }
                  ]
                },
                "invalidMultipleMakers": {
                  "summary": "Invalid - multiple makers",
                  "value": [
                    {
                      "instrument_name": "BTC_USDC-31OCT25-130000-C",
                      "type": "good_til_cancelled",
                      "contracts": 1.5,
                      "direction": "buy",
                      "price": 1000.5,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x1234567890123456789012345678901234567890",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    },
                    {
                      "instrument_name": "BTC_USDC-31OCT25-108000-C",
                      "type": "good_til_cancelled",
                      "contracts": 2,
                      "direction": "sell",
                      "price": 950,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x0987654321098765432109876543210987654321",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    }
                  ]
                },
                "invalidMultipleMarkets": {
                  "summary": "Invalid - multiple markets",
                  "value": [
                    {
                      "instrument_name": "BTC_USDC-31OCT25-130000-C",
                      "type": "good_til_cancelled",
                      "contracts": 1.5,
                      "direction": "buy",
                      "price": 1000.5,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x1234567890123456789012345678901234567890",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    },
                    {
                      "instrument_name": "ETH_USDC-31OCT25-3000-C",
                      "type": "good_til_cancelled",
                      "contracts": 2,
                      "direction": "sell",
                      "price": 100,
                      "post_only": true,
                      "mmp": false,
                      "liquidation": false,
                      "maker": "0x1234567890123456789012345678901234567890",
                      "signature": "0x...",
                      "signature_deadline": 1704067230
                    }
                  ]
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Request successfully processed. This response is returned even if all orders are rejected due to business rule violations.\n\n**Important**: A 200 status indicates the HTTP request was valid and processed. Individual orders may still be rejected for business logic reasons (multiple makers, market rules, etc.). Check the `rejected` array for details.\n\nThe response contains two arrays:\n- `posted`: Orders successfully placed on the orderbook\n- `rejected`: Orders rejected due to validation failures or business rule violations\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "posted",
                    "rejected"
                  ],
                  "properties": {
                    "posted": {
                      "type": "array",
                      "description": "Orders that were successfully posted to the orderbook",
                      "items": {
                        "$ref": "#/components/schemas/StoredLimitOrder"
                      }
                    },
                    "rejected": {
                      "type": "array",
                      "description": "Orders that were rejected due to validation failures or business rule violations",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/PostLimitOrderRequest"
                          },
                          {
                            "type": "object",
                            "required": [
                              "order_state",
                              "reason"
                            ],
                            "properties": {
                              "order_state": {
                                "type": "string",
                                "enum": [
                                  "rejected"
                                ]
                              },
                              "reason": {
                                "type": "string",
                                "description": "Reason for rejection (business rule violation or validation failure)",
                                "enum": [
                                  "invalid request",
                                  "invalid instrument name",
                                  "self crossing orders submitted",
                                  "wash trading violation",
                                  "post only violation",
                                  "submitted batch must have a single maker",
                                  "multiple markets provided",
                                  "max orders per market exceeded",
                                  "mmp protection required but not active or frozen",
                                  "cannot mix liquidation and non-liquidation orders in the same batch",
                                  "order size below minimum requirement",
                                  "order size not divisible by minimum increment",
                                  "order price not divisible by minimum increment",
                                  "margin account is under liquidation"
                                ]
                              },
                              "error": {
                                "type": "array",
                                "description": "Detailed validation errors (present when reason is 'invalid request')",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "instancePath": {
                                      "type": "string",
                                      "description": "Path to the invalid field"
                                    },
                                    "schemaPath": {
                                      "type": "string",
                                      "description": "JSON schema path"
                                    },
                                    "keyword": {
                                      "type": "string",
                                      "description": "Validation keyword that failed"
                                    },
                                    "params": {
                                      "type": "object",
                                      "description": "Additional parameters"
                                    },
                                    "message": {
                                      "type": "string",
                                      "description": "Human-readable error message"
                                    }
                                  }
                                }
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                },
                "examples": {
                  "successWithAllAccepted": {
                    "summary": "All orders accepted and posted",
                    "value": {
                      "posted": [
                        {
                          "order_id": "0xabc123...",
                          "instrument_name": "BTC_USDC-31OCT25-130000-C",
                          "type": "good_til_cancelled",
                          "contracts": 1.5,
                          "direction": "buy",
                          "price": 1000.5,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "taker": "0x0000000000000000000000000000000000000000",
                          "filled_amount": 0,
                          "order_state": "open",
                          "creation_timestamp": 1704067230,
                          "chain_id": 42161,
                          "user_id": ""
                        },
                        {
                          "order_id": "0xdef456...",
                          "instrument_name": "BTC_USDC-31OCT25-108000-C",
                          "type": "good_til_cancelled",
                          "contracts": 2,
                          "direction": "sell",
                          "price": 950,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "taker": "0x0000000000000000000000000000000000000000",
                          "filled_amount": 0,
                          "order_state": "open",
                          "creation_timestamp": 1704067230,
                          "chain_id": 42161,
                          "user_id": ""
                        }
                      ],
                      "rejected": []
                    }
                  },
                  "successWithMixedResults": {
                    "summary": "Partial success with some rejections",
                    "value": {
                      "posted": [
                        {
                          "order_id": "0xabc123...",
                          "instrument_name": "BTC_USDC-31OCT25-130000-C",
                          "type": "good_til_cancelled",
                          "contracts": 1.5,
                          "direction": "buy",
                          "price": 1000.5,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "taker": "0x0000000000000000000000000000000000000000",
                          "filled_amount": 0,
                          "order_state": "open",
                          "creation_timestamp": 1704067230,
                          "chain_id": 42161,
                          "user_id": ""
                        }
                      ],
                      "rejected": [
                        {
                          "instrument_name": "BTC_USDC-31OCT25-108000-C",
                          "type": "good_til_cancelled",
                          "contracts": 0.5,
                          "direction": "sell",
                          "price": 950,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "order_state": "rejected",
                          "reason": "order size below minimum requirement"
                        }
                      ]
                    }
                  },
                  "successWithAllRejections": {
                    "summary": "All orders rejected due to multiple makers",
                    "value": {
                      "posted": [],
                      "rejected": [
                        {
                          "instrument_name": "BTC_USDC-31OCT25-130000-C",
                          "type": "good_til_cancelled",
                          "contracts": 1.5,
                          "direction": "buy",
                          "price": 1000.5,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "order_state": "rejected",
                          "reason": "submitted batch must have a single maker"
                        },
                        {
                          "instrument_name": "BTC_USDC-31OCT25-108000-C",
                          "type": "good_til_cancelled",
                          "contracts": 2,
                          "direction": "sell",
                          "price": 950,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x0987654321098765432109876543210987654321",
                          "order_state": "rejected",
                          "reason": "submitted batch must have a single maker"
                        }
                      ]
                    }
                  },
                  "successWithMultipleMarketsRejection": {
                    "summary": "Orders rejected due to multiple markets",
                    "value": {
                      "posted": [],
                      "rejected": [
                        {
                          "instrument_name": "BTC_USDC-31OCT25-130000-C",
                          "type": "good_til_cancelled",
                          "contracts": 1.5,
                          "direction": "buy",
                          "price": 1000.5,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "order_state": "rejected",
                          "reason": "multiple markets provided"
                        },
                        {
                          "instrument_name": "ETH_USDC-31OCT25-3000-C",
                          "type": "good_til_cancelled",
                          "contracts": 2,
                          "direction": "sell",
                          "price": 100,
                          "post_only": true,
                          "mmp": false,
                          "liquidation": false,
                          "maker": "0x1234567890123456789012345678901234567890",
                          "order_state": "rejected",
                          "reason": "multiple markets provided"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardError"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - invalid signature, missing API key, or one-click session address mismatch (ONE_CT_USER_MISMATCH)\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StandardError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-apikey",
        "description": "API key for authentication. Generate and manage your own at https://app.kyan.blue/portfolio/api"
      }
    },
    "schemas": {
      "Address": {
        "type": "string",
        "pattern": "^0x[a-fA-F0-9]{40}$",
        "description": "Ethereum address in hexadecimal format",
        "example": "0x9a2f0C371820e8BE3D64efb3E814808F231880ff"
      },
      "OptionLimitOrder": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PostOptionsLimitRequest"
          },
          {
            "type": "object",
            "properties": {
              "order_id": {
                "type": "string",
                "description": "Order ID for this limit order",
                "pattern": "^[a-fA-F0-9]{32}$",
                "example": "1234567890abcdef1234567890abcdef"
              },
              "order_state": {
                "type": "string",
                "enum": [
                  "open",
                  "filled",
                  "rejected"
                ],
                "description": "Order state"
              },
              "filled_amount": {
                "type": "number",
                "format": "double",
                "description": "Confirmed filled size (settlement-confirmed fills only), in contracts for options. Orders currently being matched (inflight) show 0 until the fill is confirmed.",
                "example": 0.5
              },
              "filled_contracts": {
                "type": "number",
                "format": "double",
                "description": "Confirmed filled size in base contracts (canonical). For options this equals `filled_amount`.",
                "example": 0.5
              },
              "iv": {
                "type": "number",
                "format": "double",
                "description": "Implied volatility",
                "example": 0.5
              },
              "creation_timestamp": {
                "type": "integer",
                "format": "int64",
                "description": "Creation timestamp in Unix seconds",
                "example": 1704067200
              },
              "chain_id": {
                "type": "integer",
                "format": "int32",
                "description": "Chain ID",
                "example": 42161
              }
            },
            "required": [
              "order_id",
              "order_state",
              "filled_amount",
              "creation_timestamp",
              "chain_id"
            ]
          }
        ]
      },
      "PerpLimitOrder": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PostPerpsLimitRequest"
          },
          {
            "type": "object",
            "properties": {
              "order_id": {
                "type": "string",
                "pattern": "^[a-fA-F0-9]{32}$",
                "description": "Order ID for this perpetual limit order",
                "example": "1234567890abcdef1234567890abcdef"
              },
              "order_state": {
                "type": "string",
                "enum": [
                  "open",
                  "filled",
                  "rejected"
                ],
                "description": "Order state"
              },
              "filled_amount": {
                "type": "number",
                "format": "double",
                "description": "Confirmed filled size (settlement-confirmed fills only), as USD notional for perpetuals. Orders currently being matched (inflight) show 0 until the fill is confirmed.",
                "example": 5000.05
              },
              "filled_contracts": {
                "type": "number",
                "format": "double",
                "description": "Confirmed filled size in base contracts (canonical) — the fill-side analog of `contracts`.",
                "example": 0.1
              },
              "creation_timestamp": {
                "type": "integer",
                "format": "int64",
                "description": "Creation timestamp in Unix seconds",
                "example": 1704067200
              },
              "chain_id": {
                "type": "integer",
                "format": "int32",
                "description": "Chain ID",
                "example": 42161
              }
            },
            "required": [
              "order_id",
              "order_state",
              "filled_amount",
              "creation_timestamp",
              "chain_id"
            ]
          }
        ]
      },
      "PostLimitOrderRequest": {
        "oneOf": [
          {
            "title": "Options",
            "$ref": "#/components/schemas/PostOptionsLimitRequest"
          },
          {
            "title": "Perpetual",
            "$ref": "#/components/schemas/PostPerpsLimitRequest"
          }
        ],
        "x-readme": {
          "explorer-enabled": true
        },
        "description": "Request to post a limit order, either for options or perpetuals"
      },
      "PostOptionsLimitRequest": {
        "type": "object",
        "title": "Options Limit Order",
        "properties": {
          "instrument_name": {
            "type": "string",
            "pattern": "^[A-Z]+_[A-Z]+-[0-9]{2}[A-Z]{3}[0-9]{2}-[0-9]+-[CP]$",
            "description": "Instrument name in the format `{base}_{quote}-{maturity}-{strike}-{type}`",
            "example": "BTC_USDC-31OCT25-130000-C"
          },
          "type": {
            "type": "string",
            "enum": [
              "good_til_cancelled",
              "good_til_day"
            ],
            "description": "Order type"
          },
          "contracts": {
            "type": "number",
            "format": "double",
            "minimum": 0.000001,
            "multipleOf": 0.000001,
            "description": "Number of option contracts",
            "example": 1.5
          },
          "direction": {
            "type": "string",
            "enum": [
              "buy",
              "sell"
            ],
            "description": "Order direction"
          },
          "price": {
            "type": "number",
            "format": "double",
            "minimum": 0.000001,
            "multipleOf": 0.000001,
            "description": "Limit price",
            "example": 1000.5
          },
          "post_only": {
            "type": "boolean",
            "description": "If true, ensures the order will only be added to the order book and not match against existing orders. Orders that would immediately match will be rejected."
          },
          "mmp": {
            "type": "boolean",
            "description": "Opts this order into Market Maker Protection (MMP). When `true`, this order is tracked against MMP risk thresholds and will be automatically cancelled if MMP triggers. When MMP is frozen (after a trigger), new orders with `mmp: true` are rejected while orders with `mmp: false` can still be placed. The `mmp` value is part of the EIP-712 signature and cannot be changed after signing. See `POST /mmp_config` for full MMP documentation."
          },
          "liquidation": {
            "type": "boolean",
            "description": "Internal field used for liquidation orders. Regular traders should set this to false."
          },
          "maker": {
            "$ref": "#/components/schemas/Address"
          },
          "taker": {
            "$ref": "#/components/schemas/Address",
            "description": "Must be the zero address (0x0000000000000000000000000000000000000000), indicating any taker can fill the order",
            "pattern": "^0x0{40}$"
          },
          "signature": {
            "type": "string",
            "pattern": "^0x[a-fA-F0-9]{130}$",
            "description": "EIP-712 signature (required when not using x-one-click session)"
          },
          "signature_deadline": {
            "type": "integer",
            "format": "int64",
            "minimum": 1704067200,
            "maximum": 2019686400,
            "description": "Signature deadline in Unix seconds (required when not using x-one-click session)"
          },
          "user_id": {
            "type": "string",
            "maxLength": 36,
            "description": "Optional user identifier for tracking and analytics purposes"
          }
        },
        "required": [
          "instrument_name",
          "type",
          "contracts",
          "direction",
          "price",
          "post_only",
          "mmp",
          "liquidation",
          "maker"
        ]
      },
      "PostPerpsLimitRequest": {
        "title": "Perpetual Limit Order",
        "properties": {
          "instrument_name": {
            "type": "string",
            "pattern": "^[A-Z]+_[A-Z]+-PERPETUAL$",
            "description": "Instrument name in the format `{base}_{quote}-PERPETUAL`",
            "example": "BTC_USDC-PERPETUAL"
          },
          "type": {
            "type": "string",
            "enum": [
              "good_til_cancelled",
              "good_til_day"
            ],
            "description": "Order type"
          },
          "contracts": {
            "type": "number",
            "format": "double",
            "minimum": 0.000001,
            "multipleOf": 0.000001,
            "description": "Order size in base contracts (canonical). Perpetual order size is denominated in base contracts of the underlying asset — the same unit used for options. Supply exactly one of `contracts` or `amount`.",
            "example": 0.2
          },
          "amount": {
            "type": "number",
            "format": "double",
            "minimum": 0.000001,
            "multipleOf": 0.000001,
            "description": "Legacy order size in USD notional. **Deprecated and will be removed in a future release** — the notional model is being replaced by `contracts` (base contracts). Accepted only for backward compatibility; migrate to `contracts`. When supplied instead of `contracts`, the notional is converted to base contracts at the order `price`. Supply exactly one of `contracts` or `amount`.",
            "example": 10000
          },
          "direction": {
            "type": "string",
            "enum": [
              "buy",
              "sell"
            ],
            "description": "Order direction"
          },
          "price": {
            "type": "number",
            "format": "double",
            "minimum": 0.000001,
            "multipleOf": 0.000001,
            "description": "Limit price",
            "example": 50000.5
          },
          "post_only": {
            "type": "boolean",
            "description": "If true, ensures the order will only be added to the order book and not match against existing orders. Orders that would immediately match will be rejected."
          },
          "mmp": {
            "type": "boolean",
            "description": "Opts this order into Market Maker Protection (MMP). When `true`, this order is tracked against MMP risk thresholds and will be automatically cancelled if MMP triggers. When MMP is frozen (after a trigger), new orders with `mmp: true` are rejected while orders with `mmp: false` can still be placed. The `mmp` value is part of the EIP-712 signature and cannot be changed after signing. See `POST /mmp_config` for full MMP documentation."
          },
          "liquidation": {
            "type": "boolean",
            "description": "Internal field used for liquidation orders. Regular traders should set this to false."
          },
          "maker": {
            "$ref": "#/components/schemas/Address"
          },
          "taker": {
            "$ref": "#/components/schemas/Address",
            "description": "Must be the zero address (0x0000000000000000000000000000000000000000), indicating any taker can fill the order",
            "pattern": "^0x0{40}$"
          },
          "signature": {
            "type": "string",
            "pattern": "^0x[a-fA-F0-9]{130}$",
            "description": "EIP-712 signature (required when not using x-one-click session)"
          },
          "signature_deadline": {
            "type": "integer",
            "format": "int64",
            "minimum": 1704067200,
            "maximum": 2019686400,
            "description": "Signature deadline in Unix seconds (required when not using x-one-click session)"
          },
          "user_id": {
            "type": "string",
            "maxLength": 36,
            "description": "Optional user identifier for tracking and analytics purposes"
          }
        },
        "required": [
          "instrument_name",
          "type",
          "direction",
          "price",
          "post_only",
          "mmp",
          "liquidation",
          "maker"
        ],
        "oneOf": [
          {
            "required": [
              "contracts"
            ]
          },
          {
            "required": [
              "amount"
            ]
          }
        ],
        "x-readme": {
          "explorer-enabled": true
        }
      },
      "StoredLimitOrder": {
        "oneOf": [
          {
            "title": "Options Limit Order",
            "$ref": "#/components/schemas/OptionLimitOrder"
          },
          {
            "title": "Perpetual Limit Order",
            "$ref": "#/components/schemas/PerpLimitOrder"
          }
        ],
        "description": "A stored limit order, either for options or perpetuals",
        "x-readme": {
          "explorer-enabled": true
        }
      },
      "StandardError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error code or message. Common error codes include:\n- `MIN_INCREMENT_PRICE_VIOLATION` - Order price is not divisible by the minimum price increment for the base asset\n- `MIN_SIZE_VIOLATION` - Order size is below the minimum requirement\n- `MIN_INCREMENT_SIZE_VIOLATION` - Order size is not divisible by the minimum size increment\n- `MAX_SLIPPAGE_VIOLATION` - Order price exceeds the maximum allowed slippage from fair value\n- `SIGNATURE_VALIDATION_ERROR` - Invalid or expired signature\n- `SIGNATURE_DEADLINE_INVALID` - Signature deadline is missing, expired, or outside the acceptable window. Response includes `serverTime`, `minTimestamp`, `maxTimestamp`, and `givenTimestamp` fields to help diagnose clock skew issues.\n- `SIGNATURE_DEADLINE_STALE` - Signature deadline is not strictly greater than the last accepted deadline for this maker (replay protection)\n- `ONE_CT_USER_MISMATCH` - One-click trading session was created by a different address than the maker/taker in the request\n- `VALUE_INVALID` - A request field has an invalid value (e.g., timeout out of range, or a legacy perpetual `amount` order submitted without the `price` needed to convert notional to contracts)\n- `INVALID_INSTRUMENT_NAME` - Instrument name format is invalid or instrument not found\n- `RFQ_REQUEST_ALREADY_EXISTS` - An RFQ request with the same identifier already exists (HTTP 409). The response data includes the conflicting `order_id`.\n- `RFQ_RESPONSE_ALREADY_EXISTS` - An RFQ response with the same identifier already exists (HTTP 409). The response data includes the conflicting `response_id`.\n- `RFQ_FILL_TAKER_RISK_FAILED` - Filling the RFQ would breach the taker's margin/risk limits (HTTP 400)\n- `RFQ_FILL_MAKER_RISK_FAILED` - Filling the RFQ would breach the maker's margin/risk limits (HTTP 400)\n",
            "example": "MIN_INCREMENT_PRICE_VIOLATION"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error description with details",
            "example": "Min price increment requirement violated for ETH_USDC-PERPETUAL. Price: 2500.15, Must be divisible by: 0.1"
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
````