Connect

A connection is a normal WebSocket handshake with your API key. The server checks the key, your plan and your connection limit before it accepts the connection.


Endpoints

StreamURL
Enrichedwss://wss.finlight.me
Rawwss://wss.finlight.me/raw

You choose the payload version later, in the subscribe message. The URL is the same for v2 and v3.


WEBSOCKETwss://wss.finlight.me

Connection request

Send these values as HTTP headers on the handshake. Each one also works as a query parameter. Use the query parameter only where you cannot set headers, for example in a browser, because the key then ends up in URLs and logs.

  • Name
    x-api-key
    Type
    header
    Description

    Your API key. Required. The header name must be lowercase: the server looks it up case-sensitively, so X-API-KEY or X-Api-Key is treated as missing and refused with 401. Some HTTP libraries change the case of header names (for example Go's Header.Set), so set the raw header. Query parameter: apiKey.

  • Name
    x-takeover
    Type
    header
    Description

    Optional. true replaces your stalest connection when you are at your connection limit. Without it the new connection is refused. Query parameter: takeover=true.

  • Name
    x-client-version
    Type
    header
    Description

    Optional. A free text label for your client, for example my-app/1.4.0. It is stored for support and has no effect on behaviour. Query parameter: clientVersion.

When the server accepts the connection, nothing is sent yet. The first frame comes after your first message. See Subscribe.

Connect

WEBSOCKET
wss://wss.finlight.me
npx wscat -c wss://wss.finlight.me -H "x-api-key: YOUR_API_KEY"
# then type the subscribe message:
# {"payloadVersion":3,"query":"ticker:AMD","language":"en"}

Refused connections

If the server refuses the connection, the handshake fails with an HTTP status instead of 101 Switching Protocols. The body is a small JSON object. Many WebSocket libraries show only the status, and browsers show neither (the socket just closes with code 1006).

StatusBodyCauseWhat to do
401{"error":"Missing API-KEY"}No key, or the header name was not lowercase.Fix the request. Do not retry.
401{"message":"Invalid API key"}The key does not exist or was revoked.Use a valid key. Do not retry.
401{"message":"Invalid API key format"}The value is not shaped like a finlight key.Use a valid key. Do not retry.
403{"message":"Your subscription does not include WebSockets"}Your plan has no WebSocket access.Upgrade your plan. Do not retry.
403{"message":"Too many concurrent connections. Use x-takeover: true header to replace an existing connection."}You are at your connection limit.Close a connection, wait at least 60 s before you retry, or connect with takeover.
403{"message":"WebSocket quota exceeded for the current period"}The WebSocket delivery quota of this period is used up.Wait for the next period. Retrying once per hour is enough.
403{"message":"Too many concurrent connections"}Two connections of yours were admitted at the same moment and this one lost.Retry after a short, growing wait.
500{"error":"Internal server error"}A server problem.Retry after a short, growing wait.

A refused key or a plan without WebSockets is remembered for about 60 seconds. If you just fixed your key or upgraded your plan, a new connection can still be refused for up to a minute.

See Unauthorized and Forbidden for how the client libraries report these.


Connection limit

Your plan allows a fixed number of parallel WebSocket connections.

  • The limit is shared by the enriched stream, the raw stream and connections from older client library versions (v2). Do not run an old and a new client side by side when your limit is small.
  • A connection that has not sent a ping for more than 60 seconds is treated as stale and no longer counts against the limit. Ping every 25 seconds to keep yours counted as live. See Lifecycle & limits.
  • With takeover, the server replaces the connection that counts against your limit and has gone longest without a ping. That connection receives connection.preempted with reason connection_limit and the newLeaseId of the new connection, and is then closed. See Frames.
  • Without takeover, the new connection is refused with 403 while you are at the limit.

Lifetime

A connection lives at most 2 hours. After 10 minutes without any message in either direction, it is closed. Plan for both. See Lifecycle & limits for rotation and reconnects.