Q4API Docs
Q4 APISign inGet API key
DocumentationAPI Reference
Overview
IntroductionQuickstartData overviewPlans and limits
Datasets
CompaniesMarket dataRealtime & streamingFundamentalsDividends & corporate actionsFilings & reportsBoard reportsPresentationsEarnings callsAnnouncementsEconomic data
REST API
AuthenticationPagination and filteringRate limitsErrors
WebSocket
ConnectingStreamsWebSocket errors
Webhooks
WebhooksWebhook eventsSignatures
MCP
Q4 MCP connector
More
ChangelogSupport
WebSocket

Connecting

Open a WebSocket, subscribe to symbols and keep the connection alive.

The WebSocket pushes live data as it changes, so you don't need to poll. It needs Pro+.

Connect

Pass your key as the api_key query parameter:

const ws = new WebSocket("wss://api.q4.sa/v1/ws/stocks?api_key=" + process.env.Q4_API_KEY);

ws.onopen = () => {
  ws.send(JSON.stringify({ action: "subscribe", symbols: ["2222", "1120"] }));
};

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type === "quote") console.log(msg.symbol, msg.price);
};
import asyncio, json, os, websockets

async def main():
    url = "wss://api.q4.sa/v1/ws/stocks?api_key=" + os.environ["Q4_API_KEY"]
    async with websockets.connect(url) as ws:
        await ws.send(json.dumps({"action": "subscribe", "symbols": ["2222", "1120"]}))
        async for raw in ws:
            msg = json.loads(raw)
            if msg["type"] == "quote":
                print(msg["symbol"], msg["price"])

asyncio.run(main())

Actions

ActionBodyWhat it does
subscribe{ "action": "subscribe", "symbols": [ … ] }Start receiving data for these symbols.
unsubscribe{ "action": "unsubscribe", "symbols": [ … ] }Stop.
snapshot{ "action": "snapshot", "symbols": [ … ] }Send the current state once.
ping{ "action": "ping" }Replies { "type": "pong" }.

Staying connected

  • The server sends a ping frame every 30 seconds. Most clients answer it automatically.
  • Connections are closed for maintenance about once a day. Reconnect with exponential backoff and subscribe again.
  • Outside trading hours the connection stays open but quiet.

Limits

PlanConnectionsSymbols per connection
Pro260
Business5120
EnterpriseCustom200, or * for the whole market
← Previous
Errors
Next →
Streams
On this page
ConnectActionsStaying connectedLimits