Polygon.io provides a standardized interface for streaming real-time stock, forex, and crypto data using the WebSocket protocol. Users can specify which WebSocket channels they want to consume by sending instructions in the form of actions. Our WebSockets emit events to notify the user when an event has occurred in a subscribed channel.
Access to different feeds varies depending on your subscription. These docs are customized to your version of the API and display your key and data, which only you can see. These docs demonstrate using WebSocket to interact with the API using standardized protocols over TCP.
Your API key allows 1 simultaneous connection to each cluster (3 total at one time). If another connection attempts to connect, the current connection will be disconnected.
Connect to a cluster
Delayed:wscat -c wss://delayed.polygon.io/stocks
Real-Time:wscat -c wss://socket.polygon.io/stocks
On connection you will receive the following message:
[{
"ev":"status",
"status":"connected",
"message": "Connected Successfully"
}]
You must authenticate before you can make any other requests.
{"action":"auth","params":"********"}
On successful authentication you will receive the following message:
[{
"ev":"status",
"status":"auth_success",
"message": "authenticated"
}]
Once authenticated, you can request a stream. You can request multiple streams in the same request.
Once authenticated, you can request a stream.
{"action":"subscribe","params":"T.LPL"}
You can also request multiple streams from the same cluster.
{"action":"subscribe","params":"T.LPL,Q.MSFT"}
Things happen very quickly in the world of finance, which means a Polygon.io WebSocket client must be able to handle many incoming messages per second. Due to the nature of the WebSocket protocol, if a client is slow to consume messages from the server, Polygon.io’s server must buffer messages and send them only as fast as the client can consume them. To help prevent the message buffer from getting too long, Polygon.io may send more than one JSON object in a single WebSocket message. We accomplish this by wrapping all messages in a JSON array, and adding more objects to the array if the message buffer is getting longer. For example, consider a WebSocket message with a single trade event in it:
[
{"ev":"T","sym":"MSFT","i":"50578","x":4,"p":215.9721,"s":100,"t":1611082428813,"z":3}
]
If your client is consuming a bit slow, or 2+ events happened in very short succession, you may receive a single WebSocket message with more than one event inside it, like this:
[
{"ev":"T","sym":"MSFT","i":"50578","x":4,"p":215.9721,"s":100,"t":1611082428813,"z":3},
{"ev":"T","sym":"MSFT","i":"12856","x":4,"p":215.989,"s":1,"c":[37],"t":1611082428814,"z":3}
]
Note that if a client is consuming messages too slowly for too long, Polygon.io’s server-side buffer may get too large. If that happens, Polygon.io will terminate the WebSocket connection. You can check your account dashboard to see if a connection was terminated as a slow consumer. If this happens to you consistently, consider subscribing to fewer symbols or channels.
Stream real-time trades for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"T.{ticker}"}
The event type.
The ticker symbol for the given stock.
The exchange ID. See Exchanges for Polygon.io's mapping of exchange IDs.
The trade ID.
The tape. (1 = NYSE, 2 = AMEX, 3 = Nasdaq).
The price.
The trade size.
The trade conditions
The Timestamp in Unix MS.
{
"ev": "T",
"sym": "MSFT",
"x": 4,
"i": "12345",
"z": 3,
"p": 114.125,
"s": 100,
"c": [
0,
12
],
"t": 1536036818784
}
Stream real-time quotes for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"Q.{ticker}"}
The event type.
The ticker symbol for the given stock.
The bid exchange ID.
The bid price.
The bid size.
The ask exchange ID.
The ask price.
The ask size.
The condition.
The Timestamp in Unix MS.
{
"ev": "Q",
"sym": "MSFT",
"bx": 4,
"bp": 114.125,
"bs": 100,
"ax": 7,
"ap": 114.128,
"as": 160,
"c": 0,
"t": 1536036818784
}
Stream real-time second aggregates for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"A.{ticker}"}
The event type.
The ticker symbol for the given stock.
The tick volume.
Today's accumulated volume.
Today's official opening price.
Today's volume weighted average price.
The opening tick price for this aggregate window.
The closing tick price for this aggregate window.
The highest tick price for this aggregate window.
The lowest tick price for this aggregate window.
The tick's volume weighted average price.
The average trade size for this aggregate window.
The timestamp of the starting tick for this aggregate window in Unix Milliseconds.
The timestamp of the ending tick for this aggregate window in Unix Milliseconds.
{
"ev": "A",
"sym": "SPCE",
"v": 200,
"av": 8642007,
"op": 25.66,
"vw": 25.3981,
"o": 25.39,
"c": 25.39,
"h": 25.39,
"l": 25.39,
"a": 25.3714,
"z": 50,
"s": 1610144868000,
"e": 1610144869000
}
Stream real-time minute aggregates for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"AM.{ticker}"}
The event type.
The ticker symbol for the given stock.
The tick volume.
Today's accumulated volume.
Today's official opening price.
Today's volume weighted average price.
The opening tick price for this aggregate window.
The closing tick price for this aggregate window.
The highest tick price for this aggregate window.
The lowest tick price for this aggregate window.
The tick's volume weighted average price.
The average trade size for this aggregate window.
The timestamp of the starting tick for this aggregate window in Unix Milliseconds.
The timestamp of the ending tick for this aggregate window in Unix Milliseconds.
{
"ev": "AM",
"sym": "GTE",
"v": 4110,
"av": 9470157,
"op": 0.4372,
"vw": 0.4488,
"o": 0.4488,
"c": 0.4486,
"h": 0.4489,
"l": 0.4486,
"a": 0.4352,
"z": 685,
"s": 1610144640000,
"e": 1610144700000
}
Stream real-time LULD events for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"LULD.{ticker}"}
The event type.
The ticker symbol for the given stock.
The high price.
The low price.
The tape. (1 = NYSE, 2 = AMEX, 3 = Nasdaq).
The Timestamp in Unix MS.
The sequence number.
{
"ev": "LULD",
"T": "MSFT",
"h": 218.96,
"l": 198.11,
"i": [
21
],
"z": 3,
"t": 1601316752683746,
"q": 290317
}
Stream real-time imbalance events for a given stock ticker symbol.
Specify a ticker symbol or use * to retreive all tickers. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"NOI.{ticker}"}
The event type.
The ticker symbol for the given stock.
The Timestamp in Unix MS.
The time that the auction is planned to take place in the format (hour x 100) + minutes in Eastern Standard Time, for example 930 would be 9:30 am EST, and 1600 would be 4:00 pm EST.
The auction type.
O
- Early Opening Auction (non-NYSE only)
M
- Core Opening Auction
H
- Reopening Auction (Halt Resume)
C
- Closing Auction
P
- Extreme Closing Imbalance (NYSE only)
R
- Regulatory Closing Imbalance (NYSE only)
The symbol sequence.
The exchange ID. See Exchanges for Polygon.io's mapping of exchange IDs.
The imbalance quantity.
The paired quantity.
The book clearing price.
{
"ev": "NOI",
"T": "NTEST.Q",
"t": 1601318039223013600,
"at": 930,
"a": "M",
"i": 44,
"x": 10,
"o": 480,
"p": 440,
"b": 25.03
}
Stream real-time forex quotes for a given forex pair.
Specify a forex pair in the format {from}/{to} or use * to retreive all forex pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"C.{ticker}"}
The event type.
The current pair.
The exchange ID. See Exchanges for Polygon.io's mapping of exchange IDs.
The ask price.
The bid price.
The Timestamp in Unix MS.
{
"ev": "C",
"p": "USD/CNH",
"x": "44",
"a": 6.83366,
"b": 6.83363,
"t": 1536036818784
}
Stream real-time per-minute forex aggregates for a given forex pair.
Specify a forex pair in the format {from}/{to} or use * to retreive all forex pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"CA.{ticker}"}
The event type.
The currency pair.
The open price for this aggregate window.
The close price for this aggregate window.
The high price for this aggregate window.
The low price for this aggregate window.
The volume of trades during this aggregate window.
The start time for this aggregate window in Unix Milliseconds.
The end time for this aggregate window in Unix Milliseconds.
{
"ev": "CA",
"pair": "USD/EUR",
"o": 0.8687,
"c": 0.86889,
"h": 0.86889,
"l": 0.8686,
"v": 20,
"s": 1539145740000
}
Stream real-time crypto trades for a given crypto pair.
Specify a crypto pair in the format {from}-{to} or use * to retreive all crypto pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"XT.{ticker}"}
The event type.
The crypto pair.
The price.
The Timestamp in Unix MS.
The size.
The conditions. 0 (or empty array): empty 1: sellside 2: buyside
The ID of the trade (optional).
The crypto exchange ID. See Crypto Exchanges for a list of exchanges and their IDs.
The timestamp that the tick was recieved by Polygon.
{
"ev": "XT",
"pair": "BTC-USD",
"p": 33021.9,
"t": 1610462007425,
"s": 0.01616617,
"c": [
2
],
"i": 14272084,
"x": 3,
"r": 1610462007576
}
Stream real-time crypto quotes for a given crypto pair.
Specify a crypto pair in the format {from}-{to} or use * to retreive all crypto pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"XQ.{ticker}"}
The event type.
The crypto pair.
The bid price.
The bid size.
The ask price.
The ask size.
The Timestamp in Unix MS.
The crypto exchange ID. See Crypto Exchanges for a list of exchanges and their IDs.
The timestamp that the tick was recieved by Polygon.
{
"ev": "XQ",
"pair": "BTC-USD",
"bp": 33052.79,
"bs": 0.48,
"ap": 33073.19,
"as": 0.601,
"t": 1610462411115,
"x": 1,
"r": 1610462411128
}
Stream real-time level 2 book data for a given crypto pair.
Specify a crypto pair in the format {from}-{to} or use * to retreive all crypto pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"XL2.{ticker}"}
The event type.
The crypto pair.
An array of bid prices with a maximum depth of 100.
An array of ask prices with a maximum depth of 100.
The Timestamp in Unix MS.
The crypto exchange ID. See Crypto Exchanges for a list of exchanges and their IDs.
The timestamp that the tick was recieved by Polygon.
{
"ev": "XL2",
"pair": "BTC-USD",
"t": 1610462411115,
"r": 1610462411128,
"x": 1,
"b": [
[
33712.71,
0.18635
],
[
33712.7,
0.134
]
],
"a": [
[
33718.23,
3.5527483
],
[
33718.24,
0.1
]
]
}
Stream real-time per-minute crypto aggregates for a given crypto pair.
Specify a crypto pair in the format {from}-{to} or use * to retreive all crypto pairs. You can also use a comma separated list to retrieve multiple tickers.
{"action":"subscribe", "params":"XA.{ticker}"}
The event type.
The crypto pair.
The open price for this aggregate window.
The close price for this aggregate window.
The high price for this aggregate window.
The low price for this aggregate window.
The volume of trades during this aggregate window.
The start time for this aggregate window in Unix Milliseconds.
The end time for this aggregate window in Unix Milliseconds.
{
"ev": "XA",
"pair": "BCD-USD",
"v": 951.6112,
"vw": 0.7756,
"z": 73.33,
"o": 0.772,
"c": 0.784,
"h": 0.784,
"l": 0.771,
"s": 1610463240000,
"e": 1610463300000
}