Offset pagination is not snapshot-consistent — records can shift between pages while you're iterating. Track a stable identity when duplicate records must fail loudly:
Code
const seen = new Set<string>();for (const position of positions) { const key = `${position.instrumentId}:${position.outcome}`; if (seen.has(key)) throw new Error(`Duplicate position: ${key}`); seen.add(key);}
Lossless Decimal Math (decimal)
To prevent IEEE-754 floating-point inaccuracies in financial calculations (e.g. 0.1 + 0.2 !== 0.3), the SDK includes a built-in, zero-dependency decimal utility powered by native BigInt scaling:
The SDK supports TypeScript 5.2+ explicit resource management (Symbol.dispose and Symbol.asyncDispose) for automatic cleanup of sockets, streams, and order books:
Code
// Automatically closes client and active sockets when leaving scope{ await using client = await createClient({ env: "sandbox", auth }); const symbols = await client.marketData.listSymbols(); console.log(symbols); // Scoped WebSocket streaming const stream = client.websocket.public.trades("BTCUSD"); try { for await (const trade of stream) { console.log(trade); break; // stream is automatically unsubscribed & closed on break } } finally { await stream.close(); }} // client.close() is automatic; stream cleanup is explicit
Heartbeat
Keep a session alive with an explicit heartbeat. The heartbeat is stopped by default — you control its lifecycle:
The heartbeat sends a POST /v1/heartbeat request at the configured interval. It requires an authenticated client (HMAC or OAuth).
File responses
Some endpoints return binary files (XLSX, CSV) instead of JSON:
Code
const report = await client.marketData.getFundingAmountReportFile({ symbol: "BTCGUSDPERP",});// report.bytes: Uint8Array — the raw file content// report.contentType: string | undefined (e.g. "text/csv" or XLSX MIME type)// report.contentDisposition: string | undefined (Content-Disposition header)// Write to disk (Node.js)import { writeFileSync } from "node:fs";const ext = report.contentType?.includes("csv") ? "csv" : "xlsx";writeFileSync(`funding-report.${ext}`, report.bytes);
Prediction markets — terms acceptance
Prediction market order placement requires accepting the current terms. You can
check status proactively for UI, but the order endpoint is authoritative:
Code
// Check terms statusconst terms = await client.predictions.getPredictionMarketsTermsStatus();if (!terms.hasAcceptedLatest) { // Show terms to the user, get explicit consent, then: await client.predictions.acceptTerms();}// Now orders will workawait client.predictions.placeOrder({ /* ... */ });
If you skip this, the order endpoint returns AcceptTermsRequired. Handle that
response by showing the terms, obtaining consent, accepting them, and retrying.
Advanced client options
The full set of options available on createClient():
The SDK's REST and authentication layers run on runtimes with Web Crypto and
standard fetch. WebSocket support additionally requires a native WebSocket;
authenticated WebSockets require a socket factory that can set upgrade headers.
Runtime
Browser entry
Server entry
Notes
Node.js 22.4+
Yes
Yes
Full support; native WebSocket available
Bun
Yes
Yes
Full lossless integer support; authenticated WebSocket requires ws compatibility or a custom factory
Deno
Yes
Yes
Full lossless integer support; authenticated WebSocket requires ws compatibility or a custom factory
Cloudflare Workers
Yes
No
No ws package — browser entry only; full lossless integer support
Browsers
Yes
No
Public WebSockets only; OAuth PKCE authenticates REST, while private WebSockets require a server or relay
The server entry requires the ws peer dependency for authenticated WebSocket connections:
Code
npm install ws
ws is optional — if you only use REST endpoints with skipWsInit: true, you don't need it.
Closing the client
Always close the client when done to release WebSocket connections:
Code
const client = await createClient({ env: "sandbox", auth });try { // ... use the client} finally { client.close();}
close() shuts down all active WebSocket streams and the shared session. It does not cancel in-flight REST requests.
What's next
API Reference — all 106 operations across 10 REST namespaces, with code examples