Socket Server v1.0


Step 1: Connect

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.

There are 3 separate real-time clusters. One for each market type:


Stocks Cluster

wss://socket.polygon.io/stocks

Available Channels:
T.* Trades
Q.* Quotes
A.* Aggregate ( per second )
AM.* Aggregate ( per minute )
LULD.* Limit-Up Limit-Down
NOI.* Imbalances

Forex Cluster

wss://socket.polygon.io/forex

Available Channels:
C.* Currencies / Forex
CA.* Currencies / Forex - Aggregate ( per minute )
BONDS.* Bonds Trades
COMMODITIES.* Commodities Trades
METALS.* Metals Trades

Crypto Cluster

wss://socket.polygon.io/crypto

Available Channels:
XT.* - Crypto Trades
XQ.* - Crypto Quotes
XS.* - Crypto Consolidated Tape ( Coming soon )
XL2.* - Crypto Level2 Books

On connection you will receive the following message:

1// RECV:
2[{
3        "ev":"status",
4        "status":"connected",
5        "message":"Connected Successfully"
6}]

Step 2: Authenticate

You must authenticate before you can make any other requests.

1// SEND:
2{
3        "action":"auth",
4        "params":"YOUR_API_KEY"
5}

Once authenticated, you will receive the following message:

1// RECV:
2[{
3        "ev":"status",
4        "status":"success",
5        "message":"authenticated"
6}]

Step 3: Subscribe to Stream

Once authenticated, you can request a stream. You can request multiple streams in the same request.

1// SEND:
2{
3        "action":"subscribe",
4        "params":"T.MSFT,T.AAPL,T.AMD,T.NVDA"
5}

You can unsubscribe from a stream by sending the following:

1// SEND:
2{
3        "action":"unsubscribe",
4        "params":"T.AMD"
5}

Every message will have an "ev" key which is for the event type. This is useful for when you have multiple subscriptions and need to differentiate between then.

Example:

$
|

Stocks Schemas:

1// Stocks TRADE:
2{
3    "ev": "T",              // Event Type
4    "sym": "MSFT",          // Symbol Ticker
5    "x": 4,                 // Exchange ID
6    "i": "12345",           // Trade ID
7    "z": 3,                 // Tape ( 1=A 2=B 3=C)
8    "p": 114.125,           // Price
9    "s": 100,               // Trade Size
10    "c": [0, 12],           // Trade Conditions
11    "t": 1536036818784      // Trade Timestamp ( Unix MS )
12}
13
14// Stocks QUOTE:
15{
16    "ev": "Q",              // Event Type
17    "sym": "MSFT",          // Symbol Ticker
18    "bx": 4,                // Bix Exchange ID
19    "bp": 114.125,          // Bid Price
20    "bs": 100,              // Bid Size
21    "ax": 7,                // Ask Exchange ID
22    "ap": 114.128,          // Ask Price
23    "as": 160,              // Ask Size
24    "c": 0,                 // Quote Condition
25    "t": 1536036818784      // Quote Timestamp ( Unix MS )
26}
27
28// Stocks Aggregate:
29{
30    "ev": "AM",             // Event Type ( A = Second Agg, AM = Minute Agg )
31    "sym": "MSFT",          // Symbol Ticker
32    "v": 10204,             // Tick Volume
33    "av": 200304,           // Accumulated Volume ( Today )
34    "op": 114.04,           // Today's official opening price
35    "vw": 114.4040,         // VWAP (Volume Weighted Average Price)
36    "o": 114.11,            // Tick Open Price
37    "c": 114.14,            // Tick Close Price
38    "h": 114.19,            // Tick High Price
39    "l": 114.09,            // Tick Low Price
40    "a": 114.1314,          // Tick Average / VWAP Price
41    "s": 1536036818784,     // Tick Start Timestamp ( Unix MS )
42    "e": 1536036818784,     // Tick End Timestamp ( Unix MS )
43}
44
45// Stocks Limit-Up Limit-Down:
46{
47    "ev": "LULD",            // Event Type
48    "T":"MSFT",              // Ticker
49    "h":218.96,              // High Price
50    "l":198.11,              // Low Price
51    "i":[...],               // Indicators
52    "z":3,                   // Tape ( 1=A 2=B 3=C)
53    "t":1601316752825683746, // Timestamp (Unix Nanoseconds)
54    "q":2903176              // Sequence Number
55}
56
57// Stocks Imbalances
58{
59    "ev":"NOI",              // Event Type
60    "T":"NTEST.Q",           // Ticker Symbol
61    "t":1601318039223013632, // Timestamp (Unix Nanoseconds)
62    "at":930,                // Auction Time
63    "a":"M",                 // Auction Type
64    "i":44,                  // Symbol Sequence
65    "x":10,                  // Exchange ID
66    "o":480,                 // Imbalance Quantity
67    "p":440,                 // Paired Quantity
68    "b":25.03                // Book Clearing Price
69}

Forex Schemas:

1// Forex QUOTE:
2{
3    "ev": "C",              // Event Type
4    "p": "USD/CNH",         // Currency Pair
5    "x": "44",              // FX Exchange ID
6    "a": 6.83366,           // Ask Price
7    "b": 6.83363,           // Bid Price
8    "t": 1536036818784      // Quote Timestamp ( Unix MS )
9}
10
11// Forex Aggregate:
12{
13    "ev": "CA",             // Event Type
14    "pair": "USD/EUR",      // Currency Pair
15    "o": 0.8687,            // Open Price
16    "c": 0.868734,          // Close Price
17    "h": 0.86889,           // High Price
18    "l": 0.8686,            // Low Price
19    "v": 20,                // Volume ( Quotes during this duration )
20    "s": 1539145740000      // Tick Start Timestamp
21}

Crypto Schemas:

1// Crypto QUOTE:
2{
3    "ev": "XQ",             // Event Type
4    "pair": "BTC-USD",      // Crypto Pair
5    "lp": 6001.20,          // Last Trade Price
6    "ls": 1.05              // Last Trade Size
7    "bp": 6001.09,          // Bid Price
8    "bs": 1.0003,           // Bid Size
9    "ap": 6001.115,         // Ask Price
10    "as": 3.0204005,        // Ask Size
11    "t": 1342342342342,     // Exchange Timestamp Unix ( ms )
12    "x": 3,                 // Exchange ID
13    "r": 1234134124123      // Received @ Polygon Timestamp
14}
15
16// Crypto TRADE:
17{
18    "ev": "XT",             // Event Type
19    "pair": "BTC-USD",      // Crypto Pair
20    "p": 6006.4,            // Price
21    "t": 1342342342342,     // Timestamp Unix ( ms )
22    "s": 3.15,              // Size
23    "c": [0],               // Condition
24    "i": "someid"           // Trade ID ( Optional )
25    "x": 3,                 // Exchange ID
26    "r": 1234134124123      // Received @ Polygon Timestamp
27}
28
29// Crypto AGGREGATE:
30{
31    "ev": "XA",             // Event Type
32    "pair": "BTC-USD",      // Crypto Pair
33    "o": 6443.517,          // Open Price
34    "ox": 2,                // Open Exchange
35    "h": 6446.0196,         // High Price
36    "hx": 7,                // High Exchange
37    "l": 6282.72,           // Low Price
38    "lx": 6,                // Low Exchange
39    "c": 6442.74,           // Close Price
40    "cx": 4,                // Close Exchange
41    "v": 70.3761311,        // Volume of Trades in Tick
42    "s": 1542098700000      // Tick Start Timestamp
43    "e": 1542098760000      // Tick End Timestamp
44}
45
46// Crypto SIP ( NBBO ):
47{
48    "ev": "XS",             // Event Type
49    "pair": "BTC-USD",      // Crypto Pair
50    "as": 1.94892535,       // Ask Size
51    "ap": 6277.91,          // Ask Price
52    "ax": 6,                // Ask Exchange
53    "bs": 0.01555,          // Bid Size
54    "bp": 6446.17,          // Bid Price
55    "bx": 10,               // Bid Exchange
56    "t": 1542098700000      // Tick Start Timestamp
57}
58
59// Crypto LEVEL2:
60{
61    "ev": "XL2",                // Event Type
62    "pair": "BTC-USD",          // Crypto Pair
63    "b": [[ 6001.00, 1.432 ],   // Bid Prices ( 100 depth cap )
64        [ 6000.98, 4.665 ],     // [ Price, Size ]
65        [ 5999.30, .432434 ]],                  
66    "a": [[ 6001.10, 2.2 ],     // Ask Prices ( 100 depth cap )
67        [ 6001.45, 1.405 ],     // [ Price, Size ]
68        [ 6002.10, 10.43 ]],
69    "t": 1342342342342,         // Timestamp Unix ( ms )
70    "x": 11,                    // Exchange ID
71    "r": 1234134124123          // Tick Received @ Polygon Timestamp
72}