### Install Massive JS Client Source: https://github.com/massive-com/client-js/blob/master/README.md Install the client library using npm. This is the first step to begin using the Massive API. ```bash npm install --save "@massive.com/client-js" ``` -------------------------------- ### Get Stocks Aggregates Source: https://github.com/massive-com/client-js/blob/master/README.md Fetch historical aggregate data for a given stock ticker. This example demonstrates how to retrieve daily bars for Apple (AAPL) for a specified date range. ```javascript import { restClient } from "@massive.com/client-js"; const apiKey = "XXXX"; const rest = restClient(apiKey, 'https://api.massive.com'); async function example_getStocksAggregates() { try { const response = await rest.getStocksAggregates( { stocksTicker: "AAPL", multiplier: "1", timespan: "day", from: "2025-11-01", to: "2025-11-30", adjusted: "true", sort: "asc", limit: "120" } ); console.log('Response:', response); } catch (e) { console.error('An error happened:', e); } } example_getStocksAggregates(); ``` -------------------------------- ### Get Stock Ticker Snapshot Source: https://github.com/massive-com/client-js/blob/master/README.md Retrieves a real-time snapshot of the latest trading activity for a given stock ticker. ```APIDOC ## GET /stocks/snapshot/{ticker} ### Description Retrieves a real-time snapshot of the latest trading activity for a given stock ticker. ### Method GET ### Endpoint /stocks/snapshot/{ticker} ### Parameters #### Path Parameters - **ticker** (string) - Required - The stock ticker symbol (e.g., AAPL). ### Request Example ```javascript rest.getStocksSnapshotTicker("AAPL"); ``` ### Response #### Success Response (200) - **ticker** (string) - The stock ticker symbol. - **day** (object) - Snapshot data for the current day. - **last_updated** (integer) - Unix epoch timestamp of the last update. - **previous_close** (object) - Previous day's closing information. - **// Other fields may include:** - **// session_open** - **// session_close** - **// volume** - **// latest_trade** - **// latest_quote** ``` -------------------------------- ### Get Stocks Snapshot Ticker Source: https://github.com/massive-com/client-js/blob/master/README.md Obtain a real-time snapshot of a stock ticker's data. This includes current price, volume, and other relevant metrics. ```javascript import { restClient } from "@massive.com/client-js"; const apiKey = "XXXXX"; const rest = restClient(apiKey, 'https://api.massive.com'); async function example_getStocksSnapshotTicker() { try { const response = await rest.getStocksSnapshotTicker("AAPL"); console.log('Response:', response); } catch (e) { console.error('An error happened:', e); } } example_getStocksSnapshotTicker(); ``` -------------------------------- ### Get Last Stocks Trade Source: https://github.com/massive-com/client-js/blob/master/README.md Retrieve the most recent trade for a specific stock ticker. This is useful for getting real-time or near real-time trade information. ```javascript import { restClient } from "@massive.com/client-js"; const apiKey = "XXXX"; const rest = restClient(apiKey, 'https://api.massive.com'); async function example_getLastStocksTrade() { try { const response = await rest.getLastStocksTrade("AAPL"); console.log('Response:', response); } catch (e) { console.error('An error happened:', e); } } example_getLastStocksTrade(); ``` -------------------------------- ### Get Last Stock Trade Source: https://github.com/massive-com/client-js/blob/master/README.md Retrieves the most recent trade for a given stock ticker. ```APIDOC ## GET /last/stocks/trade/{ticker} ### Description Retrieves the most recent trade for a given stock ticker. ### Method GET ### Endpoint /last/stocks/trade/{ticker} ### Parameters #### Path Parameters - **ticker** (string) - Required - The stock ticker symbol (e.g., AAPL). ### Request Example ```javascript rest.getLastStocksTrade("AAPL"); ``` ### Response #### Success Response (200) - **price** (number) - The price of the trade. - **size** (integer) - The size of the trade. - **exchange** (integer) - The exchange ID where the trade occurred. - **conditions** (array) - Array of trade condition codes. - **timestamp** (integer) - The Unix epoch timestamp of the trade. - **sequence_number** (integer) - The sequence number of the trade. ``` -------------------------------- ### Get Last Stock Quote Source: https://github.com/massive-com/client-js/blob/master/README.md Retrieves the most recent quote for a given stock ticker. ```APIDOC ## GET /last/stocks/quote/{ticker} ### Description Retrieves the most recent quote for a given stock ticker. ### Method GET ### Endpoint /last/stocks/quote/{ticker} ### Parameters #### Path Parameters - **ticker** (string) - Required - The stock ticker symbol (e.g., AAPL). ### Request Example ```javascript rest.getLastStocksQuote("AAPL"); ``` ### Response #### Success Response (200) - **bid_price** (number) - The bid price. - **bid_size** (integer) - The bid size. - **ask_price** (number) - The ask price. - **ask_size** (integer) - The ask size. - **exchange** (integer) - The exchange ID where the quote originated. - **conditions** (array) - Array of quote condition codes. - **timestamp** (integer) - The Unix epoch timestamp of the quote. - **last_updated_timestamp** (integer) - The Unix epoch timestamp of the last update. ``` -------------------------------- ### Get Last Stocks Quote Source: https://github.com/massive-com/client-js/blob/master/README.md Fetch the most recent quote for a specific stock ticker. This provides the latest bid and ask prices for a stock. ```javascript import { restClient } from "@massive.com/client-js"; const apiKey = "XXXXX"; const rest = restClient(apiKey, 'https://api.massive.com'); async function example_getLastStocksQuote() { try { const response = await rest.getLastStocksQuote("AAPL"); console.log('Response:', response); } catch (e) { console.error('An error happened:', e); } } example_getLastStocksQuote(); ``` -------------------------------- ### Get Stock Aggregates Source: https://github.com/massive-com/client-js/blob/master/README.md Fetches historical aggregate data (bars) for a given stock ticker within a specified date range. Supports various parameters for customization like multiplier, timespan, and adjusted prices. ```APIDOC ## GET /stocks/aggregates ### Description Fetches historical aggregate data (bars) for a given stock ticker within a specified date range. Supports various parameters for customization like multiplier, timespan, and adjusted prices. ### Method GET ### Endpoint /stocks/aggregates ### Parameters #### Query Parameters - **stocksTicker** (string) - Required - The stock ticker symbol (e.g., AAPL). - **multiplier** (string) - Required - The size of the timespan (e.g., 1, 5, 15, 30, 60). - **timespan** (string) - Required - The duration of each aggregate (e.g., day, hour, minute). - **from** (string) - Required - The start date in YYYY-MM-DD format. - **to** (string) - Required - The end date in YYYY-MM-DD format. - **adjusted** (string) - Optional - Whether to return adjusted prices (true/false). - **sort** (string) - Optional - Sort order for the results (asc/desc). - **limit** (string) - Optional - The maximum number of results to return. ### Request Example ```javascript rest.getStocksAggregates({ stocksTicker: "AAPL", multiplier: "1", timespan: "day", from: "2025-11-01", to: "2025-11-30", adjusted: "true", sort: "asc", limit: "120" }); ``` ### Response #### Success Response (200) - **results** (array) - Array of aggregate data objects. - **resultsCount** (integer) - The number of results returned. - **adjusted** (boolean) - Indicates if prices are adjusted. - **next_url** (string) - URL for the next page of results, if pagination is enabled. ``` -------------------------------- ### Initialize REST Client Source: https://github.com/massive-com/client-js/blob/master/README.md Create a new REST client instance with your API key. The API key can be obtained from your Massive.com dashboard. ```javascript import { restClient } from "@massive.com/client-js"; const rest = restClient(process.env.POLY_API_KEY); ``` -------------------------------- ### Connect and Subscribe to Stocks WebSocket Source: https://github.com/massive-com/client-js/blob/master/README.md Use this snippet to establish a WebSocket connection for stock data. Ensure you have your API key and the correct WebSocket endpoint. You can subscribe to specific stock symbols or all trades. ```javascript import { websocketClient } from "@massive.com/client-js"; const stocksWS = websocketClient(process.env.POLY_API_KEY, 'wss://delayed.massive.com').stocks(); stocksWS.onmessage = ({response}) => { const [message] = JSON.parse(response); stocksWS.send('{"action":"subscribe", "params":"AM.MSFT,A.MSFT"}'); switch (message.ev) { case "AM": // your trade message handler break; case "A": // your trade message handler break; } }; stocksWS.send({ action: "subscribe", params: "T.MSFT" }); ``` -------------------------------- ### Enable Pagination for REST Client Source: https://github.com/massive-com/client-js/blob/master/README.md Configure the REST client to automatically handle pagination. This feature fetches all available pages of data when the API indicates more data is present. ```javascript import { restClient } from "@massive.com/client-js"; const globalFetchOptions = { pagination: true, }; const rest = restClient(process.env.POLY_API_KEY, "https://api.massive.com", globalFetchOptions); rest.getStocksAggregates({ stocksTicker: "AAPL", multiplier: "1", timespan: "day", from: "2025-11-01", to: "2025-11-30" }).then((response) => { const data = response.data; // convert axios-wrapped response const resultCount = data.resultsCount; console.log("Result count:", resultCount); }).catch(e => { console.error('An error happened:', e); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.