Endpoint
All WebSocket connections go to a single endpoint:Authentication
You authenticate at connection time by passing your API key in the HTTP upgrade request. The server validates the key before completing the WebSocket handshake — no separate auth message is needed after connecting. Pass your key using either of these headers:| Header | Format |
|---|---|
Authorization | Bearer YOUR_API_KEY |
X-API-Key | YOUR_API_KEY |
ws:connect scope in addition to any channel-specific scopes. If the key is missing or invalid, the connection is rejected with close code 4401. If the key lacks the required scopes, it is rejected with close code 4403.
API keys are managed in your account at app.stratalerts.com. Each key is issued with a specific set of scopes — if you cannot connect or subscribe to a channel, check that your key includes the required scope.
One connection per account
Each account may have only one active WebSocket connection at a time. If you open a second connection while an existing one is live, the server evicts the older connection by closing it with code4409 before completing the new handshake. The new connection then proceeds normally.
Design your client to handle close code 4409 as a signal that it was replaced — typically this means you should not attempt to reconnect immediately, since a newer instance of your application is already connected.
Message envelope
Every message the server sends — including acknowledgments and data events — uses the same JSON envelope:| Field | Type | Description |
|---|---|---|
type | string | Event type (e.g. quote, alert.in_force, subscribed) |
ts | string | ISO 8601 server timestamp for this message |
seq | string | Monotonically increasing integer string; increments for every message sent on this connection |
data | object | Event-specific payload |
seq field is a string representation of an integer that starts at 1 and increments with each message. You can use it to detect dropped messages if you are logging or buffering events.
Subscribing to channels
After the connection is established, send a subscribe message to begin receiving events from one or more channels:subscribed acknowledgment listing the channels it accepted:
quotes, states) are subscribed per symbol. Channels that are account-wide (alerts.in_force, alerts.simultaneous_breaks) do not take a symbols list — once subscribed, you receive all events globally.
If your key is missing the scope for a channel, that channel is silently omitted from the acknowledgment. Check the
channels array in the response to confirm which subscriptions were accepted.Unsubscribing
Send the same message format with"op": "unsubscribe" to stop receiving events from specific channels or symbols:
unsubscribed acknowledgment in the same envelope format.
Close codes
| Code | Meaning |
|---|---|
4401 | No API key provided or key could not be resolved |
4403 | API key is valid but the account is not entitled or the key is missing the ws:connect scope |
4409 | Connection evicted — a new connection was opened for this account and replaced this one |
Reconnection
WebSocket connections can drop due to network interruptions, server restarts, or idle timeouts. Implement reconnection with exponential backoff in your client, and re-subscribe to all channels after each successful reconnect. A basic backoff strategy:- Start with a 1-second delay after the first disconnect
- Double the delay on each failed reconnect attempt
- Cap the delay at 60 seconds
- Reset the delay counter after a successful reconnect
Complete examples
The examples below show a full connect → subscribe → receive loop. ReplaceYOUR_API_KEY with your actual key.
Related
Channels
Full reference for all four channels: required scopes, symbol subscriptions, and example event payloads.
Authentication
How to obtain an API key, understand scopes, and pass credentials in requests.