• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The official JS client library for the Polygon REST and WebSocket API.

Polygon JS Client

code style: prettier

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.

Getting the client

To get started, you'll need to install the client library:

npm install --save @polygon.io/client-js

Next, create a new client with your API key.

import { restClient } from '@polygon.io/client-js';
const rest = restClient(process.env.POLY_API_KEY);

Using the client

After creating the client, making calls to the Polygon API is easy. For example, here's how to get aggregates (bars):

rest.stocks.aggregates("AAPL", 1, "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.stocks.lastTrade("AAPL").then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});

// last quote (NBBO)
rest.stocks.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.snapshotAllTickers().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.

Launchpad Usage

Users of the Launchpad product will need to pass in certain headers in order to make API requests. Example can be found here.

WebSocket Client

Import the Websocket client and models packages to get started. You can get preauthenticated websocket clients for the 3 topics.

import { websocketClient } from "@polygon.io/client-js";
const stocksWS = websocketClient(process.env.POLY_API_KEY).stocks();

stocksWS.onmessage = ({data}) => {
  const [message] = JSON.parse(data);

  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" });

See full examples for more details on how to use this client effectively.

Contributing

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.

More Repositories

1

client-python

The official Python client library for the Polygon REST and WebSocket API.
Python
801
star
2

client-go

The official Go client library for the Polygon REST and WebSocket API.
Go
127
star
3

go-app-ticker-wall

Scalable Stock Ticker Tape
Go
107
star
4

tradingview-adapter

JS Library for using Polygon.io with TradingView charting.
JavaScript
87
star
5

client-examples

Examples of how to connect to Polygon.io
85
star
6

client-jvm

The official JVM client library SDK, written in Kotlin, for accessing the Polygon REST and WebSocket API.
Kotlin
50
star
7

issues

Quickly track and report problems with polygon.io
29
star
8

client-php

The official PHP client library for the Polygon REST APIs.
PHP
28
star
9

xbrl-parser

A Go library to parse xbrl documents into their facts, contexts, and units.
Go
22
star
10

errands-server

Errands API Server. A language agnostic, HTTP based queue
Go
19
star
11

client-cs

C#
9
star
12

selenium-on-kubernetes

Kube files for deploying Selenium Hub and Nodes on Kubernetes
8
star
13

ui-swagger

Swagger UI for Polygon.io Docs.
JavaScript
7
star
14

go-multicast-dump

Dump multicast data to stdout
Go
4
star
15

errands-js

NodeJS Client for Errands
JavaScript
3
star
16

wordpress-plugins

Wordpress Plugins by Polygon.io
PHP
2
star
17

contentful-markdown-plugin

A Contentful Plugin to replace images created in the markdown editor with SEO-friendly HTML img tags that include alt, height, width, and title attributes
TypeScript
2
star
18

client-r

1
star
19

legendary-sniffle

People like forking this repo
1
star
20

errands-go

Golang client for Errands API server
Go
1
star