
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@polygon.io/client-js
Advanced tools
Isomorphic Javascript client for Polygon.io Stocks, Forex, and Crypto APIs
Welcome to the official JS client library for the Polygon REST and WebSocket API. To get started, please see the Getting Started section in our documentation, view the examples directory for code snippets, or the blog post with video tutorials to learn more. To generate the package documentation please run npm run generate-doc.
For upgrade instructions please see the Release Notes.
To get started, you'll need to install the client library:
npm install --save `@polygon.io/client-js@next`
Next, create a new client with your API key.
import { restClient } from '@polygon.io/client-js';
const rest = restClient(process.env.POLY_API_KEY);
After creating the client, making calls to the Polygon API is easy. For example, here's how to get aggregates (bars):
rest.getStocksAggregates("AAPL", 1, GetStocksAggregatesTimespanEnum.Day, "2023-01-01", "2023-04-14").then((data) => {
console.log(data);
}).catch(e => {
console.error('An error happened:', e);
});
Or, maybe you want to get the last trades or quotes for a ticker:
// last trade
rest.lastTrade("AAPL").then((data) => {
console.log(data);
}).catch(e => {
console.error('An error happened:', e);
});
// last quote (NBBO)
rest.lastQuote("AAPL").then((data) => {
console.log(data);
}).catch(e => {
console.error('An error happened:', e);
});
Finally, maybe you want a market-wide snapshot of all tickers:
rest.stocks.snapshots().then((data) => {
console.log(data);
}).catch(e => {
console.error('An error happened:', e);
});
See full examples for more details on how to use this client effectively.
To run these examples from the command line, first check out this project and run npm i in the root directory to install dependencies, then run POLY_API_KEY=yourAPIKey node examples/rest/crypto-aggregates_bars.js, replacing yourAPIKey with your Polygon API Key.
The client can handle pagination for you through the globalFetchOptions by turning on the pagination: true option. The feature will automatically fetch all next_url pages of data when the API response indicates more data is available.
import { restClient } from '@polygon.io/client-js';
const rest = restClient(process.env.POLY_API_KEY);
const globalFetchOptions = {
pagination: true,
};
const rest = restClient("XXXX", "https://api.polygon.io", globalFetchOptions);
rest.getStocksAggregates("AAPL", 1, GetStocksAggregatesTimespanEnum.Day, "2023-01-01", "2023-04-14").then((data) => {
const resultCount = data.length;
console.log("Result count:", resultCount);
}).catch(e => {
console.error('An error happened:', e);
});
If there is a next_url field in the API response, the client will recursively fetch the next page for you, and then pass along the accumulated data.
If you found a bug or have an idea for a new feature, please first discuss it with us by submitting a new issue. We will respond to issues within at most 3 weeks. We're also open to volunteers if you want to submit a PR for any open issues but please discuss it with us beforehand. PRs that aren't linked to an existing issue or discussed with us ahead of time will generally be declined. If you have more general feedback or want to discuss using this client with other users, feel free to reach out on our Slack channel.
FAQs
Isomorphic Javascript client for Polygon.io Stocks, Forex, and Crypto APIs
The npm package @polygon.io/client-js receives a total of 11,617 weekly downloads. As such, @polygon.io/client-js popularity was classified as popular.
We found that @polygon.io/client-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.