{"id":13876128,"url":"https://github.com/polygon-io/client-js","last_synced_at":"2025-07-16T10:33:10.245Z","repository":{"id":37896984,"uuid":"215102045","full_name":"polygon-io/client-js","owner":"polygon-io","description":"The official JS client library for the Polygon REST and WebSocket API.","archived":false,"fork":false,"pushed_at":"2024-04-22T20:50:58.000Z","size":1346,"stargazers_count":167,"open_issues_count":11,"forks_count":56,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-23T20:47:24.256Z","etag":null,"topics":["api-client","javascript","js","lib","library","polygon","polygonio","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polygon-io.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-14T17:12:33.000Z","updated_at":"2024-06-02T10:57:46.253Z","dependencies_parsed_at":"2024-04-22T20:02:07.270Z","dependency_job_id":"2c6e1763-6951-487f-9d8b-25bf3669b052","html_url":"https://github.com/polygon-io/client-js","commit_stats":{"total_commits":156,"total_committers":27,"mean_commits":5.777777777777778,"dds":0.5833333333333333,"last_synced_commit":"856c83d0db086531c9f316b61513c7c1ba3bbcfe"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygon-io%2Fclient-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygon-io%2Fclient-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygon-io%2Fclient-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polygon-io%2Fclient-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polygon-io","download_url":"https://codeload.github.com/polygon-io/client-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226126067,"owners_count":17577472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","javascript","js","lib","library","polygon","polygonio","websocket"],"created_at":"2024-08-06T06:01:02.551Z","updated_at":"2025-07-16T10:33:10.228Z","avatar_url":"https://github.com/polygon-io.png","language":"TypeScript","readme":"# Polygon JS Client\n\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nWelcome to the official JS client library for the [Polygon](https://polygon.io/) REST and WebSocket API. To get started, please see the [Getting Started](https://polygon.io/docs/stocks/getting-started) section in our documentation, view the [examples](./examples/) directory for code snippets, or the [blog post](https://polygon.io/blog/javascript-stock-market-data/) with video tutorials to learn more. To generate the package documentation please run `npm run generate-doc`.\n\nFor upgrade instructions please see the [Release Notes](./CHANGELOG.md).\n\n## Getting the client\n\nTo get started, you'll need to install the client library:\n\n```bash\nnpm install --save '@polygon.io/client-js'\n```\n\nNext, create a new client with your [API key](https://polygon.io/dashboard/signup).\n\n```javascript\nimport { restClient } from '@polygon.io/client-js';\nconst rest = restClient(process.env.POLY_API_KEY);\n```\n\n## Using the client\n\nAfter creating the client, making calls to the Polygon API is easy. For example, here's how to get aggregates (bars):\n\n```javascript\nrest.stocks.aggregates(\"AAPL\", 1, \"day\", \"2023-01-01\", \"2023-04-14\").then((data) =\u003e {\n\tconsole.log(data);\n}).catch(e =\u003e {\n\tconsole.error('An error happened:', e);\n});\n```\n\nOr, maybe you want to get the last trades or quotes for a ticker:\n\n```javascript\n// last trade\nrest.stocks.lastTrade(\"AAPL\").then((data) =\u003e {\n\tconsole.log(data);\n}).catch(e =\u003e {\n\tconsole.error('An error happened:', e);\n});\n\n// last quote (NBBO)\nrest.stocks.lastQuote(\"AAPL\").then((data) =\u003e {\n\tconsole.log(data);\n}).catch(e =\u003e {\n\tconsole.error('An error happened:', e);\n});\n```\n\nFinally, maybe you want a market-wide snapshot of all tickers:\n\n```javascript\nrest.stocks.snapshotAllTickers().then((data) =\u003e {\n\tconsole.log(data);\n}).catch(e =\u003e {\n\tconsole.error('An error happened:', e);\n});\n```\n\nSee [full examples](./examples/rest/) for more details on how to use this client effectively.\nTo 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.\n\n## Pagination\n\nThe 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.\n\n```javascript\nimport('@polygon.io/client-js').then(({ restClient }) =\u003e {\n\tconst globalFetchOptions = {\n\t\tpagination: true,\n\t};\n\tconst rest = restClient(\"XXXX\", \"https://api.polygon.io\", globalFetchOptions);\n\trest.stocks.aggregates(\"TSLA\", 1, \"minute\", \"2022-01-01\", \"2023-08-31\", { limit: 50000 }).then((data) =\u003e {\n\t    const resultCount = data.length;\n\t    console.log(\"Result count:\", resultCount);\n\t}).catch(e =\u003e {\n\t\tconsole.error('An error happened:', e);\n\t});\n});\n```\n\nIf 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.\n\n## Debugging\n\nSometimes you may find it useful to see the actual request and response details while working with the API. The client allows for this through the `globalFetchOptions` by turning on the `trace: true` option.\n\n### How to Enable Debug Mode\n\nYou can activate the debug mode as follows:\n\n```javascript\nimport('@polygon.io/client-js').then(({ restClient }) =\u003e {\n\tconst globalFetchOptions = {\n\t\ttrace: true,\n\t};\n\tconst rest = restClient(\"XXXX\", \"https://api.polygon.io\", globalFetchOptions);\n\trest.stocks.aggregates(\"TSLA\", 1, \"minute\", \"2023-08-01\", \"2023-08-01\", { limit: 50000 }).then((data) =\u003e {\n\t    const resultCount = data.length;\n\t    console.log(\"Result count:\", resultCount);\n\t}).catch(e =\u003e {\n\t\tconsole.error('An error happened:', e);\n\t});\n});\n```\n\n### What Does Debug Mode Do?\n\nWhen debug mode is enabled, the client will print out useful debugging information for each API request. This includes: the request URL, the headers sent in the request, and the headers received in the response.\n\n### Example Output\n\nFor instance, if you made a request for `TSLA` data for the date `2023-08-01`, you would see debug output similar to the following:\n\n```\nRequest URL:  https://api.polygon.io/v2/aggs/ticker/TSLA/range/1/minute/2023-08-01/2023-08-01?limit=50000\nRequest Headers:  { Authorization: 'Bearer REDACTED' }\nResponse Headers:  Headers {\n  [Symbol(map)]: [Object: null prototype] {\n    server: [ 'nginx/1.19.2' ],\n    date: [ 'Thu, 06 Jul 2023 18:34:27 GMT' ],\n    'content-type': [ 'application/json' ],\n    'transfer-encoding': [ 'chunked' ],\n    connection: [ 'close' ],\n    'content-encoding': [ 'gzip' ],\n    vary: [ 'Accept-Encoding' ],\n    'x-request-id': [ '06dc97920681d8335c0451894aa1f79f' ],\n    'strict-transport-security': [ 'max-age=15724800; includeSubDomains' ]\n  }\n}\n```\n\nThis can be an invaluable tool for debugging issues or understanding how the client interacts with the API.\n\n## WebSocket Client\n\nImport the [Websocket](https://polygon.io/docs/stocks/ws_getting-started) client and models packages to get started. You can get preauthenticated [websocket clients](https://www.npmjs.com/package/websocket) for the 3 topics.\n\n```javascript\nimport { websocketClient } from \"@polygon.io/client-js\";\nconst stocksWS = websocketClient(process.env.POLY_API_KEY).stocks();\n\nstocksWS.onmessage = ({data}) =\u003e {\n  const [message] = JSON.parse(data);\n\n  stocksWS.send('{\"action\":\"subscribe\", \"params\":\"AM.MSFT,A.MSFT\"}');\n\n  switch (message.ev) {\n    case \"AM\":\n      // your trade message handler\n      break;\n    case \"A\":\n      // your trade message handler\n      break;\n  }\n};\n\nstocksWS.send({ action: \"subscribe\", params: \"T.MSFT\" });\n```\nSee [full examples](./examples/websocket/) for more details on how to use this client effectively.\n\n## Contributing\n\nIf you found a bug or have an idea for a new feature, please first discuss it with us by [submitting a new issue](https://github.com/polygon-io/client-js/issues/new/choose). 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](https://polygon-io.slack.com/archives/C03FCSBSAFL).\n","funding_links":[],"categories":["TypeScript","websocket"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolygon-io%2Fclient-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolygon-io%2Fclient-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolygon-io%2Fclient-js/lists"}