Docs · Guides

Open and close a perp

Open a leveraged long or short against the perps vault at the oracle price, read the position, change its collateral and close it, in the app or from code.

A perp on Mesa is a sealed position against the perps vault. It opens and closes at the oracle price, so there is no order book and no counterparty to find. Its size, direction and liquidation price are readable only by you.

Before you open

Each market on Perps shows its oracle price, funding, open interest long and short, and the vault's size.

Open

1. Open Perps and choose the market.
2. In "Open a sealed position", choose Long or Short.
3. Enter the collateral and choose the leverage.
4. Check "Size", "Liquidation price, yours to see" and the open fee. Press "Review position".
5. Press "Open position".

In the app you choose collateral and leverage, and the size follows: collateral times leverage, divided by the oracle price. From code you give the collateral and the size directly.

The position's entry price is the oracle price at the moment you place it. The proof made then shows the position is within the market's maximum leverage and above its maintenance margin.

The open goes through a batch. When the batch clears, the market adds the position to its open interest. If that would pass the market's open interest limit, the open is refused, and Close on the position returns the collateral.

On the batch record, the market's open interest on your side rises by the size.

Read the position

ShownMeaning
CollateralWhat the position holds
EntryThe oracle price it opened at
UnrealizedIts result at the current oracle price, before fees and funding
Health1.00 is the maintenance margin. Above it the position can renew.
Liquidation priceThe oracle price at which health reaches 1.00. Shown only to you.
Next renewalTime left until the position's deadline
Renewed byThis browser, the watcher, or your own script

From code: entryPrice, unrealizedQuote, health, liquidationPrice, nextDeadlineAt and renewedBy on each entry of mesa.snapshot().positions.

Funding

While longs outweigh shorts in a market, longs pay funding and shorts receive it, and the reverse when shorts outweigh longs. Funding accrues against your position each time the market clears a batch. It counts in health at every renewal and is settled when the position closes. See Funding.

Change collateral

1. On the market's page, select "Collateral" in the position panel.
2. Choose "Add collateral" or "Remove collateral" and enter the amount.
3. Press "Review" and confirm.

Both land at once, prove the position healthy after the change, and move its deadline one heartbeat on. Adding collateral moves the liquidation price away from the market.

Close

Press "Close" on the position.

A close goes through the next batch and settles at the oracle price that batch's clear reads. Your balance receives

text
collateral + result − open fee − close fee − funding owed

A gain is paid from the perps vault and a loss is paid into it. The open fee is charged on the size at the entry price and the close fee on the size at the closing price. Rates are in Fees and MESA.

If the vault cannot pay the gain in that batch, the close is refused and the position stays open. Take the close back, and the position returns with its collateral, its entry and a new deadline:

The position's line reads "Close not done in batch N". Press "Restore the position".

While a close is in its batch, the line reads "Closing in batch N" and the position's other actions are hidden.

What can stop a perp

You seeCauseDo
"More than your Mesa balance of …"The collateral exceeds the free balanceEnter less or deposit
MarketPausedThe perp market is pausedOpens resume when it is unpaused. Closing runs while paused.
StaleOracleThe oracle price is older than the program acceptsTry again when the price updates
ProofVerificationFailedThe oracle price moved between proving and landingTry again. The proof is rebuilt at the new price.
A refused openThe market's open interest limit was reached in that batchClose the position to take the collateral back, then open a smaller one
A refused closeThe perps vault could not pay the gain in that batchReclaim the close. The position comes back with its collateral, its entry and a new deadline. Close it again in a later batch.

If you stop renewing

A perp that passes its deadline unrenewed lapses, and its contents become readable. If its margin is still above maintenance, renewing seals it again. If not, anyone can liquidate it: the liquidator receives the market's liquidation bonus from the collateral and the rest goes to the perps vault. See Liquidation.