New to Rust? Grab our free Rust for Beginners eBook Get it free →
Market Real Time Data in Node.js with Marketstack

Adding stock information to a Node.js app starts with choosing a source for ticker data. Marketstack is an API, or service that applications contact to request data, and it returns stock-market information as JSON.
This article walks through choosing an endpoint and sending a V2 request with the access key kept outside source code.
TL;DR
Marketstack returns stock data through HTTPS REST requests, so choose an endpoint and plan for the freshness your app needs, then parse its JSON response in Node.js.
- Use end-of-day data for daily prices and intraday data for observations during a trading session.
- Use the V2 documentation for new integrations. The V1 endpoint guide carries a deprecation notice.
- Keep the access key on your server and check both HTTP status and the response body.
- Marketstack calls its endpoint on each refresh. The API uses REST rather than a WebSocket or streaming feed.
What Is the Marketstack API?
Marketstack is an APILayer service that gives an application access to stock-market data through HTTP requests and JSON responses. The current API overview describes V2 endpoints for stock prices, company and ticker details, exchanges, indices, corporate actions, bonds, ETFs, commodities and SEC filings.
An end-of-day (EOD) endpoint returns daily observations, while an intraday endpoint returns records from within a trading session. The plan and supported instrument determine which intervals and markets your account can query. Check those two details before choosing a route.
The API’s request/response model has no WebSocket stream. A dashboard that polls asks for a new response each time it refreshes.
The V1 endpoint guide carried a deprecation notice for use after June 30, 2025 and directed readers to V2 for new functionality. For new requests, follow the V2 reference and do not copy older V1 paths.
Market data has two freshness questions. The endpoint determines whether a record is a daily bar or an observation from within a session. The account plan determines which interval and market the request can access.
Check both before building a polling loop. A short timer cannot make an unavailable endpoint return a different data feed.
How to Fetch Marketstack Data in Node.js
A server-side Node.js integration needs a Marketstack account, an access key and an endpoint supported by your plan. The built-in Fetch API avoids a package for a GET request. Use a supported Node.js release with Fetch available.
Step 1: Choose EOD or intraday data
Pick the data interval before writing the request, because it determines both the endpoint and the subscription requirements. EOD suits a daily summary or a historical chart, while intraday data is for observations during the session.
| Reader task | Data choice | Check before coding |
|---|---|---|
| Display a daily closing history | EOD | Available history and ticker coverage |
| Show price observations during a session | Intraday | Eligible plan, exchange coverage and interval |
| Refresh a dashboard periodically | REST polling | Request quota and allowed cadence |
Marketstack’s pricing page lists EOD on Free and IEX intraday for US symbols on Basic and higher. Professional and higher add updates at shorter intervals. Confirm instrument access and the current plan terms before coding.
The same pricing table lists historical coverage of up to 12 months on Free, 120 months on Basic, and 180 or more months on Professional and Business. Choose a tier that covers the oldest date in the dataset you plan to query.
A historical loader should check two limits before it starts. The plan determines how far back data is available, while pagination determines how much arrives in each response. Work out both before building a long backfill.
Step 2: Store the access key outside source code
Its FAQ says authentication uses an access key in the endpoint URL. Avoid placing the key in a checked-in source file, a browser bundle or a public issue. The key is a credential, so keep it out of screenshots and application logs too.
For a local shell session, supply the key as an environment variable when starting the process. A hosted service should read it from its secret manager or deployment environment instead of a checked-in file.
Step 3: Send a V2 HTTPS request
For an EOD request, the current APILayer guide documents /v2/eod/latest. The V2 reference confirms the API host, HTTPS GET method and access_key query parameter. The vendor guide uses symbols to select a ticker, and lists additional filters in the endpoint reference.
The script below uses Node.js built-in Fetch and the documented EOD route. The API key comes from the process environment, while URLSearchParams adds query values without hand-built escaping.
const accessKey = process.env.MARKETSTACK_ACCESS_KEY;
const endpoint = process.env.MARKETSTACK_ENDPOINT || 'https://api.marketstack.com/v2/eod/latest';
if (!accessKey) {
throw new Error('Set MARKETSTACK_ACCESS_KEY before running this example');
}
const url = new URL(endpoint);
url.searchParams.set('access_key', accessKey);
url.searchParams.set('symbols', 'AAPL');
async function getMarketData() {
const response = await fetch(url);
const body = await response.json();
if (!response.ok || body.error) {
throw new Error(JSON.stringify(body.error || { status: response.status }));
}
console.log(JSON.stringify(body, null, 2));
}
getMarketData().catch((error) => {
console.error(error.message);
process.exitCode = 1;
});
Run the file from the shell where you set MARKETSTACK_ACCESS_KEY. The key travels in the query string because that is the documented authentication method, so make sure your own server, proxy and logging configuration does not record the full URL.
I ran the script with the placeholder key to check its error path. The API rejected the placeholder instead of returning stock data. A valid account key is needed to see a successful response.
The exact error response from that execution was:
pankaj@codeforgeek:~$ MARKETSTACK_ACCESS_KEY=YOUR_ACCESS_KEY node marketstack.js
{"code":"invalid_access_key","message":"You have not supplied a valid API Access Key. [Technical Support: [email protected]]"}

Step 4: Check the response and read the data
The code distinguishes an HTTP failure from an API error object and reports the provider’s error body. With a valid key, use the V2 endpoint schema to read fields from the returned JSON.
The selected route determines the JSON shape. Read its documented fields instead of assuming EOD and intraday records use the same properties.
For a paginated result, read its pagination metadata and request additional pages using the documented parameters. A smaller page size limits how much data the application has to inspect during development.
After the request succeeds, check that the expected data collection exists and contains the requested ticker. Validate the timestamp before displaying the quote so a stale or empty response does not look like a new price.
For a server-rendered application, keep the vendor request in a server route or service module. The browser can call your own application, while your server adds the Marketstack credential and applies the allowed fields and refresh schedule. This design also gives you one place to handle provider errors and prevent each visitor from making an independent vendor request.
Before deploying, test the selected endpoint with a single ticker and a small result limit if the V2 reference supports one. Confirm the returned symbol and timestamp, then check how the endpoint represents an empty data set. These checks catch a wrong symbol or unsupported exchange before the application turns an empty response into a misleading blank chart.
A historical query uses the route and date filters listed in the selected V2 endpoint. APILayer’s guide shows date_from and date_to for an EOD range. Use those filters to limit the requested period instead of downloading a broad history and discarding records in Node.js.
Some responses contain several records for one ticker. Decide whether the application needs the latest observation or a series before selecting the endpoint. A single latest record suits a summary card, while a time series gives a chart its ordered points.
Keep the date, ticker and exchange alongside each stored value. That context lets a later query distinguish an EOD close from an intraday observation and makes it possible to explain which session a displayed price represents.
Marketstack API Limits and Common Errors
When an API request fails, first compare its route, ticker and account access with the V2 reference and current pricing. Those checks separate a configuration issue from a data-availability issue.
| Symptom | What to check | Next move |
|---|---|---|
| Request rejected | HTTPS URL, access key present, correct V2 endpoint | Compare the route and required parameters with current V2 docs |
| No records | Ticker spelling, exchange support, date range and endpoint | Check the instrument in Marketstack’s ticker search and inspect the returned body |
| Intraday access denied | Plan, market coverage and requested interval | Confirm the tier includes that data and interval |
| Usage reaches its allowance | Requests per ticker and repeated polling schedule | Reduce unnecessary polls or choose a plan with suitable quota |
| Data does not update continuously | REST request/response model and refresh interval | Schedule polling within product limits. REST has no WebSocket feed |
Marketstack’s FAQ says a request containing five symbols consumes five API requests. Keep that rule in mind when batching symbols, and check account usage rather than assuming one HTTP call equals one quota unit.
On the pricing page checked October 24, 2026, Free lists 100 requests per month and EOD data. Basic lists 10,000 requests and US IEX intraday access. Professional lists 100,000 requests and updates at shorter intervals.
Annual billing prices differ from monthly billing, so verify the current amount before choosing a plan.
Polling frequency is an application decision with a quota cost. If a dashboard asks every minute for several symbols, count each ticker request across every refresh and every active user. Cache shared responses where permitted, avoid duplicate polling from each browser tab, and choose an update interval that matches the data rights and plan.
Keep the key on your server. Browser code exposes its request URL to the user, and browser network tools can show query parameters. Have your server make the vendor request and return only the fields the interface needs.
For a generic explanation of Node HTTP request choices, see making REST API requests in Node.js. If you are comparing Fetch with a package-based client, the Node.js fetch guide covers that separate decision. Marketstack’s own API overview and current V2 endpoint reference should decide the exact route and schema.
Open, high, low and close describe prices at the start, peak, trough and end of an interval. Volume describes shares traded during that period. The timestamp and ticker identify when and for which instrument those values apply.
Keep the interval visible in the interface. A daily close and an intraday observation answer different questions, even if both are displayed beside the same company name.
Use the field definitions for the selected V2 endpoint rather than assuming that each route returns the same object. A daily record and an intraday record may have different time semantics. Preserve the timestamp and symbol with every value you store so a chart does not mix records from different instruments or periods.
Historical analysis also needs care around splits and dividends. Marketstack lists corporate-action data among its API offerings. When a price series crosses a split or dividend date, check whether the values you use are adjusted and keep the adjustment convention consistent across the series.
Exchange time zones matter when grouping records by day. The vendor’s integration guidance recommends storing timestamps in a consistent form and converting for display. Use exchange metadata from the API documentation when the application serves more than one market, and avoid deriving a trading date from the server’s local time.
An empty response can also be a valid outcome when a market is closed or a symbol has no record for the requested period. Check the requested date range, exchange and ticker before treating an empty data collection as an outage. This keeps weekends and market holidays from appearing as application errors.
Review data-use rights before shipping a public or commercial feature. The pricing page checked for this draft labels the Free plan non-commercial and Basic as commercial. A prototype’s successful API call does not grant rights beyond the terms of the account.
Conclusion
Build the integration around the data interval your application needs, then verify the current V2 endpoint, plan access and response schema before sending requests. Keep the key on the server and treat each poll as a quota-consuming request.
For the next step, use the Marketstack API documentation to select a V2 route and compare its required parameters with the plan shown on the official pricing page.
FAQ
These quick answers cover integration questions that remain after selecting an endpoint.
Does Marketstack provide a WebSocket feed?
No. Marketstack describes its API as REST request/response and says it does not provide WebSocket or streaming APIs. Applications can poll within plan and quota limits.
Can I use Marketstack intraday data on the Free plan?
The pricing page retrieved on 2026-10-24 lists EOD data on Free and IEX intraday data for US symbols on Basic and higher. Check the current plan and endpoint documentation before relying on access.
Where should I put the Marketstack access key?
Keep it in a server-side environment variable or secret manager. Do not commit it to source control or expose it in browser JavaScript.
Should a new integration use the V1 endpoints?
Start with the current V2 documentation. The V1 endpoint guide contains a notice that V1 was to be deprecated for use after June 30, 2025.




