> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tplus.cx/llms.txt
> Use this file to discover all available pages before exploring further.

# Synchronous making

> Place a quote in your sync book, execute the approved exchange onchain, and reconcile a fill after a disconnect.

A sync book lets a designated market maker quote a token it can source onchain. Only you can quote in your book. You act as the settler through your executor, the contract that performs the onchain exchange. When a taker matches your quote, the matched quantity leaves the book. Record the exchange as settled when your executor's transaction produces a matching `Settled` event on the deposit contract. For the trading model, see [Composability](https://docs.tplus.cx/composability.md#synchronous-making).

## Get ready to quote

1. 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 you `SyncBookCreated`. If the book already exists or you missed the notice, ask Tplus to confirm.
2. Use a cross-margin trading account on each side. Choose a token market identified by address and chain. Check `GET /registry/assets` for a USD representation on that chain and confirm that the base token has no native asset. Find the chain's deposit contract with `GET /registry/vaults`. Check your maker key in its `getApprovedSettlers()` list and confirm with Tplus that your executor contract is registered for that key.
3. Start consuming the authenticated `/sync/pending-fills` WebSocket before you quote. The subscription starts after the welcome frame, so even connection setup can leave a gap. Use `/orders` to track your quotes. Public market depth excludes sync quotes. See [WebSocket streams](https://docs.tplus.cx/api-reference/websockets.md).

## Sign and post a quote

Submit the signed order to `POST /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](https://docs.tplus.cx/trading/orders.md) 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.

```python theme={"dark"}
import time
from tplus.model.order import CreateOrderRequest, Order, Side, TradeTarget
from tplus.model.sync_order import SyncQuoteOrderDetails

market = await oms.get_market(asset_id)
assert (market.book_price_decimals, market.book_quantity_decimals) == (2, 4)
order = Order(
    signer=maker.public_key,
    order_id=order_id,
    base_asset=asset_id,
    book_price_decimals=market.book_price_decimals,
    book_quantity_decimals=market.book_quantity_decimals,
    details=SyncQuoteOrderDetails(
        limit_price=10_000, quantity=50_000, executor_address=executor_address
    ),
    side=Side.SELL,
    creation_timestamp_ns=time.time_ns(),
    target=TradeTarget.margin_account_spot_trade(),
)
signature, additional = maker.signing_parts(order.signable_part())
request = CreateOrderRequest(
    order=order, signature=signature, additional_signers=additional,
    post_sign_timestamp=time.time_ns(),
)
reply = await oms.send_order(request, user=maker)
```

The signature covers the complete order, including its time-in-force and lowercase hex executor address. The deposit contract checks the calling executor's registration under your settler key. A create status of `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](https://docs.tplus.cx/guides/signing.md#raw-signing).

## Follow the taker's order

A `SyncTaker` 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.

```python theme={"dark"}
from decimal import Decimal

await taker_oms.create_sync_taker_order(
    quantity=Decimal("20"), price=Decimal("110"), side="Buy", asset_id=asset_id, user=taker
)
```

The ordinary offer fills **10**, your offer fills **5**, and the remaining **5** cancel. Your executor owes **5 tokens** for a **500 USD** payout, converted to the chain's USD token. Only the sync leg goes into your approval, even when it spans several of your quotes.

Clearing locks the taker's outgoing spot inventory and chooses a settlement nonce. A buyer needs spendable USD for the purchase and any reserved fee. A seller needs the market tokens it sells. The fill itself requests approval. Skip the separate settlement-init step used for a manually requested settlement.

| Your quote | Deposit contract sends your executor | Your executor delivers to the deposit contract |
| - | - | - |
| Offer (taker buys) | The chain's USD token | The market token |
| Bid (taker sells) | The market token | The chain's USD token |

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`.

1. Use `approval.vault` as 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 from `asset_out`, `amount_out`, `asset_in`, `amount_in`, spot mode (`0`), `tplus_user`, `sub_account_index`, `inner.nonce` and `expiry`. Use the signed amounts in native token units and `expiry` as `validUntil`. The lifetime is set per chain within a fixed **5–120 second** range. The block timestamp may equal the signed expiry in Unix seconds.
2. Have your registered executor call `executeAtomicSettlement(order, settler, data, signature)` with your maker key as settler and the approval's `inner.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.
3. In `onAtomicSettlement`, use the outgoing tokens to source the incoming token. Return at least the approved `amount_in` and 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](https://docs.tplus.cx/guides/settlement-integration.md#onchain-execution).

## Reconcile before replenishing

| What you observe | What to do |
| - | - |
| Successful transaction | Find the `Settled` log on the approved chain and deposit contract for the taker, sub-account and nonce. Verify the settler, tokens and signed amounts. `Settled.amountIn` records the signed minimum even if your callback paid more. The taker can match `SettlementCompleted` on its account-events stream and check inventory for the incoming credit. Credit can lag, and an unvalued settlement can produce no completion notice. See [Settlement](https://docs.tplus.cx/funds/settlement.md). |
| Fill refused or approval expired unused | Both parties receive a failure on the sync stream with their own orders. Inspect `reason` and, for your own fault, `details`. `counterparty_at_fault` identifies a refusal caused by the other party. Confirmed unused expiry releases the taker's reservation and reports `sync_settlement_expired`. The matched quantity stays off your book even if settlement fails. |
| Transaction reverted | That attempt made no exchange. Check the revert, executor registration, available tokens and allowance. Retry the same approval only while its deadline and nonce still permit execution. |
| Transaction pending or outcome unknown | Check the receipt and matching deposit contract log before hedging or resending. A higher `settlementCounts(user, account)` can mean a later nonce executed. A local timeout or an elapsed deadline alone cannot tell you whether this approval landed. |
| Disconnect or silence | Pause quoting and reconnect. As the maker, call `GET /settlement/signatures/{user_id}` with **your own** user ID to recover retained approval terms. The list includes manually requested settlements, has no sync-fill marker or quote IDs, and can still contain an executed approval. Match recovered terms to your own strategy records before executing. An empty list cannot rule out execution. Missed failures cannot be fetched and the stream has no replay. A fill dropped during recovery or a freeze can leave no notice at all. |

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](https://docs.tplus.cx/guides/bot-safe-stop.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.