Skip to main content
This guide uses OMS for trading and account state. Market data comes from MDS; see Market data client.

Flow

  1. Authenticate: GET /nonce/{user_id}, sign the nonce value, POST /auth.
  2. Discover the market on OMS: GET /markets or GET /market/{asset_id} for book decimals and fees.
  3. Sign the action-specific object: order create signs order and replace signs request. Cancels are not signed.
  4. Submit over REST or the /control WebSocket.
  5. Treat the REST response as acceptance, not as a finalized fill. Confirm over the orders and trades streams or by refetching orders.
Numeric examples use raw book units. With book_price_decimals = 2, 250000 means 2500.00. With book_quantity_decimals = 8, 125000000 means 1.25000000.

Raw REST

create-order.json contains the signed body from Signing. Replace:
Cancel:
Batch create wraps signed create requests:
Batch create is not all-or-nothing: accepted orders remain live even if a later item rejects. Cancel-all is unsigned at the action layer and authenticated by the session. OMS collects open orders with timestamp_ns < max_ts; if max_ts is omitted, it uses server time:
Use DELETE /orders/cancel-all/{asset_id} to scope to one market. Use DELETE /orders/cancel-batch with order IDs for a selected subset; IDs not owned by the caller are ignored.

tpluspy

tpluspy takes prices and quantities as Decimal whole units and scales them by the market’s book decimals. Any other type, or a value that does not scale to a whole u64, raises OrderScaleError before anything is sent.
Pass use_ws_control=True to OrderBookClient to send create, replace, and cancel over /control instead of REST. The control channel accepts v0 raw action wrappers or v1 envelopes with request_id.

Replace semantics

Replace preserves the order ID. The mutable fields are price, quantity, and trigger. Every replace signs the effective price, lifetime-total quantity (including fills), trigger state and both book decimals. Fill state of a partially filled enabled order is preserved. A replace with an older timestamp_ns than a newer applied replace is rejected by the orderbook. REST replace and REST cancel first look up the current OMS order and return not found if absent. On REST and /control, OMS looks up the order and checks the market decimals, resulting trigger and remaining size before forwarding a replace. A cancel that reaches the fast queue before its create can reject the later create.

Sub-accounts, transfers, and close-all

There is no standalone “create sub-account” call. Transfer a balance from a trading account into an unused target_index and include target_account_type. Raw transfer: Populate signature with the Ed25519 signature bytes over compact inner before sending.
To move deposited tokens from the Funding account (account 0) into a trading account, make a Funding account transfer: name the token instead of an asset index, as "transfer_asset": "<32-byte hex token address>@<9-byte hex chain id>". tpluspy-assisted transfer, using the SDK user signer and the raw request path:
Use a client-generated, strictly increasing nonce per action domain and treat that nonce as the retry key: after a timeout, check /account/events/{user_id} and /inventory/user/{user_id} before sending a new nonce. Clearing a position (POST /account/transfer/clear-position) settles the whole quote once the base leg is zero. It folds the remaining quote credits into spot USD, or repays quote liabilities from spot USD, and emits PositionCleared; if a quote liability remains, the spot USD balance must cover it. While a long is open, it moves only a quote profit to spot USD, keeps the base and emits PositionCleared. If a short has no quote leg, clearing repays its base liability using spot of the same asset, up to the smaller of the spot balance and the liability. Other open positions with no settled profit or repayable base are rejected with No settled PnL while the long is open or No settled PnL while the short is open.
Close-all is a preview loop:
  1. GET /positions/close-all/{user_id}/{sub_account} returns close-order suggestions.
  2. Sign each suggested order.
  3. Submit with POST /orders/batch-create.
  4. Watch fills, then call clear-position for each flattened asset.
  5. Re-run the preview after partial fills or price movement.