Skip to content
Temporal Docs← Back to the app

07 · Leaving a position

Leaving a position

There is one way out, and it is the market#

These options never expire, so nothing tears one up. Leaving is a trade at the front: the best quote on the side you need, at your leg's own strike and decay. The price is the market's now, not a function of what you paid. If no maker stands there, the leg goes back to the maker who wrote it, at the oracle's price and never below intrinsic, and the screen says so. Partial fills are honest too: what filled, filled. A fee applies to the taker on each close (section 6).

A taker's close#

You sell at the best bid (or buy back at the best ask) among the makers standing. The position then goes back to the maker who wrote it, the writer of record, and the writer pays or receives that best price itself. The maker who quoted the best price only set the price. So every taker close removes a position from the book: open interest falls whenever a taker closes. You never see a difference; you simply get the best price.

A writer can sit a little off the best quote, so the gap between its own quote and the best is its to bear. That gap is small by construction: no quote outside the corridor can set the front (see Pricing).

A maker's close#

A maker closing passes its obligation to the makers standing at the front, and the trader's side is untouched. The claim changes house; nothing disappears from the trader's side. A maker that has stopped quoting still stands on the trades that reduce what it already wrote, so whoever wrote your position can take it back.

Funding: holding a position#

You never need to trade to hold. What an option holder pays is funding, the cost of the roll described in How it works: the leg's extrinsic at the oracle's relevant side and its own decay, times its rate per year, for the time that passed. The long pays it; the short receives it, less the venue's 10 % share. A close first settles the funding built up to that moment. Intrinsic is never charged. It shows in PORTFOLIO as FUNDING, and funding alone never liquidates an account.

What a close pays#

An in-the-money option pays its intrinsic in full at every exit; only the time value is at the market's current view. A single option from the OPTION ticket has no second leg, so closing it trades that one leg and pays the result into the account. For a PROTECT pair, P/L is carried per pair, and the dollars go back to your HyperCore wallet, by a payout you sign, when the account closes.

The close verbs: three#

CLOSE is one position: a perp row, one option pair, one single option, or one maker line. CLOSE ACCOUNT closes every position in one account; the account goes inactive, its curve stops quoting, and its name stays with it for good. CLOSE ALL is wallet-wide: every position in every account. CLOSE and CLOSE ALL touch positions only, so a curve keeps quoting and the account stays alive. On a PROTECT account the two positions are one structure, so CLOSE ACCOUNT is the only close there is. The same words work whatever the account's kind.

Do this from your agent

Close a leg, or CLOSE ACCOUNT

A close is the open with the side reversed, asked of the same front. closeLegAtFront(account, legIndex, qty) closes all or part of one option leg (the leg index is in your /chain/state). closeAccountAtFront(account) is CLOSE ACCOUNT: every open leg at the front and a close request for every open perp, in one signed act. A PROTECT account closes only this way, as a whole.

Your legs, with their index
curl -s "https://protect.temporal.exchange/api/venue/chain/state?wallet=0xYOUR_WALLET"
# accounts.T1.legs[] -> { "legIndex": 0, "wing": 0, "strikeUSD": 83805.75, "qty": 0.01, "side": 0, ... }   (wing 0 call, 1 put)
close.mjs
// close.mjs leg <account> <legIndex> <qty>   close (all or part of) one option leg at the front
// close.mjs account <account>               CLOSE ACCOUNT: every open leg at the front and a close request for every open perp, in one signed act
import { wallet, get, call, check, act, coin } from "./temporal.mjs";

const [what, account, legIndex, qty] = process.argv.slice(2);
if (what === "leg") {
  const st = await get(`/chain/state?wallet=${wallet.address}`);
  const acct = Object.values(st.accounts).find((a) => String(a.id) === account);
  const leg = acct.legs.find((l) => String(l.legIndex) === legIndex);
  console.log("closing", leg.asset, leg.wing === 0 ? "call" : "put", "strike", leg.strikeUSD, "qty", qty ?? leg.qty);
}
const data = what === "leg" ? call("closeLegAtFront", account, legIndex, coin(Number(qty))) : call("closeAccountAtFront", account);
const dry = await check(data);
if (!dry.ok) throw new Error(`the venue would refuse: ${dry.reason} (${dry.errorName ?? dry.code})`);
if (process.env.CONFIRM !== "yes") process.exit(console.log("Dry run passed. Run again with CONFIRM=yes to sign and send."));
console.log(await act(data));
// A PROTECT account closes only as a whole (use `account`). A close of an account that holds a perp asks HyperCore to close it; the venue's keeper settles it within a minute or two.
Run it (dry run first, then CONFIRM=yes)
WALLET_KEY=0x… node close.mjs leg 5 0 0.01
WALLET_KEY=0x… node close.mjs account 5

A perp on the account is closed on HyperCore by the venue's keeper within a minute or two; watch perps[] in your state go from closing to closed. What is left in the account is yours to take out: see withdrawals. A close that finds no maker at the front leaves the position open and says so.

Paste this to your agent

On the Temporal testnet venue, close my option leg 0 in account 5 (all of it). Read my state first and show me the leg, then run the dry run, tell me what I should get back after the fee, and wait for my yes. Use close.mjs from https://protect.temporal.exchange/docs/settlement. After it lands, read /chain/state and /chain/fills and show me the fill price, the fee and the account's deposit before and after.

Check the result yourself: the close and CLOSE ACCOUNT checks.

Kept in lockstep with the code: a check fails if this page drifts.

Everything above is the short form. The canon — every ruling, every rejected alternative with the reason it was rejected, and the measurements behind each number — is the design spec, and the corroboration procedure is the audit protocol. Both live in the repository this venue is built from.