watchEnigmaPrices
Subscribe to the chain’s Enigma lowcap price-service WebSocket and receive live mark-price ticks.
The endpoint is broadcast-only — there is no subscribe message; every connected client receives the same ticks. The service pushes batches of EnigmaPriceTick — your onPrices handler is called once per push with every market that ticked. Watchers sharing the same wsUrl share one underlying socket (pooled per wsUrl); it reconnects with exponential backoff and closes only when the last watcher unwatches.
This is a subscribe function, not a query — there are no query options. For a React binding, use the useEnigmaPrices hook.
import { watchEnigmaPrices } from "@symmio/trading-core";
const unwatch = watchEnigmaPrices(config, {
onPrices: (ticks) => {
for (const tick of ticks) {
console.log(tick.name, tick.markPrice, tick.time);
}
},
onStatusChange: (status) => console.log("status:", status),
onError: (err) => console.error("prices error:", err),
});
// later, dispose (idempotent):
unwatch();Parameters
Called for every parsed batch of price ticks.
onStatusChange(s: SocketStatus) => voidoptionalCalled whenever the underlying connection status changes. SocketStatus is "connecting" | "open" | "reconnecting" | "closing" | "closed".
onError(e: SymmError) => voidoptionalCalled on a transport or parse error; does not stop the subscription.
chainIdnumberoptionalTarget chain id. Defaults to the config’s defaultChainId.
Returns
UnwatchCall to stop the subscription; idempotent. The pooled socket closes when the last watcher releases.
Throws
Throws a SymmError synchronously when the chain is unsupported, has no priceService.wsUrl configured (PRICES_WS_NOT_CONFIGURED), or no WebSocket implementation is available. Per-frame parse and transport failures surface on onError as a SymmError (PRICES_SOCKET_ERROR) and do not stop the subscription.
Related
- WebSocket streams — pool, reconnect, and the
SocketStatuslifecycle. - EnigmaPriceTick — the shape delivered to
onPrices. - getEnigmaPriceServicePricesByAddresses — one-shot REST alternative when you don’t need a live stream.