Settled event on the deposit contract. For the trading model, see Composability.
Get ready to quote
- Connect to the authenticated
/account/events/{user_id}WebSocket. Give Tplus your maker user ID and token market ID and ask for a sync book. Public self-service creation is unavailable. You can have one book per market. A newly created book sends youSyncBookCreated. If the book already exists or you missed the notice, ask Tplus to confirm. - Use a cross-margin trading account on each side. Choose a token market identified by address and chain. Check
GET /registry/assetsfor a USD representation on that chain and confirm that the base token has no native asset. Find the chain’s deposit contract withGET /registry/vaults. Check your maker key in itsgetApprovedSettlers()list and confirm with Tplus that your executor contract is registered for that key. - Start consuming the authenticated
/sync/pending-fillsWebSocket before you quote. The subscription starts after the welcome frame, so even connection setup can leave a gap. Use/ordersto track your quotes. Public market depth excludes sync quotes. See WebSocket streams.
Sign and post a quote
Submit the signed order toPOST /orders/create. A SyncQuote is post-only and takes no trigger. A bid or offer that would cross your opposite quote in the same book is rejected. Price and base quantity are integers scaled by the market’s respective book decimals. After applying both decimal scales, price × quantity must be worth at least 5 whole quote units. Any positive remainder after a replace or amend must still meet that minimum. Use cancel to withdraw the quote.
The default time-in-force is GTC. For GTD, set time_in_force=SyncGTD(timestamp_ns=deadline_ns) using the SyncGTD model from tplus.model.sync_order and a Unix timestamp in nanoseconds. Both expire no later than 30 days after the signed creation time. Choose a fresh client order ID across your sync and ordinary orders in the market. See Orders for order management.
This example offers 5 tokens at 100 USD. It assumes a market with two price decimals and four quantity decimals. Use an OMS client oms, your signer maker, token-market asset_id, fresh order_id and registered executor_address. Build the details explicitly because the Python quote helper has no executor-address argument.
Received confirms book acceptance. An unregistered maker gets HTTP 403 WRONG_AUTHORIZATION. A missing book can produce HTTP 400 INVALID_BOOK_CONFIGURATION. If the request times out, check GET /orders/lookup?order_id=…&asset_id=… before submitting again. See Signing.
Follow the taker’s order
ASyncTaker is an untriggered immediate-or-cancel (IOC) spot order with a positive limit price and base quantity. The taker cannot select a maker. The venue selects the sync book that could fill the most within the limit, breaking quantity ties by best total price for the taker. It takes the best prices across that book and the orderbook, giving ordinary orders priority at equal prices.
Suppose the only other liquidity is an ordinary offer of 10 tokens at 100 USD. On a separate client, the taker can submit this order for 20 tokens with a limit of 110 USD using the same market decimals.
The sync leg emits no trade and charges no trading fee. A USD payout can reserve a rebalancing fee against the taker, shown in
approval.reserved_fee. A market-token payout reserves none. The signed trading fee cap does not bound this settlement fee. Budget gas and the cost of sourcing the incoming token when pricing your quote.
Execute the approval
Only the maker receives the approval on/sync/pending-fills. In the default protocol, an approval carries approval and a failure carries reason. In tplus.ws.v1, read data on the sync-settlement-approved or sync-fill-failed channel. Python’s oms.stream_sync_fills(user=maker) yields typed events, but its approval model omits vault. Save the raw frame before submitting a transaction. It identifies the market, your crossed orders in maker_quotes (each with an order ID and optional trade ID), the taker’s tplus_user and sub_account_index, and the signed approval.
- Use
approval.vaultas the deposit contract on the approval’s chain. For EVM token and contract addresses, take the first 20 bytes of the right-padded 32-byte value. Keep the full taker and settler keys. Assemble the contract order in ABI order fromasset_out,amount_out,asset_in,amount_in, spot mode (0),tplus_user,sub_account_index,inner.nonceandexpiry. Use the signed amounts in native token units andexpiryasvalidUntil. The lifetime is set per chain within a fixed 5–120 second range. The block timestamp may equal the signed expiry in Unix seconds. - Have your registered executor call
executeAtomicSettlement(order, settler, data, signature)with your maker key as settler and the approval’sinner.signature. Execute pending approvals in increasing nonce order for the same deposit contract, taker and sub-account. A higher executed nonce invalidates lower ones. Record the transaction hash with the approval as soon as you have it. - In
onAtomicSettlement, use the outgoing tokens to source the incoming token. Return at least the approvedamount_inand grant the deposit contract allowance for the full amount you return. The deposit contract pulls exactly that amount, so returning more also pays more. See Settlement integration.
Reconcile before replenishing
After a gap, check the deposit contract’s logs through a block past the approval deadline before declaring it unused. If you missed the nonce, compare the taker, sub-account, settler and settlement terms against your saved records. Keep ambiguous matches unresolved. As the maker, fetch all pages of
GET /orders/user/{user_id}/{asset_id}?open_only=true starting at page=0 before sizing replacement quotes. See Bot safe stop.