watchNotifications
Subscribe to live position/quote state notifications for one account.
Opens (or reuses) one reconnecting socket to the chain’s notifications endpoint, sends the subscribe frame on every (re)connect, normalizes inbound frames into Notifications, and invokes your handlers. Watchers sharing the same endpoint and account share one socket; it closes when the last one unwatches.
This is a subscribe function, not a query — there are no query options. For a React binding, use the useNotifications hook.
import { watchNotifications } from "@symmio/trading-core";
const unwatch = watchNotifications(config, {
account: "0xaccount...",
onNotification: (n) => console.log(n.type, n.quoteId),
onStatusChange: (status) => console.log(status),
onError: (err) => console.error(err),
});
// later, dispose (idempotent):
unwatch();Parameters
accountAddressrequiredSubAccount address to subscribe for.
chainIdnumberoptionalTarget chain id. Defaults to the config’s defaultChainId.
Called for every normalized notification frame.
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.
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 or no WebSocket implementation is available.
Related
- WebSocket concept — pool, reconnect, and the
SocketStatuslifecycle. - searchNotifications — REST history over the same channel.