Knowledge Base/What is the difference between RESTful APIs and WebSockets?

What is the difference between RESTful APIs and WebSockets?

A REST call asks Massive one question and gets one answer, so it suits history and snapshots. A WebSocket holds one connection open and pushes every new event as it happens, so it suits live data. Both cover the same asset classes and use the same API key.

The difference between Massive's RESTful API and its WebSockets is who starts each exchange. With REST you send a request and get one response, which suits history, reference data and a point-in-time snapshot. With a WebSocket you hold one connection open and we push every new event to you as it happens, which suits live data. Both cover the same asset classes and authenticate with the same API key, so the choice is about the shape of the question rather than about access.

Applies to

  • Plans: REST is on every plan including the free Basic tier; WebSockets need a paid subscription.
  • Endpoints or feeds: https://api.massive.com for REST, wss://socket.massive.com for streaming.
  • Asset classes: stocks, options, indices, futures, forex and crypto on both.

Which one to use

Match the transport to the shape of the question. This table covers the requests support sees most often:

What you wantUseWhy
Bars for a date rangeREST /v2/aggsOne request returns the whole range
Every trade or quote as it printsWebSocketREST would need you to poll, and you would still miss prints between calls
The latest price right now, onceREST snapshotOne request, no connection to keep alive
The latest price, continuouslyWebSocketA snapshot loop costs a request every time and lags by its interval
Reference data, tickers, splits, dividendsRESTIt changes daily at most, so there is nothing to stream
Bars while the session is runningWebSocket A or AMBars are pushed as they close and corrected if a late trade changes them

What each one costs you

REST costs requests. The free Basic tier allows five a minute and paid tiers are unlimited, so a polling loop is the pattern most likely to run into a rate limit. A WebSocket costs a connection rather than requests: your plan includes a number of simultaneous connections per cluster, and once connected, the number of tickers you subscribe to is free.

That is the practical reason to stream rather than poll for anything live. The unified snapshot takes up to 250 tickers per request, so polling 500 tickers once a second is two requests a second that still lag by up to a second, and the loop grows with your universe. One WebSocket subscription delivers the same 500 tickers with no request cost and no lag beyond the network.

Why you often need both

Most Massive integrations use both, because a stream only tells you what happened after you connected. The usual pattern is one REST call to load the history or the state you need, then a WebSocket subscription to keep it current, with the stream buffered while the REST call is in flight so nothing falls between the two.

If you see an error

HTTP 429 from REST means you are over your plan's request rate. If the loop is polling for live data, move it to a WebSocket rather than adding retries.

{"ev":"status","status":"error","message":"not authorized"} on a WebSocket while the same data works over REST usually means your plan covers the REST tier but not the streaming feed for that product.

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.