Docs · Guides

Place and follow an order

Place a limit or market order into a batch, follow it through every state to its fill, and reclaim an order that was never opened.

An order on Mesa goes into the current batch sealed, opens with every other order when the batch closes, and fills at the batch's one clearing price or not at all.

Before you place

You need a Mesa balance of the asset you give up: the quote asset to buy, the base asset to sell. See Deposit and withdraw.

A limit order names the worst price you accept. It fills whole if the batch clears at a better price, pro rata if the batch clears exactly at your limit, and not at all if it clears at a worse one. A market order fills at whatever price clears the batch.

Either way the fill is at the clearing price. An order with a limit of 185.00 in a batch that clears at 182.18 fills at 182.18.

Place it

1. Open Trade and choose the market.
2. In "Place a sealed order", choose Buy or Sell, then Limit or Market.
3. Enter the amount under "You pay".
4. For a limit order, enter the limit price. "Last clearing price" fills in the last batch's price.
5. Press "Review order". Check "You lock", the limit, "You receive at least" and the batch.
6. Press "Place order".

amount is what you lock. A sell locks the base amount it sells. A buy locks quote: to buy up to 10 SOL at a limit of 185.00, lock 1,850 USDC. Whatever a buy does not spend returns at settlement.

The review's Batch line says which batch the order joins. In the last moments before a close, an order goes into the next batch.

Follow it

The order appears under Your orders here on the market's page and under Open orders and fills on Portfolio. Only your browser can list it: it finds the order by decrypting Mesa's notes with your keys.

StateIn the appMeaning
sealedSealedPlaced. The chain holds a commitment and nothing else.
openingOpeningThe batch has closed and its orders are being opened
filledFilledThe whole order filled at the clearing price
partially_filledPartly filledThe batch cleared exactly at your limit and the order filled pro rata. The rest is back in your balance.
unfilledNot filledThe batch cleared at a worse price than your limit. Everything is back in your balance.
reclaimableNot opened: reclaimThe batch's open window ended and the order was never opened
reclaimedReclaimedYou took the locked funds back

A filled order shows the amount filled and the clearing price, and links to its batch.

From code, swap resolves once the batch has settled, with the order in its final state:

ts
if (order?.state === 'filled' || order?.state === 'partially_filled') {
  console.log(order.filledBase, order.filledQuote, order.clearingPrice)
}

To follow the clock yourself, subscribe to the batch event stream, or read GET /v1/clock.

You do not need to stay. Once an order is placed, opening and settling it need nothing from you: its terms and the keys to settle it are timelock-encrypted to the batch's close, and the fill is paid to a key only your account can read.

Reclaim

Mesa's keeper opens every action of every batch, and anyone else can too. If an order was still not opened when the batch's open window ended, it shows Not opened: reclaim.

Press "Reclaim" on the order.

Reclaim proves the order is yours and returns the locked funds to your balance. Only the owner can produce that proof.

Read what the batch shows

Open the batch from the order's batch N link. Your order is on the public record with its side, amount, limit and fill, and with no owner. Read a batch goes through the page.

What can stop an order

You seeCauseDo
"Deposit into Mesa first"No free balance of the asset you pay withDeposit, then place
"More than your Mesa balance of …"The amount exceeds the free balanceEnter less
BATCH_CLOSED, STALE_BATCHThe batch closed while the order was being provedPlace it again. It joins the current batch.
InvalidBatchTimeThe order reached the program inside the place margin before the closePlace it again
ActionLimitExceededThe market has taken its maximum number of actions for this batchPlace it again in the next batch
"This market is paused."The market is paused. An order already sealed for it opens as invalid.Reclaim the order. New orders resume when it is unpaused.
ProtocolPausedThe whole protocol is pausedOrders resume when it is unpaused
PROVER_FAILEDThe prover service did not answerTry again

Each program error is described in Program: errors.