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 )

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
2
3
4
5
6
// RECV:
[{
        "ev":"status",
        "status":"connected",
        "message":"Connected Successfully"
}]

Step 2: Authenticate

You must authenticate before you can make any other requests.

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

Once authenticated, you will receive the following message:

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

Step 3: Subscribe to Stream

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

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

You can unsubscribe from a stream by sending the following:

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

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Stocks TRADE:
{
    "ev": "T",              // Event Type
    "sym": "MSFT",          // Symbol Ticker
    "x": 4,                 // Exchange ID
    "i": "12345",           // Trade ID
    "z": 3,                 // Tape ( 1=A 2=B 3=C)
    "p": 114.125,           // Price
    "s": 100,               // Trade Size
    "c": [0, 12],           // Trade Conditions
    "t": 1536036818784      // Trade Timestamp ( Unix MS )
}

// Stocks QUOTE:
{
    "ev": "Q",              // Event Type
    "sym": "MSFT",          // Symbol Ticker
    "bx": 4,                // Bix Exchange ID
    "bp": 114.125,          // Bid Price
    "bs": 100,              // Bid Size
    "ax": 7,                // Ask Exchange ID
    "ap": 114.128,          // Ask Price
    "as": 160,              // Ask Size
    "c": 0,                 // Quote Condition
    "t": 1536036818784      // Quote Timestamp ( Unix MS )
}

// Stocks Aggregate:
{
    "ev": "AM",             // Event Type ( A = Second Agg, AM = Minute Agg )
    "sym": "MSFT",          // Symbol Ticker
    "v": 10204,             // Tick Volume
    "av": 200304,           // Accumulated Volume ( Today )
    "op": 114.04,           // Today's official opening price
    "vw": 114.4040,         // VWAP (Volume Weighted Average Price)
    "o": 114.11,            // Tick Open Price
    "c": 114.14,            // Tick Close Price
    "h": 114.19,            // Tick High Price
    "l": 114.09,            // Tick Low Price
    "a": 114.1314,          // Tick Average / VWAP Price
    "s": 1536036818784,     // Tick Start Timestamp ( Unix MS )
    "e": 1536036818784,     // Tick End Timestamp ( Unix MS )
}

Forex Schemas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Forex QUOTE:
{
    "ev": "C",              // Event Type
    "p": "USD/CNH",         // Currency Pair
    "x": "44",              // FX Exchange ID
    "a": 6.83366,           // Ask Price
    "b": 6.83363,           // Bid Price
    "t": 1536036818784      // Quote Timestamp ( Unix MS )
}

// Forex Aggregate:
{
    "ev": "CA",             // Event Type
    "pair": "USD/EUR",      // Currency Pair
    "o": 0.8687,            // Open Price
    "c": 0.868734,          // Close Price
    "h": 0.86889,           // High Price
    "l": 0.8686,            // Low Price
    "v": 20,                // Volume ( Quotes during this duration )
    "s": 1539145740000      // Tick Start Timestamp
}

Crypto Schemas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Crypto QUOTE:
{
    "ev": "XQ",             // Event Type
    "pair": "BTC-USD",      // Crypto Pair
    "lp": 6001.20,          // Last Trade Price
    "ls": 1.05              // Last Trade Size
    "bp": 6001.09,          // Bid Price
    "bs": 1.0003,           // Bid Size
    "ap": 6001.115,         // Ask Price
    "as": 3.0204005,        // Ask Size
    "t": 1342342342342,     // Exchange Timestamp Unix ( ms )
    "x": 3,                 // Exchange ID
    "r": 1234134124123      // Received @ Polygon Timestamp
}

// Crypto TRADE:
{
    "ev": "XT",             // Event Type
    "pair": "BTC-USD",      // Crypto Pair
    "p": 6006.4,            // Price
    "t": 1342342342342,     // Timestamp Unix ( ms )
    "s": 3.15,              // Size
    "c": [0],               // Condition
    "i": "someid"           // Trade ID ( Optional )
    "x": 3,                 // Exchange ID
    "r": 1234134124123      // Received @ Polygon Timestamp
}

// Crypto AGGREGATE:
{
    "ev": "XA",             // Event Type
    "pair": "BTC-USD",      // Crypto Pair
    "o": 6443.517,          // Open Price
    "ox": 2,                // Open Exchange
    "h": 6446.0196,         // High Price
    "hx": 7,                // High Exchange
    "l": 6282.72,           // Low Price
    "lx": 6,                // Low Exchange
    "c": 6442.74,           // Close Price
    "cx": 4,                // Close Exchange
    "v": 70.3761311,        // Volume of Trades in Tick
    "s": 1542098700000      // Tick Start Timestamp
    "e": 1542098760000      // Tick End Timestamp
}

// Crypto SIP ( NBBO ):
{
    "ev": "XS",             // Event Type
    "pair": "BTC-USD",      // Crypto Pair
    "as": 1.94892535,       // Ask Size
    "ap": 6277.91,          // Ask Price
    "ax": 6,                // Ask Exchange
    "bs": 0.01555,          // Bid Size
    "bp": 6446.17,          // Bid Price
    "bx": 10,               // Bid Exchange
    "t": 1542098700000      // Tick Start Timestamp
}

// Crypto LEVEL2:
{
    "ev": "XL2",                // Event Type
    "pair": "BTC-USD",          // Crypto Pair
    "b": [[ 6001.00, 1.432 ],   // Bid Prices ( 100 depth cap )
        [ 6000.98, 4.665 ],     // [ Price, Size ]
        [ 5999.30, .432434 ]],                  
    "a": [[ 6001.10, 2.2 ],     // Ask Prices ( 100 depth cap )
        [ 6001.45, 1.405 ],     // [ Price, Size ]
        [ 6002.10, 10.43 ]],
    "t": 1342342342342,         // Timestamp Unix ( ms )
    "x": 11,                    // Exchange ID
    "r": 1234134124123          // Tick Received @ Polygon Timestamp
}