Part 2: trading
Part 2: Trading
From here every action is signed by your session key, submitted through the SDK to the Enigma solver, and confirmed over the notifications WebSocket. You never prompt the Owner wallet again.
Load markets and stream prices
import { getMarkets, watchEnigmaPrices } from "@symmio/trading-core";
const markets = await getMarkets(config);
const unwatch = watchEnigmaPrices(config, {
onPrices: (ticks) => {
for (const tick of ticks) {
// tick.name is the price-service symbol name — NOT the display symbol
console.log(tick.name, tick.markPrice, tick.time);
}
},
onStatusChange: (s) => console.log("price stream:", s),
onError: (e) => console.error(e),
});Enigma is both your solver and your price feed on HyperEVM. Prices key on
SymbolContractSymbol.name, which can differ from the display symbol. Passmarket.name(not the ticker) when you open, or mark-price lookups fail silently.
Open a position
instantOpenAuto is the one-call orchestrator: it prepares parameters and submits in a single step. Internally it resolves the trade into an InstantOpenParameters bag (requestedOpenPrice, quantity, cva, lf, partyAmm, partyBmm, notional, addMargin, all 18-decimal bigint), signs it EIP-712, and POSTs it to the Enigma solver at https://solver.enigma.bz/api/instant_trade/instant_open. You never hand-build that body; you just pass the inputs below.
The call returns a negative tempQuoteId, a placeholder the solver issues until the trade anchors on-chain.
Confirm the fill
The open is two-phase. Watch notifications for the on-chain quoteId, then reconcile it against your optimistic tempQuoteId record.
Attach take-profit / stop-loss
Set TP/SL against the Virtual Account for the position (the SDK resolves the predicted VA for you). Confirm via the TP/SL notification stream, not the POST response.
Close a position
Close against the on-chain quoteId. instantCloseAuto handles the whole flow, and quantityToClose lets you close partially.
That's the full loop: stream prices, open, confirm, manage with TP/SL, close. For headless bots this is all of @symmio/trading-core. For a UI, the same steps have React hooks (useInstantOpenAuto, useInstantCloseAuto, useSetQuoteTpSl, useManagedQuotes).
Last updated

