Skip to content

Real-time Price Feed

SecurityPro offers a WebSocket API for streaming live market prices and trades.

  • URL (Prod): wss://api.securitypro.com/market/ws
  • Auth: API key in the subscribe frame (or query string if enabled by your org policy)
const ws = new WebSocket('wss://api.securitypro.com/market/ws');
ws.onopen = () => {
ws.send(JSON.stringify({
op: "subscribe",
channel: "trades",
symbol: "BTC-USD",
apiKey: process.env.API_KEY
}));
};
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
console.log(msg);
};
ws.onclose = () => {
// TODO: reconnect with backoff (see below)
};
import WebSocket from "ws";
const ws = new WebSocket("wss://api.securitypro.com/market/ws");
ws.on("open", () => {
ws.send(JSON.stringify({
op: "subscribe",
channel: "ticker",
symbol: "BTC-USD",
apiKey: process.env.API_KEY }));
});
ws.on("message", (msg) => {
const data = JSON.parse(msg.toString());
if (data.channel === "ticker") console.log("price:", data.price);
});
import json, websocket
def on_open(ws):
ws.send(json.dumps({
"op":"subscribe",
"channel":"ticker",
"symbol":"BTC-USD",
"apiKey": os.getenv("API_KEY") }))
def on_message(ws, message):
data = json.loads(message)
if data.get("channel") == "ticker":
print("price:", data.get("price"))
ws = websocket.WebSocketApp("wss://api.securitypro.com/market/ws",
on_open=on_open, on_message=on_message)
ws.run_forever()
import asyncio, json, os, websockets
async def main():
uri = "wss://api.securitypro.com/market/ws"
async with websockets.connect(uri) as ws:
await ws.send(json.dumps({
"op": "subscribe",
"channel": "trades",
"symbol": "BTC-USD",
"apiKey": os.getenv("API_KEY")
}))
async for raw in ws:
msg = json.loads(raw)
print(msg)
asyncio.run(main())
{
"op": "subscribe",
"channel": "trades",
"symbol": "BTC-USD",
"apiKey": "<YOUR_API_KEY>"
}
{
"type": "trade",
"symbol": "BTC-USD",
"price": "45000.12",
"size": "0.002",
"side": "buy",
"ts": "2025-08-17T14:25:31.125Z"
}
{
"type": "ticker",
"symbol": "BTC-USD",
"bid": "44995.00",
"ask": "45005.00",
"price": "45000.12",
"ts": "2025-08-17T14:25:31.125Z"
}
{ "type": "heartbeat", "ts": "2025-08-17T14:25:32.000Z" }

Send a pong if required by your org policy:

{ "type": "pong", "ts": "2025-08-17T14:25:32.100Z" }

If the socket closes, reconnect with exponential backoff (jitter recommended):

let ws;
let delay = 1000;
function connect() {
ws = new WebSocket('wss://api.securitypro.com/market/ws');
ws.onopen = () => {
delay = 1000;
ws.send(JSON.stringify({
op: "subscribe",
channel: "trades",
symbol: "BTC-USD",
apiKey: process.env.API_KEY
}));
};
ws.onmessage = (ev) => {
const msg = JSON.parse(ev.data);
console.log(msg);
};
ws.onclose = () => {
const jitter = Math.floor(Math.random() * 250);
setTimeout(connect, delay + jitter);
delay = Math.min(delay * 2, 30000);
};
ws.onerror = () => ws.close();
}
connect();
Terminal window
# WebSocket quick test (requires wscat: npm i -g wscat)
wscat -c wss://api.securitypro.com/market/ws
# then paste:
# {"op":"subscribe","channel":"trades","symbol":"BTC-USD","apiKey":"<API_KEY>"}
curl -X GET "$API_BASE/v1/market/ticker?symbol=BTC-USD" \
-H "X-API-Key: $API_KEY"

Tip: For WS, handle heartbeats and reconnect with backoff.
For high-throughput feeds, batch updates before UI render.

  • REST returns { "symbol": "BTC-USD", "price": "…", "ts": "…" }
  • WS delivers continuous trade/ticker messages
  • Example frame:
    { "channel": "trades", "symbol": "BTC-USD", "price": "45000.12", "size": "0.005", "side": "buy" }