Instant Close hooks
React hooks over the core Instant Close flow. Same three-function split as Instant Open, plus bulk variants.
Single and bulk market-close hooks inherit core’s solver-specific order types: Enigma signs MARKET_BEST_EFFORT (2), Rasa signs MARKET (1), and limit closes retain LIMIT (0). Callers keep the same hook parameters.
The page is split into two groups:
- Reads — pending queue reads (
useInstantCloses). - Writes — single-quote close (
useInstantCloseAuto,useLimitCloseAuto,useInstantClose) + bulk variants (useInstantCloseBulk,useInstantCloseBulkAuto).
Import
import {
useInstantClose,
useInstantCloseAuto,
useLimitCloseAuto,
useInstantCloseBulk,
useInstantCloseBulkAuto,
useInstantCloses,
} from "@symmio/trading-react";Reads
useInstantCloses
Paginated list of the solver’s pending instant-closes for a SubAccount. useManagedQuotes consumes this internally.
const pending = useInstantCloses({ account: subAccount, offset: 0n, size: 20n });Writes
useInstantCloseAuto
One-line orchestrator: prepareInstantCloseParams + instantClose. Runs the market metadata / mark-price fetches inline.
const close = useInstantCloseAuto();
close.mutate({
from: sessionKey,
partyA,
market: { id: 1 },
positionType: PositionType.LONG,
quoteId: 42n,
quantityToClose: "0.5",
slippage: 1,
});useLimitCloseAuto
The LIMIT-close variant — same one-line shape, but the caller passes a resting price (no slippage) and the close is written as a pending close resting at that price instead of filling at mark. Majors / Rasa only; throws UNSUPPORTED_BY_SOLVER when the resolved solver has no limit support (gate with useSupportsLimitOrder). On success it invalidates the instant-closes feed so the resting close surfaces without a poll.
const close = useLimitCloseAuto();
close.mutate({
from: sessionKey,
partyA,
market: { id: 1 },
positionType: PositionType.LONG,
quoteId: 42n,
quantityToClose: "0.5",
price: "64000", // resting close price
});useInstantClose
Low-latency primitive — caller supplies the pre-resolved InstantCloseParameters. Pair with a staged prepareInstantCloseParams for fast closes.
const close = useInstantClose();
close.mutate(prepared);useInstantCloseBulk / useInstantCloseBulkAuto
Close up to 100 positions in one solver call. Auto fetches metadata per order; the primitive expects pre-resolved bags.
const bulk = useInstantCloseBulkAuto();
bulk.mutate({
from: sessionKey,
orders: [
{
partyA: vaA,
market: { id: 1 },
positionType: PositionType.LONG,
quoteId: 42n,
quantityToClose: "0.5",
slippage: 1,
},
{
partyA: vaB,
market: { id: 2 },
positionType: PositionType.SHORT,
quoteId: 43n,
quantityToClose: "1.0",
slippage: 1,
},
],
});mutation.data is { count, success: true } once the solver accepts the batch. A solver rejection fails the whole batch; retry with fewer orders.
Delegation preflight
Every close hook — useInstantCloseAuto, useLimitCloseAuto, useInstantClose, the bulk pair, and useCloseQuoteGroup — checks before signing that the key holds the requestToClosePosition delegation, on the VA’s parent sub-account. A key without it fails with a SymmioRequestError whose code is INSTANT_SIGNER_NOT_DELEGATED, before anything is signed or sent (a group close reports it in its summary’s error). Pass preflightDelegation: false when your UI already gates the close on delegation. See Delegation preflight.
Fees at close
Instant Open defers close fees — the open funds only its open-side legs, so the close fees are charged here, at close, by the contract collecting them from the position. Three legs:
- Platform close fee — taken from the position’s allocated balance after PnL settlement.
- Solver close fee — priced by the position’s real holding time (the time-decaying rate that starts at the early rate and decays to the standard rate), and capped by the
closeRateCapthe quote signed at open. A longer hold pays less. - Static close fee — the flat USD close amount from the solver’s
useSolverInfo(charged on each partial close too).
Liquidation charges no fees — these close fees are collected only on a user-initiated close, not on liquidation.
Preview these legs with useInstantCloseFees — it prices the platform leg, the holding-time solver leg, and the static leg from cached reads (markets, useFeeForUser, useSolverInfo, the shared price stream), re-stamping the holding time on every refetch so the decaying rate stays honest. Feed it the position’s createTimestamp as openedAt; omit it for the worst case. The low-level pieces it composes (calculateSolverCloseFee, useSolverInfo) stay available, but the hook is the intended surface. Core detail: getInstantCloseFees. The open-side preview (useInstantOpenFees) deliberately covers only the legs the open funds.
Related
- Core Instant Close — three-function split.
useInstantCloseFees— preview the close-fee legs before submitting.- Instant Open — the open-side analog.
- Unified Quotes — close-side lifecycle transitions live in
applyNotificationToQuotes.