Live gold prices over WebSocket

Get prices as they change instead of polling. On connect the stream sends every price, then only the ones that changed, at most once a second.

Last updated:

Connecting and quota

Pro and Business plans can open a plain WebSocket to wss://api.pixcharp.com/v1/stream. Authenticate with the same API key as REST. You get all prices in one snapshot message on connect. After that, as prices change, you get at most one prices message a second with the latest value of every symbol that changed in that second. Each snapshot and prices message uses 1 request of your monthly quota; ping, pong, error and subscribed are free, and seconds with no change cost nothing. REST calls and all open connections share the quota. The connection handshake also counts toward the per-minute limit.

// Install: npm install ws
import WebSocket from "ws";

const ws = new WebSocket("wss://api.pixcharp.com/v1/stream", {
  headers: { "X-API-Key": process.env.PIXCHARP_API_KEY },
});

ws.on("open", () => {
  // Optional: only the symbols you need. [] or ["*"] restores all.
  ws.send(JSON.stringify({ type: "subscribe", symbols: ["HAS", "USDTRY"] }));
});

ws.on("message", (raw) => {
  const message = JSON.parse(raw.toString());
  if (message.type === "snapshot") console.log(message.data.length, "symbols");
  if (message.type === "prices") for (const row of message.data) console.log(row.symbol, row.satis);
});

Messages

Messages
// On connect, and again after "subscribe"
{"type":"snapshot","asOfUtc":"2026-11-14T10:24:13Z","market":"open","data":[{"symbol":"HAS","alis":6127.46,"satis":6155.99,...}]}

// As prices change, at most once a second (1 request of quota)
{"type":"prices","asOfUtc":"2026-11-14T10:24:14Z","data":[{"symbol":"USDTRY","alis":41.1,"satis":41.2,"asOfUtc":"2026-11-14T10:24:14Z","source":"harem","stale":false}]}

// Every 30 seconds (no reply needed)
{"type":"ping","ts":"2026-11-14T10:24:43Z"}

// A bad client message; the connection stays open
{"type":"error","code":"invalid_symbol","message":"..."}

Connection errors

HTTPCodeMeaning
400websocket_requiredThe request was not a WebSocket upgrade.
403websocket_not_includedYour plan has no WebSocket connections (Starter).
403ip_not_allowedThe address is not on your IP whitelist.
429websocket_connection_limitAll connections of your plan are open. Connections from all keys count together.
429monthly_quota_exceededYour monthly quota is used up. New connections are refused until it resets on the 1st (UTC).

Connection checks and reconnecting

Open connections are re-checked every 60 seconds. If the key is revoked, the plan changes, the address leaves the whitelist or the monthly quota runs out, the server sends an error message and closes with code 1008. While the market keeps moving, one always-open connection lasts about 11 days on Pro and the whole month on Business. Reconnect with backoff after any close.