Knowledge Base/How can I connect to a Massive WebSocket?

How can I connect to a Massive WebSocket?

Open a socket to the cluster for the asset class you subscribe to, send an auth message with your API key, then send a subscribe message naming the channels and tickers you want. The server answers each step with a status message.

The order is what trips people up on a Massive WebSocket. A subscribe sent before the auth message is answered with auth_failed, naming an authentication problem even though the key was never sent, so a client that pipelines the two ends up re-copying a key that was fine. Wait for each reply: reading the three status messages is the fastest way to find what went wrong.

Applies to

  • Plans: every paid subscription. Basic, the free tier, has no WebSocket access.
  • Feeds: wss://socket.massive.com/stocks, /options, /indices, /futures, /forex and /crypto. One socket talks to one cluster.
  • Asset classes: stocks, options, indices, futures, forex and crypto.

How to connect

  1. Open a socket to the cluster you need. The connection is accepted before any authentication, and the server greets you:
[{"ev":"status","status":"connected","message":"Connected Successfully"}]
  1. Send your key. Your key is on the keys page of the dashboard.
{"action":"auth","params":"KEY"}

Response

[{"ev":"status","status":"auth_success","message":"authenticated"}]
  1. Subscribe. A parameter is a channel and a ticker joined by a dot, and you can pass a comma-separated list or * for every ticker on that channel.
{"action":"subscribe","params":"T.AAPL,Q.MSFT"}

Response

[{"ev":"status","status":"success","message":"subscribed to: T.AAPL"},{"ev":"status","status":"success","message":"subscribed to: Q.MSFT"}]

One status object comes back per parameter, in one array, so a parser that reads only the first element will miss the rest. Data messages start arriving straight after the acknowledgement, each one a JSON array that often carries several events.

Which channel names to use

Channel names are per cluster, and using another cluster's name is the most common reason a subscribe is refused. The WebSocket documentation lists every channel; these are the ones asked about most:

ChannelClusterWhat it carries
Tstocks, options, futuresIndividual trades
Qstocks, options, futuresQuotes
Astocks, options, indices, futuresPer-second aggregate bars
AMstocks, options, indices, futuresPer-minute aggregate bars
XT, XQcryptoTrades and quotes
XAS, XAcryptoPer-second and per-minute aggregate bars
CforexQuotes. Forex has no trade feed
CAS, CAforexPer-second and per-minute aggregate bars
VindicesIndex values

Why the order matters

The order matters because the server tracks a connection's state. A subscribe sent before the auth message is answered with auth_failed and the socket is closed, even though the key was never sent, so wait for auth_success rather than pipelining the two. Authenticating twice on one socket is not how you add a second stream either: one socket carries as many subscriptions as you like, so subscribe again on the same socket instead of opening another. Opening another socket spends one of your connections, and if that takes you over your plan's allowance for that cluster, one of the two connections is closed.

If you see an error

{"ev":"status","status":"auth_failed","message":"authentication failed"} means either the key was rejected or a subscribe arrived before the auth message. The server closes the socket either way. Check the order first, because a client that sends both messages without waiting for auth_success produces this frame with a perfectly good key.

{"ev":"status","status":"error","message":"not authorized"} in reply to a subscribe means either your plan does not cover that feed, or you used a channel that exists on another cluster but not this one. A on the crypto cluster gets this, because crypto uses XAS.

Nothing at all after auth_success is the other failure, and it is quieter. A channel name that exists nowhere, or a channel from the wrong cluster that we do not recognize at all, is not acknowledged and not refused: the server simply says nothing. If a subscribe gets no reply, check the spelling against the table above rather than waiting.

Related


Was this article helpful?

Modernizing Wall St.

Reimagining financial market data for the 21st century.

Schedule a demo

Talk with our market data experts

Recommended

Can't find the answer you're looking for? Contact our team.
  • Title
    Are all indices available through the basic subscription tier?
    Data Coverage Category

    Data Coverage

    Indices Category

    Indices

    Description
    No, and the ones it withholds are the famous ones: SPX, DJI, RUT and VIX all need a paid Indices tier. Basic still reaches more than 10,000 of the 13,000-odd indices Massive publishes, and NDX and the Nasdaq Composite are among them.
  • Title
    Does Massive offer dark pool data?
    Data Coverage Category

    Data Coverage

    Stocks Category

    Stocks

    Description
    Yes. Off-exchange prints, which include dark pool executions, arrive on the ordinary trades feed and are identified by an exchange ID of 4. There is no separate dark pool endpoint, and no way to tell which individual venue a print came from.
  • Title
    Does Massive offer pre-market and after-hours data?
    FAQ Category

    FAQ

    Stocks Category

    Stocks

    Description
    Yes. Every extended-hours trade and quote is published, from 04:00 to 20:00 Eastern. There is no session parameter, so you select a session with timestamps, and expect far fewer aggregate bars outside regular hours because many extended-hours trades are odd lots that cannot set a price.