Flow
- Authenticate:
GET /nonce/{user_id}, sign the nonce value,POST /auth. - Discover the market on OMS:
GET /marketsorGET /market/{asset_id}for book decimals and fees. - Sign the action-specific object: order create signs
order, replace signsrequest, cancel signscancel. - Submit over REST or the
/controlWebSocket. - Treat the REST response as admission, not finality. Confirm over the orders and trades streams or by refetching orders.
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:
timestamp_ns < max_ts; if max_ts is omitted, it uses server time:
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
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; the request also carries book decimals when price or quantity changes. Fill state of a partially filled enabled order is preserved. A replace with an oldertimestamp_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. The control channel forwards directly to the orderbook; 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 spot balance into an unusedtarget_index and include target_account_type.
Raw transfer:
Populate signature with the Ed25519 signature bytes over compact inner before sending.
/account/events/{user_id} and /inventory/user/{user_id} before sending a new nonce. The current request_transfer_to_subaccount SDK helper does not include the required signed nonce field; use the explicit signing path above until the helper exposes it.
Close-position is available only after 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.
request_close_position SDK helper also omits the required signed nonce; use the explicit signing path above until the helper exposes it.
Close-all is a preview loop:
GET /positions/close-all/{user_id}/{sub_account}returns unsigned reduce-only close orders.- Sign each suggested order.
- Submit with
POST /orders/batch-create. - Watch fills, then call close-position for each flattened asset.
- Re-run the preview after partial fills or price movement.