For the complete documentation index, see llms.txt. This page is also available as Markdown.

POST /trade

Submits one signed action.

curl -sS -X POST "$API_URL/trade" \
  -H 'content-type: application/json' \
  -H 'x-trace-id: client-trace-001' \
  -d '{
    "action": {
      "type": "order",
      "market_id": "0",
      "side": "bid",
      "order_type": "limit",
      "tif": "gtc",
      "price": "1000.00",
      "quantity": "0.0025",
      "cloid": "0x11111111111111111111111111111111"
    },
    "nonce": "1760000000000",
    "expires_after_ms": "1760000005000",
    "signature": "0x..."
  }'

Request envelope fields:

Field
Required
Description

action

yes

Action object. Public top-level types: order, cancel, cancelAll, modify, batch, transfer, activateFor, withdraw, settle, repay, approveAgent, revokeAgent, and setAccountMultisig (see Account Multisig). Internal operator/accounting writes are not part of this public contract. See the full public list below.

nonce

yes

Decimal string u64 Unix millisecond timestamp nonce. Use current Date.now()/Unix ms; if sending multiple requests in the same millisecond for the same signer, increment locally so each signed nonce is unique and monotonically nondecreasing.

agent_epoch

no

Decimal string u64; required only for agent-signed requests. Omit for owner-signed requests. Mutually exclusive with auth_account — sending both is rejected with AgentEpochNotAllowedWithAuthAccount.

expires_after_ms

no

Decimal string u64 Unix milliseconds. An envelope already past expires_after_ms at the gateway clock is fast-failed with submission_status: "rejected", error.code: "ExpiredTx" (before the node hop); execution also enforces expiry against the committed block timestamp.

auth_scheme

no

"legacy" (default) or "eip712". Public transfer, activateFor, withdraw, settle, repay, approveAgent, revokeAgent, and setAccountMultisig require "eip712"; public trading actions (order/cancel/cancelAll/modify/batch) require "legacy". Every account-auth request requires it too (AccountAuthRequiresEip712). See EIP-712 signing.

signature

yes unless account-auth

0x-prefixed 65-byte recoverable secp256k1 signature. Legacy v1, or — when auth_scheme="eip712" — an EIP-712 v4 single signature. Omitted on an account multisig request, which carries signatures instead. Mutually exclusive with signatures.

signatures

no

Array of 0x-prefixed 65-byte signatures. Sent with auth_account and policy_epoch to submit an account multisig quorum request. Without auth_account it is an internal multisig submission, which is not part of this public contract and is rejected for public actions with SignaturesNotAllowedForAction. Mutually exclusive with signature.

auth_account

no

Owner address the quorum acts for, on an account multisig request. Must be sent with policy_epoch and auth_scheme:"eip712", and only for the actions a quorum can sign.

policy_epoch

no

Decimal string u64 from the accountMultisig read; required whenever auth_account is present. A stale value is rejected with AccountMultisigEpochMismatch.

The envelope is strict: exactly one of signature or signatures must be present (neither or both → AmbiguousAuthFields), and any field not in the table above is rejected as InvalidJson. Numeric fields (nonce, agent_epoch, expires_after_ms) accept a decimal string or an unsigned JSON integer, with the string form preferred above 2^53. Only action, nonce, agent_epoch, and expires_after_ms are folded into the signed payload — plus auth_account and policy_epoch on an account multisig request, which are signed by every approval. auth_scheme, signature, and signatures are transport fields that select and carry the proof (see Transaction Signing).

Public actions are single-signature, except the eight an account multisig covers (transfer / activateFor / withdraw / settle / repay / approveAgent / revokeAgent / setAccountMultisig) when one is Active. Trading actions can never be quorum-signed. For a public action, signatures without auth_account is rejected with SignaturesNotAllowedForAction. The transaction authority used for nonce/rate-limit and txStatusByCloid is the recovered signer — except on a quorum request, where it is the auth_account the quorum acts for, not any of the signing keys.

Nonce validation is authority-scoped. Execution accepts nonces within the committed block timestamp window (block_timestamp_ms - 2 days through block_timestamp_ms + 1 day), rejects duplicates, and retains the latest 100 consumed nonces per authority. When the retained window is full, a new nonce must be greater than the current minimum retained nonce.

order

Places one order.

Field
Required
Values

type

yes

"order"

market_id

yes

Decimal string market id.

side

yes

"bid" or "ask"; "buy" and "sell" are also accepted aliases.

order_type

yes

"limit" or "market".

tif

yes

"gtc", "ioc", "fok", or "alo".

price

yes

Human decimal string display price. For limit orders this is the limit price. For market orders this is the protection price used by execution.

quantity

yes

Human decimal string base-asset quantity.

cloid

no

0x-prefixed 16-byte client order id.

Limit order example:

Protected market order example:

POST /trade is synchronous: the request blocks while the transaction is admitted, executed on-chain, and the outcome is read back. Typical latency is a block or two, and a slow call can take up to 10 seconds. Set your client timeout above 10 seconds or you will abandon replies that were about to arrive.

Response envelope:

submission_status answers "did the transaction land?", and it has exactly three values:

  • accepted — the transaction landed and reached execution. There is no top-level error. This does not mean the order succeeded — see what accepted carries below.

  • rejected — the write never reached execution: request-shaping, rate limit, expiry, place-order suspension, or a check before inclusion. error.code carries the reason; tx_hash is present once canonical bytes exist. Six envelope-level execution failures also land here — badnonce, badsignature, expiredtx, malformedtx, invalidbatchlength, featuredisabled — returned in their CamelCase display form (BadNonce, BadSignature, ExpiredTx, MalformedTx, InvalidBatchLength, FeatureDisabled).

  • timeout — the outcome was not observed within the 3-second budget, or the submission could not be routed. Whether it can still land depends on the code — see timeout.

What accepted carries

On accepted the reply includes a fourth field, response, holding the actual per-order outcome. You do not need an /info round trip to learn whether an order rested or filled.

response.type is the action type (order, cancel, cancelAll, modify, batch, or default for a non-order action). Where the outcome sits depends on the action:

  • order, cancel, modify — one status, holding one leaf.

  • cancelAll — statuses[], one leaf per cancelled order. An empty array cancelled nothing and is still a success.

  • batch — statuses[], one full sub-response per item, in item order. Each element repeats the same {"type", …} shape, so a batch leaf sits one level deeper, at statuses[i].status. See batch.

Each leaf is one of four shapes, keyed by its single field:

Leaf
Meaning

{"open":{"oid","cloid"}}

The order rested on the book

{"filled":{"total_sz","avg_px","oid","cloid"}}

The order filled. total_sz and avg_px are display values, formatted exactly as /info formats them.

{"cancelled":{"oid","cloid"}}

The order was cancelled — by an explicit cancel, or by its own time-in-force / self-trade rule

{"error":"<code>"}

The order failed at execution — e.g. insufficientspotbalance, mintradespotntl, tick, missingorder

The transaction landed; the order did not enter the book. There is no top-level error — the code is only in the leaf.

A node-admission reject (CamelCase, verbatim): the order notional was below the market's quote-asset minimum. The transaction never reached execution, so there is no response.

Request-shaping rejections (e.g. InvalidQuantityPrecision) carry no tx_hash because canonical bytes were never assembled; admission rejections include one.

timeout — can it still land?

The error.code tells you, and the two cases need opposite handling:

Code
HTTP
Did it reach a node?
Do next

(none) — the wait budget elapsed

200

Yes. It was admitted and is executing.

Reconcile by cloid. Never resubmit under a new nonce.

Unavailable

503

No. Refused before the write left the API.

Resubmit the same signed bytes. Nothing will be there to reconcile.

NodeUnreachable

504

Unknown. The connection broke mid-submission and the node may already hold it.

Reconcile by cloid. Never resubmit under a new nonce.

When in doubt, treat it as the 504 case and reconcile. The outcomes playbook has the reasoning behind each row.

Beyond per-action outcomes, the API can refuse a write for operational reasons: RateLimited (HTTP 429 — the per-IP budget, 1 request/second by default, or the per-signer 1000/second, with error.retry_after_ms), TooManyPending (HTTP 503 with error.retry_after_ms: 50 — too many synchronous writes are already in flight; retry immediately, it is transient), PlaceOrderSuspended (HTTP 503 — while the write path is degraded, only cancel/cancelAll and an all-cancel batch are accepted so you can reduce exposure; order, modify, any batch that mixes in a non-cancel item, and an empty batch are refused), ExpiredTx (HTTP 200), and the routing codes Unavailable (HTTP 503) and NodeUnreachable (HTTP 504), which come back as submission_status: "timeout". A request body over 256 KiB is rejected with HTTP 413. See the full /trade error-code table in Error responses.

Limits on resting orders. You may hold 1000 open orders per market per account; the 1001st is rejected with accountopenorderlimit. A single order may take at most 100 fills — one that would sweep more comes back as maxfillsexceeded, so split large market orders. Both arrive as leaf codes with submission_status: "accepted".

cancel

Cancels one order by exchange order id or client order id. Provide oid or cloid; if both are present, oid is used.

Field
Required
Values

type

yes

"cancel"

market_id

yes

Decimal string market id.

oid

conditional

Decimal string exchange order id. Required unless cloid is present.

cloid

conditional

0x-prefixed 16-byte client order id. Required unless oid is present.

cancelAll

Cancels every open resting order for the effective owner (recovered signer or agent-resolved principal) in one market. The market must exist. A pure cancel skips admission entirely, so an unknown market is not a top-level reject: the envelope still comes back accepted and the failure appears in the response leaf as marketnotfound. A market that exists but has no open orders for this owner is a successful no-op.

Effects to confirm via reads:

  • The owner's openOrders for this market_id becomes empty.

  • Each previously-open oid reaches orderStatus = "cancelled" with remaining_qty = 0. Orders remain queryable by their existing oid and cloid (if any).

  • Open orders in other markets and orders owned by other signers are unaffected.

Field
Required
Values

type

yes

"cancelAll"

market_id

yes

Decimal string market id.

cancelAll carries no oid and no cloid in the request. The MissingOidOrCloid parse error does not apply to it. Agent signatures are accepted (same allowlist as cancel). Submit precheck classifies it (and any pure-cancelAll or cancel/cancelAll-only batch) as a pure cancel: oracle freshness, frozen SpotCreditAccount, mark coverage, quote-min-notional, and duplicate cloid checks are skipped at admission.

modify

Replaces one open order using action-atomic cancel-plus-place semantics. Provide oid or cloid; if both are present, oid is used. replacement has the same shape as an order without market_id.

Field
Required
Values

type

yes

"modify"

market_id

yes

Decimal string market id.

oid

conditional

Decimal string exchange order id. Required unless cloid is present.

cloid

conditional

0x-prefixed 16-byte client order id. Required unless oid is present.

replacement.side

yes

"bid" or "ask"; "buy" and "sell" are also accepted aliases.

replacement.order_type

yes

"limit" or "market".

replacement.tif

yes

"gtc", "ioc", "fok", or "alo".

replacement.price

yes

Human decimal string display price. For limit orders this is the limit price. For market orders this is the protection price used by execution.

replacement.quantity

yes

Human decimal string base-asset quantity.

replacement.cloid

no

0x-prefixed 16-byte replacement client order id, or null to omit one.

batch

batch is the only multi-item write action. Its items array may mix these item types in payload order under one envelope nonce:

  • order

  • cancel

  • cancelAll

  • modify

cancel and modify items use the same target rules as top-level actions: provide oid or cloid; if both are present, oid is used. A cancelAll item carries only market_id and behaves the same as a top-level cancelAll. A replacement has the same order shape as an order without market_id.

Batch constraints:

  • items must contain 1..=10 items. Anything outside that range fails while the API assembles the canonical bytes, so it comes back rejected with EncodeLengthOverflow and no tx_hash.

  • Items execute in array order.

  • The batch has one envelope nonce. Individual items may succeed or fail inside the batch execution result.

Reading a batch response

statuses[] answers the request item for item. Each element is a full sub-response, not a bare leaf, so the outcome you want is at statuses[i].status:

The first item rested; the second never entered the book. submission_status stays accepted for both, because it describes the envelope and not the items.

A failure leaf carries only error — no oid, no cloid. Array position is your only link back to the item you sent, so keep your own items array to match against.

A cancelAll item is itself multi-result, so it nests one level further, with bare leaves under its own statuses[]:

transfer

Moves an asset between two Native accounts (tag 10). Owner-signed: sign with the main wallet — transfer is not in the agent-signable set, so an API wallet cannot sign it. Under an account multisig it is quorum-signed instead. asset_id/amount are raw atoms. cloid is a required 16-byte hex client operation id.

Both sides must be ordinary balance-mode accounts that already exist. The transfer is rejected if the sender is a SpotCreditAccount or the recipient is one (ActionNotAllowedForSpotCreditAccount), if to is unregistered (AccountNotFound) — this action never creates an account, use activateFor for that — if to equals the signer (TransferToSelf), or if to is the zero address or amount is 0 (InvalidTransfer). Only available balance moves — quantity locked by resting orders cannot be transferred, and a shortfall is InsufficientSpotBalance.

Requires auth_scheme:"eip712". See EIP-712 signing.

activateFor

Creates a balance-mode account for target_address, paid for by the signer (tag 43). Owner-signed, auth_scheme:"eip712" only — this action has no legacy form at all. cloid is a required 16-byte hex client operation id.

There is deliberately no fee amount field: the activation fee is taken from the protocol schedule for asset_id, which must be one of the allowlisted activation assets (InvalidActivationFeeAsset). The fee is exactly 1.0 unit on both mainnet and testnet — asset_id 1 (USDC) or 2 (USDT), both 8-decimal, so 100000000 atoms. It comes out of the signer's available balance and goes to the protocol fee account, so quantity locked by resting orders cannot pay it; a shortfall is InsufficientSpotBalance. The allowlist is append-only and the listed amounts are frozen, so read the fee asset from the schedule rather than hardcoding the pair.

Rejections: the signer must already be registered (AccountNotFound) and must be balance-mode (ActionNotAllowedForSpotCreditAccount); target_address must not already exist (AccountAlreadyActivated) and must not be a registered API wallet (AddressIsAgent); a zero target_address, or a signer that is the protocol fee account, is InvalidAccountActivation.

withdraw

User single-signature withdrawal (tag 32). On success it debits amount from the signer owner's available balance. The asset's withdraw_fee_atoms is recorded (in the event and /info withdraws) but not deducted; amount must be strictly greater than the fee and at least the configured min_withdraw_atoms for (dst_chain_id, asset_id). amount and withdraw_nonce are raw atoms/values. Uses signature, or — when the account has an account multisig Active — signatures with auth_account and policy_epoch. signatures sent without auth_account is rejected (SignaturesNotAllowedForAction). New requests must include a fixed 16-byte hex cloid used only for txStatusByCloid; it is not an idempotency key.

Requires auth_scheme:"eip712". See EIP-712 signing.

Clients should use the current Unix millisecond timestamp for withdraw_nonce and locally increment it if sending multiple withdrawals for the same account in the same millisecond.

Withdraw consumes a windowed-unique business nonce with 3-day retention: a nonce at/below the pruned floor or already retained for its account window is rejected (WithdrawDuplicateNonce). A failed withdraw burns the envelope nonce but not the business nonce, so a retry reuses the business nonce under a new envelope nonce.

These are also rejected before inclusion when the current committed state already proves them invalid: missing accounting config, missing asset/config, invalid account shape, duplicate committed business nonce, withdraw amount/fee/minimum failures, or insufficient withdraw cash. Once a withdraw is accepted into ingress, its business nonce is also held in a live-only pending overlay, so a concurrent replay of the same business nonce is rejected before block inclusion. This overlay is not canonical state and is retired after the accepted transaction's result publishes to QueryView.

Parse errors include MissingCloid and InvalidCloid. Older records written before this field existed still replay without a cloid and are not queryable by txStatusByCloid.

settle

settle and repay move value between the two account types. A SpotCreditAccount is the credit account; a balance-mode / cash account is the default spot account. See Account Types.

SpotCreditAccount de-risking (tag 33). The signer must be an Active SpotCreditAccount (the margin owner). It moves amount of asset_id out of the signer's long margin position (actual_qty > 0) into cash_account's available balance, requiring the signer's post-position available_usd >= 0. cash_account may be any existing balance-mode account (it must not be a SpotCreditAccount). asset_id/amount are raw atoms. cloid is a required 16-byte hex client operation id. Uses signature, or — when the account has an account multisig Active — signatures with auth_account and policy_epoch. signatures sent without auth_account is rejected (SignaturesNotAllowedForAction).

Requires auth_scheme:"eip712". See EIP-712 signing.

Parse errors: MissingCloid (cloid absent), InvalidCloid (not 16 bytes), InvalidCashAccount (not a 20-byte hex address), InvalidAssetId. Execution errors include InvalidSettle (signer not a credit account, cash_account missing/credit, zero amount, no settleable long, or over-settle), SpotCreditAccountFrozen (frozen signer), OracleMarkPriceMissing (a residual nonzero-net asset lacks a fresh mark), and InsufficientSpotCredit (post available_usd < 0). A full settle that clears the asset's net to zero needs no mark.

These same settle errors can come back before block inclusion when the current committed state already proves the settle invalid. Execution remains authoritative for any transaction accepted into ingress.

repay

SpotCreditAccount de-risking (tag 34). The signer must be a balance-mode cash account. It spends amount of asset_id from the signer's available balance to reduce margin_account's short (actual_qty < 0) toward zero. margin_account may be any existing SpotCreditAccount, Active or Frozen (repay does not unfreeze). There is no available_usd check and no oracle dependency — repay strictly de-risks. asset_id/amount are raw atoms; cloid is required. Uses signature, or a quorum under an account multisig.

Requires auth_scheme:"eip712". See EIP-712 signing.

Parse errors: MissingCloid, InvalidCloid, InvalidMarginAccount, InvalidAssetId. Execution errors include InvalidRepay (signer is a credit account, margin_account missing/non-credit, zero amount, no short, or over-repay past zero) and InsufficientSpotBalance (signer's cash is too low).

These same repay errors can come back before block inclusion when the current committed state already proves the repay invalid. Execution remains authoritative for any transaction accepted into ingress.

Settle/repay carry no business nonce and provide no idempotency: the cloid is used only for txStatusByCloid lookups within the recent query window (see txStatusByCloid). The envelope nonce is the only replay protection — the same cloid resubmitted under a new envelope nonce is a distinct transaction. The lookup is keyed on the recovered signer (settle → margin owner; repay → cash owner), or on the auth_account under an account multisig; a counterparty cannot find the tx by cloid.

approveAgent

Approves an agent (API-wallet) signing key on one of the owner's agent slots. Owner-signed: sign with the main wallet under auth_scheme:"eip712" — an API-wallet key cannot sign it. Carries no agent_epoch, takes one signature (or a quorum under an account multisig), and cannot appear inside a batch. After approval, subsequent agent-signed writes reference the slot's current epoch via agent_epoch (read it from userAgents).

Field
Required
Values

type

yes

"approveAgent"

slot_id

yes

Owner agent slot, 0–3.

agent

yes

0x-prefixed 20-byte agent (API-wallet) signing address.

Parse errors: InvalidAgentSlot (slot outside 0–3), InvalidAgent (not a 20-byte hex address). A legacy signature is rejected with LegacySignatureNotAccepted; supplying agent_epoch is rejected with Eip712AgentEpochNotAllowed.

revokeAgent

Clears the agent approval on one owner slot. Owner-signed under auth_scheme:"eip712", same constraints as approveAgent (no agent_epoch, one signature or a quorum, not batchable). After revocation, writes signed by that key are rejected with UnknownAgent.

Field
Required
Values

type

yes

"revokeAgent"

slot_id

yes

Owner agent slot, 0–3.

Parse errors: InvalidAgentSlot. Same EIP-712 gating as approveAgent.

setAccountMultisig

Creates or replaces the account's own signer quorum. Owner-signed under auth_scheme:"eip712" for a first-ever creation; once a configuration is Active, a replacement is itself quorum-signed.

Field
Required
Values

type

yes

"setAccountMultisig"

threshold

yes

Approvals required, 1 … signers.length.

signers

yes

1–32 addresses, unique, non-zero, sorted ascending, and never the account's own key.

creation_fee

first creation only

1,000 USDC or USDT, selfPaid or sponsored. Omit when replacing.

cloid

yes

16-byte hex, for txStatusByCloid only.

Enabling a quorum permanently stops the owner key from signing trading actions, and a configuration can never be removed. The full contract — setup order, the creation fee, sponsorship, the quorum-signed envelope, and the complete error list — is on Account Multisig. Read it before submitting this action.

Last updated