Use this file to discover all available pages before exploring further.
ExchangeClient is the single entry point for all interactions with the Proof Exchange. It handles Ed25519 key management, timestamp-nonce allocation, chain ID resolution, signed transaction encoding, and every read endpoint exposed by the Go API server and CometBFT RPC layer. Instantiate once, load a private key, and call the appropriate method group.
Returns the hex-encoded owner address (without a 0x prefix), or null if no key has been set. This string is accepted by every query endpoint that takes an addressHex parameter.
Pre-warms the chain ID resolution cache. The client resolves its chain ID lazily on the first submitTx call; calling ready() at startup surfaces /status-fetch errors during initialization rather than mid-flow.This method is optional — submitTx resolves the chain ID automatically — but recommended for production code where you want to fail fast.
const client = new ExchangeClient();await client.ready(); // throws here if /status is unreachableclient.setPrivateKey(privateKey);
The client exposes two submission modes. Both submit the same V3 signed MessagePack envelope; they differ only in how long they wait and what they return.
Block height at which the transaction was included. Only populated by submitTxCommit and the background DeliverTx verifier after inclusion is confirmed.
Signs and broadcasts a transaction, returning as soon as CometBFT’s CheckTx (or the gateway) responds. On code === 0 a background verifier is spawned that polls /tx?hash=... for up to 5 seconds to capture the DeliverTx result. Collect those results with awaitPendingVerifies.This is the preferred high-throughput path. The timestamp nonce is allocated automatically.
import { Side } from "@proof/trading-sdk";const result = await client.submitTx({ type: "PlaceOrder", data: { market: 1, owner: client.getAddress()!, side: Side.Buy, price: 50_000_000n, // $500,000.00 in cents quantity: 1n, postOnly: true, },});if (result.code !== 0) { console.error(`Order rejected: [${result.code}] ${result.log}`);}
Resolves after CheckTx with code === 0 for acceptance or a non-zero code for rejection. height is not set — use submitTxCommit or awaitPendingVerifies if you need confirmed inclusion.
Submits a transaction and synchronously polls /tx?hash=... until block inclusion is confirmed or the 9-second deadline is reached. Returns the DeliverTx result including height and events.Use this when downstream logic depends on the transaction’s on-chain effect (e.g. open a position, then immediately query account).
Waits for all in-flight background DeliverTx verifiers (spawned by prior submitTx calls) to settle, then returns the collected results. The internal buffer is drained on each call — subsequent calls return only results that completed after the previous drain.Call this before issuing a transaction that depends on a previous transaction’s state having landed.
// Submit a batchfor (const order of orders) { await client.submitTx({ type: "PlaceOrder", data: order });}// Wait for all to landconst deliveryResults = await client.awaitPendingVerifies();const failed = deliveryResults.filter((r) => r.code !== 0);if (failed.length > 0) { console.warn(`${failed.length} orders failed at inclusion`, failed);}
All read methods call the Go API server at apiUrl. The addressHex parameter is optional on most methods — when omitted the client uses the address derived from the loaded private key.
Returns a one-round-trip market summary bundling 24-hour statistics, funding data, and top-of-book in a single response. Returns null for unknown market IDs.
Returns the auto-deleveraging queue for a market — profitable positions sorted by adlScore descending (highest-risk first). Use the position’s rank index divided by the total entry count to compute a per-position ADL percentile.
Looks up a withdrawal record by its engine-assigned ID. Returns null for unknown IDs (the engine encodes “not found” as MessagePack nil, not HTTP 404).
Returns the withdrawal lifecycle log for an address — covering withdraw_requested, withdrawal_confirmed, and withdrawal_failed events, newest first. Filter by kind client-side to show only pending requests.
Returns point-in-time position snapshots written after each fill that changes a position. A row with size === "0" is a close event. Results are newest first.
Opens a WebSocket connection to the CometBFT node (at wsUrl) and delivers NewBlock and Tx events to the callback. The connection reconnects automatically with exponential backoff (2s → 4s → … capped at 60s with ±25% jitter) if it closes unexpectedly.Multiple calls register multiple listeners on the same underlying socket. Returns an unsubscribe function that removes the specific listener; the socket is kept open while any listener remains.
const unsubscribe = client.subscribeBlocks((event) => { const type = (event as { type?: string }).type; if (type === "TradeExecuted") { console.log("Trade:", event); } if (type === "NewBlock") { const block = event as { value?: { block?: { header?: { height?: string } } } }; console.log("New block:", block.value?.block?.header?.height); }});// Later, remove this listener:unsubscribe();
Callback invoked for every NewBlock and Tx event received over the WebSocket. The event object is the result.data field of the CometBFT subscription message.
An unsubscribe function. Call it to remove this listener. If no listeners remain after unsubscribing, the WebSocket reconnect timer is left active until disconnect() is called.
Closes the WebSocket connection and cancels any pending reconnect timer. Call this when the client instance is no longer needed to avoid background reconnection loops.