8000 Update README.md (#150) · polygon-io/client-js@470a946 · GitHub
[go: up one dir, main page]

Skip to content

Commit 470a946

Browse files
Update README.md (#150)
* Update README.md Updated the readme to: - Match the Python and Go client libraries - Link to the example code snippets - Provide more examples * Update README.md Updated header text and first example.
1 parent 1ff04b5 commit 470a946

File tree

1 file changed

+49
-44
lines changed

1 file changed

+49
-44
lines changed

README.md

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,76 @@
1-
# [polygon.io](https://polygon.io)
1+
# Polygon JS Client
22

33
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
44

5-
## Upgrading to Version 7
5+
The official JS client library for the [Polygon](https://polygon.io/) REST and WebSocket API. Explore the [REST API](https://polygon.io/docs/stocks/getting-started) documentation and many example [code snippets](./examples/). Please see the [Release Notes](./CHANGELOG.md) for instructions on upgrading. To generate the package documentation please run `npm run generate-doc`.
66

7-
See the [Release Notes](./CHANGELOG.md) for instructions on upgrading to Version 7.
7+
## Getting the client
88

9-
## Install
9+
To get started, you'll need to install the client library:
1010

1111
```bash
1212
npm install --save @polygon.io/client-js
1313
```
1414

15-
## usage
15+
Next, create a new client with your [API key](https://polygon.io/dashboard/signup).
1616

17-
### Authentication
18-
19-
- call the desired client with your api key to initialize it
20-
21-
```typescript
22-
import { polygonClient, restClient, websocketClient } from "@polygon.io/client-js";
17+
```javascript
18+
const { restClient } = require('@polygon.io/client-js');
2319
const rest = restClient("API KEY");
24-
25-
// you can use the api now
26-
27-
rest.forex
28-
.previousClose("C:EURUSD")
29-
.then(/* your success handler */)
30-
.catch(/* your error handler*/);
3120
```
3221

33-
### [REST API](https://polygon.io/docs/stocks/getting-started)
22+
## Using the client
3423

35-
- import the rest submodule
36-
37-
```typescript
38-
import { restClient } from "@polygon.io/client-js";
39-
40-
const rest = restClient("API KEY");
24+
After creating the client, making calls to the Polygon API is easy. For example, here's how to get aggregates (bars):
4125

42-
rest.forex.previousClose("C:EURUSD").then(/* your success handler */);
26+
```javascript
27+
rest.stocks.aggregates("AAPL", 1, "day", "2023-01-01", "2023-04-14").then((data) => {
28+
console.log(data);
29+
}).catch(e => {
30+
console.error('An error happened:', e);
31+
});
4332
```
4433

45-
- import a specific submodule
46-
47-
```typescript
48-
import { referenceClient } from "@polygon.io/client-js";
34+
Or, maybe you want to get the last trades or quotes for a ticker:
35+
36+
```javascript
37+
// last trade
38+
rest.stocks.lastTrade("AAPL").then((data) => {
39+
console.log(data);
40+
}).catch(e => {
41+
console.error('An error happened:', e);
42+
});
43+
44+
// last quote (NBBO)
45+
rest.stocks.lastQuote("AAPL").then((data) => {
46+
console.log(data);
47+
}).catch(e => {
48+
console.error('An error happened:', e);
49+
});
50+
```
4951

50-
const reference = referenceClient("API KEY");
52+
Finally, maybe you want a market-wide snapshot of all tickers:
5153

52-
reference.tickers().then(/* your success handler */);
53-
reference.conditions({ asset_class: 'stocks', data_type: 'trades', sort: 'id' }).then(/* your success handler */)
54+
```javascript
55+
rest.stocks.snapshotAllTickers().then((data) => {
56+
console.log(data);
57+
}).catch(e => {
58+
console.error('An error happened:', e);
59+
});
5460
```
5561

62+
See [full examples](./examples/rest/) for more details on how to use this client effectively.
5663

57-
#### [For Launchpad Examples and Usage, see Polygon Launchpad Examples](examples/rest/launchpad/README.md)
64+
## Launchpad Usage
5865

59-
### [Websocket](https://polygon.io/docs/stocks/ws_getting-started)
66+
Users of the Launchpad product will need to pass in certain headers in order to make API requests. Example can be found [here](./examples/rest/launchpad/README.md).
6067

61-
You can get preauthenticated [websocket clients](https://www.npmjs.com/package/websocket) for the 3 topics.
68+
## WebSocket Client
6269

63-
```typescript
64-
import { websocketClient } from "@polygon.io/client-js";
70+
Import 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.
6571

72+
```javascript
73+
import { websocketClient } from "@polygon.io/client-js";
6674
const stocksWS = websocketClient("API KEY").stocks();
6775

6876
stocksWS.onmessage = ({data}) => {
@@ -82,11 +90,8 @@ stocksWS.onmessage = ({data}) => {
8290

8391
stocksWS.send({ action: "subscribe", params: "T.MSFT" });
8492
```
93+
See [full examples](./examples/websocket/) for more details on how to use this client effectively.
8594

86-
### documentation
95+
## Contributing
8796

88-
- Generate the package documentation
89-
90-
```bash
91-
npm run generate-doc
92-
```
97+
If 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).

0 commit comments

Comments
 (0)
0