Make your first Exchange API call in under 5 minutes.
This guide walks you through verifying the service, listing markets, submitting your first order, and connecting to the WebSocket for live market data.
You need an API key to place orders and view account state. An operator must provision your trader account. If you don’t have a key yet, ask your exchange operator.
If status is "degraded", the persistence backend is unhealthy (retrying, backpressured, or stopped). Trading continues in memory, but data may not be fully persisted.
2
List available markets
Discover which markets are configured and their trading parameters.
Note the tick_size and min_order_quantity for each market — your order price must be a multiple of tick_size and quantity must be at least min_order_quantity.
3
Submit your first order
Place a limit buy order for 2 units of BTC-USD at price 100.
The ?market=BTC-USD query parameter is optional — omit it to see all markets.
5
Connect to WebSocket and subscribe to market data
Subscribe to live L3 orderbook updates.
const socket = new WebSocket("wss://exchange.jamesxu.dev/ws");socket.addEventListener("open", () => { // Subscribe to L3 orderbook for BTC-USD socket.send(JSON.stringify({ op: "subscribe", channel: "l3", market: "BTC-USD", last_sequence: null, }));});socket.addEventListener("message", (event) => { const msg = JSON.parse(event.data); switch (msg.type) { case "snapshot": // Full orderbook state — initialize your local book console.log("Snapshot:", msg.sequence, msg.bids, msg.asks); break; case "delta": // Incremental update — apply to local book console.log("Delta:", msg.sequence, msg.events); break; case "resync_required": // Gap detected — resubscribe for a fresh snapshot console.warn("Resync required:", msg.reason); socket.send(JSON.stringify({ op: "subscribe", channel: "l3", market: "BTC-USD", last_sequence: null, })); break; case "heartbeat": // Keep-alive — no action needed break; }});
You receive one snapshot message immediately after subscribing, followed by delta messages for every subsequent change. Always track the sequence number and resubscribe if you receive resync_required.
6
Authenticate on WebSocket and receive order events
Authenticate your WebSocket session to enable trading and receive user-scoped events.
const socket = new WebSocket("wss://exchange.jamesxu.dev/ws");socket.addEventListener("open", () => { // Authenticate first socket.send(JSON.stringify({ op: "authenticate", api_key: process.env.EXCHANGE_API_KEY, })); // Market data subscription (can be sent before or after auth) socket.send(JSON.stringify({ op: "subscribe", channel: "l3", market: "BTC-USD", last_sequence: null, }));});socket.addEventListener("message", (event) => { const msg = JSON.parse(event.data); switch (msg.type) { case "authenticated": console.log("Authenticated as", msg.username); // Now submit an order via WebSocket socket.send(JSON.stringify({ op: "submit_order", request_id: "req-1", market: "BTC-USD", side: "BUY", price: 100, quantity: 2, })); break; case "ack": console.log("Order acknowledged:", msg.request_id); break; case "reject": console.error("Order rejected:", msg.code, msg.message); break; case "fill": console.log("Fill received:", msg.fill); break; case "order_state": console.log("Order state update:", msg.order, msg.status); break; case "admin_message": console.log("[Admin]", msg.message.title, msg.message.body); break; }});
Using WebSocket for order entry gives you real-time fill and order_state events pushed directly to your client without polling.