### Connect and Subscribe to Stock Quotes Source: https://massive.com/docs/websocket/stocks/quotes?assetClass=currencies&display=all&license=personal This example demonstrates how to connect to the WebSocket, authenticate with your API key, and subscribe to quote data for specific tickers or all tickers. ```APIDOC ## Connect and Subscribe to Stock Quotes ### Description Connect to the WebSocket endpoint, authenticate your session using your API key, and subscribe to real-time quote data. You can subscribe to specific tickers, multiple tickers using a comma-separated list, or all tickers using '*'. ### Method WebSocket Connection ### Endpoint `wss://socket.massive.com/stocks` (Real-Time) `wss://delayed.massive.com/stocks` (Delayed) ### Parameters #### Subscription Parameters (JSON Payload) - **action** (string) - Required - The action to perform, e.g., `"auth"` or `"subscribe"`. - **params** (string) - Required - For `"auth"`, this is your API key. For `"subscribe"`, this is the ticker symbol(s) to subscribe to (e.g., `"Q.MSFT"`, `"Q.AAPL,Q.GOOG"`, or `"Q.*"`). ### Request Example ```json // Authenticate {"action":"auth","params":"YOUR_API_KEY"} // Subscribe to all stock tickers {"action":"subscribe", "params":"Q.*"} // Subscribe to specific tickers (e.g., Microsoft and Google) {"action":"subscribe", "params":"Q.MSFT,Q.GOOG"} ``` ### Response Attributes - **ev** (enum) - The event type. Expected value: `"Q"`. - **sym** (string) - The ticker symbol. - **bx** (integer) - The bid exchange ID. - **bp** (number) - The bid price. - **bs** (integer) - The bid size (number of round lot orders). - **ax** (integer) - The ask exchange ID. - **ap** (number) - The ask price. - **as** (integer) - The ask size (number of round lot orders). - **c** (integer) - The condition code. - **i** (array of integers) - The indicators. - **t** (integer) - The SIP timestamp in Unix milliseconds. - **q** (integer) - The sequence number for quote events. - **z** (integer) - The tape identifier (1 = NYSE, 2 = AMEX, 3 = Nasdaq). ### Response Example ```json { "ev": "Q", "sym": "MSFT", "bx": 4, "bp": 114.125, "bs": 100, "ax": 7, "ap": 114.128, "as": 160, "c": 0, "i": [ 604 ], "t": 1536036818784, "q": 50385480, "z": 3 } ``` ``` -------------------------------- ### LULD Event Response Object Source: https://massive.com/docs/websocket/stocks/luld?assetClass=futures&endpointProducts=futures_basic%2Cfutures_starter%2Cfutures_developer%2Cfutures_advanced&license=commercial&name=business_futures_cbot This is an example of the data structure you will receive for each LULD event. ```APIDOC ## Response Object ```json { "ev": "LULD", "T": "MSFT", "h": 492.99, "l": 446.04, "i": [ 16 ], "z": 3, "t": 1764086430905642800, "q": 5925769 } ``` ``` -------------------------------- ### Connect and Subscribe to Futures Quotes Source: https://massive.com/docs/websocket/stocks/quotes?assetClass=futures&endpointProducts=futures_basic%2Cfutures_starter%2Cfutures_developer%2Cfutures_advanced&license=commercial&name=business_futures_cbot Connect to the WebSocket endpoint and subscribe to real-time futures quote data. This example demonstrates how to establish a connection, authenticate, and subscribe to quote updates. ```APIDOC ## Connect and Subscribe to Futures Quotes ### Description Connect to the WebSocket endpoint to receive real-time quote data for futures. This involves establishing a connection, authenticating with your API key, and subscribing to the desired topics. ### Method WebSocket Connection ### Endpoint `wss://socket.massive.com/stocks` (for real-time data) ### Parameters #### Connection Parameters - **`assetClass`** (string) - `futures` - Specifies the asset class to subscribe to. - **`endpointProducts`** (string) - `futures_basic,futures_starter,futures_developer,futures_advanced` - Specifies the product tiers available. - **`license`** (string) - `commercial` - Specifies the license type. - **`name`** (string) - `business_futures_cbot` - Specifies the name of the product. #### Authentication - **`action`**: `auth` (string) - **`params`**: `YOUR_API_KEY` (string) - Your unique API key for authentication. #### Subscription - **`action`**: `subscribe` (string) - **`params`**: `Q.*` (string) - Subscription string to receive all quote events. For specific tickers, use `Q.TICKER_SYMBOL`. ### Request Example ``` # Connect to the websocket npx wscat -c wss://socket.massive.com/stocks?assetClass=futures&endpointProducts=futures_basic%2Cfutures_starter%2Cfutures_developer%2Cfutures_advanced&license=commercial&name=business_futures_cbot # Authenticate {"action":"auth","params":"YOUR_API_KEY"} # Subscribe to the topic {"action":"subscribe", "params":"Q.*"} ``` ### Response Attributes - **`ev`** (enum: `Q`) - Event type. - **`sym`** (string) - Ticker symbol. - **`bx`** (integer) - Bid exchange ID. - **`bp`** (number) - Bid price. - **`bs`** (integer) - Bid size (number of round lots). - **`ax`** (integer) - Ask exchange ID. - **`ap`** (number) - Ask price. - **`as`** (integer) - Ask size (number of round lots). - **`c`** (integer) - Condition code. - **`i`** (array of integers) - Indicators. - **`t`** (integer) - SIP timestamp in Unix milliseconds. - **`q`** (integer) - Sequence number of the quote event. - **`z`** (integer) - Tape identifier (1=NYSE, 2=AMEX, 3=Nasdaq). ### Response Example ```json { "ev": "Q", "sym": "MSFT", "bx": 4, "bp": 114.125, "bs": 100, "ax": 7, "ap": 114.128, "as": 160, "c": 0, "i": [ 604 ], "t": 1536036818784, "q": 50385480, "z": 3 } ``` ``` -------------------------------- ### Get Current Market Status (Python) Source: https://massive.com/docs/rest/forex/market-operations/market-status?assetClass=economy&endpointProducts=all_stocks%2Call_options%2Call_indices%2Call_currencies&license=personal&name=indices_indices_feed Example of fetching market status using Python's requests library. Ensure you have the library installed (`pip install requests`). ```python import requests url = "https://api.massive.com/v1/marketstatus/now" params = { "apiKey": "YOUR_API_KEY" } response = requests.get(url, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Query All Contracts Source: https://massive.com/docs/rest/options/contracts/all-contracts?assetClass=indices&display=all&license=personal This example shows how to construct a GET request to retrieve all available options contracts. It includes parameters for ordering, limiting results, and sorting by ticker. An API key is required for authentication. ```bash GET https://api.massive.com/v3/reference/options/contracts?order=asc&limit=10&sort=ticker&apiKey=YOUR_API_KEY ``` -------------------------------- ### Accessing S3 Flat Files Source: https://massive.com/docs/flat-files/stocks/quotes/2009/11?assetClass=stocks&endpointProducts=stocks_basic%2Cstocks_starter%2Cstocks_developer%2Cstocks_advanced&license=personal&name=stocks_starter This example shows how to access the S3 flat files. Ensure you have the necessary account and permissions. ```bash aws s3 cp s3://us_stocks_sip/quotes_v1/2009-11-30/2009-11-30.csv.gz . ``` -------------------------------- ### Get Last Forex Quote (Python) Source: https://massive.com/docs/rest/forex/quotes/last-quote?assetClass=economy&endpointProducts=all_stocks%2Call_options%2Call_indices%2Call_currencies&license=personal&name=all_indices Example of fetching the last forex quote using Python. Ensure you have the 'requests' library installed. ```python import requests url = "https://api.massive.com/v1/last_quote/currencies/AUD/USD" params = { "apiKey": "YOUR_API_KEY" } response = requests.get(url, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### File Browser Example Source: https://massive.com/docs/flat-files/futures/session-aggregates/comex/2020/04?assetClass=futures&endpointProducts=futures_basic%2Cfutures_starter%2Cfutures_developer%2Cfutures_advanced&license=personal&name=futures_developer Example of file structure for COMEX futures session aggregates, showing daily compressed CSV files. ```markdown Name| Files| Size| Last Updated| Select ---|---|---|---|--- ..| | | | 2020-04-30/2020-04-30.csv.gz| | 3.82 kB| Jun 16, 2026| Create account 2020-04-29/2020-04-29.csv.gz| | 3.51 kB| Jun 16, 2026| Create account 2020-04-28/2020-04-28.csv.gz| | 4.01 kB| Jun 16, 2026| Create account 2020-04-27/2020-04-27.csv.gz| | 3.93 kB| Jun 16, 2026| Create account 2020-04-24/2020-04-24.csv.gz| | 3.36 kB| Jun 16, 2026| Create account 2020-04-23/2020-04-23.csv.gz| | 3.75 kB| Jun 16, 2026| Create account 2020-04-22/2020-04-22.csv.gz| | 3.74 kB| Jun 16, 2026| Create account 2020-04-21/2020-04-21.csv.gz| | 4.18 kB| Jun 16, 2026| Create account 2020-04-20/2020-04-20.csv.gz| | 3.59 kB| Jun 16, 2026| Create account 2020-04-17/2020-04-17.csv.gz| | 3.67 kB| Jun 16, 2026| Create account 2020-04-16/2020-04-16.csv.gz| | 3.59 kB| Jun 16, 2026| Create account 2020-04-15/2020-04-15.csv.gz| | 3.68 kB| Jun 16, 2026| Create account 2020-04-14/2020-04-14.csv.gz| | 4.12 kB| Jun 16, 2026| Create account 2020-04-13/2020-04-13.csv.gz| | 3.54 kB| Jun 16, 2026| Create account 2020-04-10/2020-04-10.csv.gz| | 98 B| Jun 16, 2026| Create account 2020-04-09/2020-04-09.csv.gz| | 3.64 kB| Jun 16, 2026| Create account 2020-04-08/2020-04-08.csv.gz| | 3.42 kB| Jun 16, 2026| Create account 2020-04-07/2020-04-07.csv.gz| | 3.87 kB| Jun 16, 2026| Create account 2020-04-06/2020-04-06.csv.gz| | 3.52 kB| Jun 16, 2026| Create account 2020-04-03/2020-04-03.csv.gz| | 3.31 kB| Jun 16, 2026| Create account 2020-04-02/2020-04-02.csv.gz| | 3.11 kB| Jun 16, 2026| Create account 2020-04-01/2020-04-01.csv.gz| | 3.24 kB| Jun 16, 2026| Create account ``` -------------------------------- ### Retrieve Historical Quotes (JavaScript) Source: https://massive.com/docs/rest/options/trades-quotes/quotes?assetClass=partner&endpointProducts=benzinga_ratings%2Cbenzinga_analyst_insights&license=personal&name=benzinga_ratings This JavaScript example uses the 'node-fetch' library to make a GET request for historical quotes. It demonstrates how to handle the response and potential errors. Ensure you have 'node-fetch' installed (`npm install node-fetch`). ```javascript const fetch = require('node-fetch'); const apiKey = "YOUR_API_KEY"; const optionsTicker = "O:SPY241220P00720000"; const url = `https://api.massive.com/v3/quotes/${optionsTicker}?order=asc&limit=10&sort=timestamp&apiKey=${apiKey}`; fetch(url) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .then(data => { console.log(data); }) .catch(error => { console.error('Error fetching quotes:', error); }); ```