Skip to main content
This page walks through the full orderbook trading lifecycle — loading state, getting quotes, posting and filling orders, collecting interest, and withdrawing funds.

Installation

Setup

1

Get a Quote

getQuote simulates a trade and returns the expected output before you send a transaction.
Always use connection.getClock() for the unixNow parameter — Date.now() may drift from the onchain clock and produce inaccurate quotes.
2

Post a Limit Order

ixWrapperPostOffer places a limit order on the orderbook. The wrapper handles token account creation for you.
The setupIxs array creates PT, YT, and SY token accounts if they do not exist. Always include them before ix in your transaction.
3

Execute a Market Order

ixWrapperMarketOffer fills against existing orders immediately.
Set minAmountOut for slippage protection. The transaction reverts if the output falls below this threshold.
4

Check Open Orders

Query your active orders to see what is currently on the book.
5

Remove an Order

Cancel an open order using its offerIdx from getUserOpenOrders.
Use getUserOpenOrders to find the offerIdx of the order you want to remove. Removing an order returns PT/YT back to your escrow balance.
6

Collect Interest

Collect yield that has accrued on YT held in your open or filled orders.
Interest accrues on YT held in open sell orders and from filled buy orders. You can collect it at any time without affecting your active orders.
7

Withdraw Funds

Withdraw PT, YT, and SY from your orderbook escrow back to your wallet.
Use amount("All") to withdraw all available funds, or amount("Some", [500_000_000n]) for a specific amount. The amount helper is imported from @exponent-labs/exponent-sdk.

Reading State

Read orderbook and user state without transactions:

Next Steps

Core Concepts

Understand escrows, fee decay, interest accrual, expiry behavior, and the account model behind the orderbook.

Virtual Offers

Learn how PT trades route through shared YT liquidity using strip and merge flows under the hood.

TypeScript Instructions

Explore the full set of instruction builders for posting offers, taking liquidity, removing orders, collecting interest, and withdrawing funds.

Read Functions

Query quotes, balances, open orders, and other orderbook state without sending transactions.