Instant Open hooks
React hooks over the core Instant Open flow. The three-function split (prepare / submit / auto) applies here too — pick based on how much control you want.
The page is split into two groups:
- Reads — pending queue reads (
useInstantOpens,useInstantOpenQuoteId). - Writes — the three-function open path (
useInstantOpenAuto,useInstantOpen) plus the composed orchestrator (useInstantOpenWithTpSl).
Import
import {
useInstantOpen,
useInstantOpenAuto,
useInstantOpenWithTpSl,
useInstantOpens,
useInstantOpenQuoteId,
} from "@symmio/trading-react";Reads
useInstantOpens
Paginated list of the solver’s pending instant-opens for a SubAccount. useManagedQuotes consumes this internally.
const pending = useInstantOpens({ account: subAccount, offset: 0n, size: 20n });useInstantOpenQuoteId
Resolve the on-chain quoteId for a given tempQuoteId. useManagedQuotes and the notification handlers use this to link rows.
const quoteId = useInstantOpenQuoteId({ tempQuoteId: -1001 });Writes
useInstantOpenAuto
The default — one-line orchestrator. Runs prepareInstantOpenParams inline (fetches market metadata, mark price, locked params, fee rates) then signs and POSTs.
const open = useInstantOpenAuto();
<Button
disabled={open.isPending}
onClick={() =>
open.mutate({
from: sessionKey,
subAccountAddress: subAccount,
market: { id: 1 },
positionType: PositionType.LONG,
initialMargin: "100",
leverage: 5,
slippage: 1,
})
}
>
{open.isPending ? "Opening…" : "Open"}
</Button>;Latency: prepare fetches run inline, so click → sign gap includes the network hop. Fine for most flows; see useInstantOpen below for the low-latency variant.
useInstantOpen
Low-latency primitive — the caller supplies the fully-resolved InstantOpenParameters bag. Pair with a pre-resolved prepareInstantOpenParams call staged earlier (on trade-panel mount) so the critical path is just sign + POST.
const prepare = usePrepareInstantOpenParamsCached(uiInputs); // your own hook
const open = useInstantOpen();
// user clicks Open — no fetches on the critical path
open.mutate(prepare.data);useInstantOpenWithTpSl
Orchestrator that opens a position and immediately attaches TP/SL against the returned tempQuoteId. Two mutations chained under the hood:
instantOpenAuto→ returnstempQuoteId.setQuoteTpSlwithquoteId: tempQuoteId→ creates the conditional-order legs.
const open = useInstantOpenWithTpSl();
open.mutate({
...instantOpenInputs,
tpsl: hasTpOrSl
? {
from: sessionKey,
virtualAccount: predictedVa,
subAccount,
symbolId,
positionType,
quantity,
pricePrecision,
tp: tpInput,
sl: slInput,
}
: undefined,
});On success, useTpSlStore is populated with the confirming record keyed by tempQuoteId. When the position anchors on-chain, the solver maps tempQuoteId ↔ quoteId and the same TP/SL record is reachable by either id.
See TP/SL for the store + reconciliation model.
Related
- Core Instant Open — the three-function split explained.
- TP/SL —
useInstantOpenWithTpSlcomposes over these. - Unified Quotes —
useManagedQuotesreconciles the pending list with on-chain reads + notifications.