Skip to content

Commit 98b66a4

Browse files
authored
added ability to pass headers to client calls (#111)
* feat: added headers for select required endpoints * fix: update Readme.md for new launchpad header example * fix: incorrect param assignment * fix: README typo * fix: update summaries endpoint with header additions * fix: remove change of broken headers being passed * fix: update headers structure * chore: update docs and example location
1 parent 2cb63d4 commit 98b66a4

33 files changed

+229
-129
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const reference = referenceClient("api key");
4848
reference.tickers().then(/* your success handler */);
4949
```
5050

51+
#### [For Launchpad Examples and Usage, see Polygon Launchpad Examples](examples/rest/launchpad/README.md)
52+
5153
### [Websocket](https://polygon.io/docs/stocks/ws_getting-started)
5254

5355
You can get preauthenticated [websocket clients](https://www.npmjs.com/package/websocket) for the 3 topics.

examples/rest/launchpad/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
### [Launchpad REST API](https://polygon.io/docs/stocks/launchpad/getting-started)
2+
3+
- import all the rest submodule or a specific submodule
4+
5+
```typescript
6+
// The entire rest submodule
7+
import { restClient } from "@polygon.io/client-js";
8+
// A specific submodule, in this instance the reference client
9+
import { referenceClient } from "@polygon.io/client-js";
10+
11+
// Headers required to use the Launchpad product.
12+
const edgeHeaders = {
13+
// X-Polygon-Edge-ID is a required Launchpad header. It identifies the Edge User requesting data.
14+
'X-Polygon-Edge-ID': sampleEdgeID,
15+
// X-Polygon-Edge-IP-Address is a required Launchpad header. It denotes the originating IP Address of the Edge User requesting data.
16+
'X-Polygon-Edge-IP-Address': 192.0.2.1,
17+
// X-Polygon-Edge-User-Agent is an optional Launchpad header. It denotes the originating UserAgent of the Edge User requesting data.
18+
'X-Polygon-Edge-User-Agent': useragent
19+
}
20+
21+
const rest = restClient("api key", "https://api.polygon.io", edgeHeaders);
22+
rest.forex.previousClose("C:EURUSD").then(/* your success handler */);
23+
24+
const reference = referenceClient("api key", "https://api.polygon.io", edgeHeaders);
25+
reference.tickers().then(/* your success handler */);
26+
```

examples/rest/launchpad/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { restClient } from "@polygon.io/client-js";
2+
import { referenceClient } from "@polygon.io/client-js";
3+
4+
// Headers required to use the Launchpad product.
5+
const edgeHeaders = {
6+
// X-Polygon-Edge-ID is a required Launchpad header. It identifies the Edge User requesting data.
7+
'X-Polygon-Edge-ID': 'sampleEdgeID',
8+
// X-Polygon-Edge-IP-Address is a required Launchpad header. It denotes the originating IP Address of the Edge User requesting data.
9+
'X-Polygon-Edge-IP-Address': '192.0.2.1',
10+
// X-Polygon-Edge-User-Agent is an optional Launchpad header. It denotes the originating UserAgent of the Edge User requesting data.
11+
'X-Polygon-Edge-User-Agent': 'useragent'
12+
}
13+
14+
const rest = restClient("api key", "https://api.polygon.io", edgeHeaders);
15+
rest.forex.previousClose("C:EURUSD").then(/* your success handler */);
16+
17+
const reference = referenceClient("api key", "https://api.polygon.io", edgeHeaders);
18+
reference.tickers().then(/* your success handler */);
File renamed without changes.
File renamed without changes.

src/rest/crypto/aggregates.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// CF: https://polygon.io/docs/crypto/get_v2_aggs_ticker__cryptoTicker__range__multiplier___timespan___from___to
22

3-
import { get } from "../transport/request";
3+
import { get, IHeaders } from "../transport/request";
44
import { IAggsQuery, IAggs } from "../stocks/aggregates";
55

66
export const aggregates = async (
@@ -11,11 +11,13 @@ export const aggregates = async (
1111
timespan: string,
1212
from: string,
1313
to: string,
14-
query?: IAggsQuery
14+
query?: IAggsQuery,
15+
headers?: IHeaders,
1516
): Promise<IAggs> =>
1617
get(
1718
`/v2/aggs/ticker/${ticker}/range/${multiplier}/${timespan}/${from}/${to}`,
1819
apikey,
1920
apiBase,
20-
query
21+
query,
22+
headers
2123
);

src/rest/crypto/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { auth } from "../transport/request";
1+
import { auth, IHeaders } from "../transport/request";
22

33
import { IAggsQuery, IAggs } from "../stocks/aggregates";
44
import {
@@ -53,13 +53,14 @@ export interface ICryptoClient {
5353
timespan: string,
5454
from: string,
5555
to: string,
56-
query?: IAggsQuery
56+
query?: IAggsQuery,
57+
headers?: IHeaders
5758
) => Promise<IAggs>;
5859
aggregatesGroupedDaily: (
5960
date: string,
6061
query?: IAggsGroupedDailyQuery
6162
) => Promise<IAggsGroupedDaily>;
62-
summaries: (query?: ISummariesQuery) => Promise<ISummaries>;
63+
summaries: (query?: ISummariesQuery, headers?: IHeaders) => Promise<ISummaries>;
6364
dailyOpenClose: (
6465
from: string,
6566
to: string,
@@ -89,11 +90,12 @@ export interface ICryptoClient {
8990

9091
export const cryptoClient = (
9192
apiKey,
92-
apiBase = "https://api.polygon.io"
93+
apiBase = "https://api.polygon.io",
94+
headers?: IHeaders
9395
): ICryptoClient => ({
94-
aggregates: auth(apiKey, aggregates, apiBase),
96+
aggregates: auth(apiKey, aggregates, apiBase, headers),
9597
aggregatesGroupedDaily: auth(apiKey, aggregatesGroupedDaily, apiBase),
96-
summaries: auth(apiKey, summaries, apiBase),
98+
summaries: auth(apiKey, summaries, apiBase, headers),
9799
dailyOpenClose: auth(apiKey, dailyOpenClose, apiBase),
98100
lastTrade: auth(apiKey, lastTrade, apiBase),
99101
trades: auth(apiKey, trades, apiBase),

src/rest/crypto/summaries.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// CF:
1+
// CF: https://polygon.io/docs/crypto/launchpad/get_v1_summaries
22

3-
import { get } from "../transport/request";
3+
import { get, IHeaders } from "../transport/request";
44
import { ISummaries, ISummariesQuery } from "../stocks/summaries";
55

66
export const summaries = async (
77
apikey: string,
88
apiBase: string,
9-
query?: ISummariesQuery
9+
query?: ISummariesQuery,
10+
headers?: IHeaders
1011
): Promise<ISummaries> =>
1112
get(
1213
`/v1/summaries`,
1314
apikey,
1415
apiBase,
15-
query
16+
query,
17+
headers
1618
);

src/rest/forex/aggregates.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// CF: https://polygon.io/docs/forex/get_v2_aggs_ticker__forexTicker__range__multiplier___timespan___from___to
22

3-
import { get } from "../transport/request";
3+
import { get, IHeaders } from "../transport/request";
44
import { IAggsQuery, IAggs } from "../stocks/aggregates";
55

66
export const aggregates = async (
@@ -11,11 +11,13 @@ export const aggregates = async (
1111
timespan: string,
1212
from: string,
1313
to: string,
14-
query?: IAggsQuery
14+
query?: IAggsQuery,
15+
headers?: IHeaders
1516
): Promise<IAggs> =>
1617
get(
1718
`/v2/aggs/ticker/${ticker}/range/${multiplier}/${timespan}/${from}/${to}`,
1819
apikey,
1920
apiBase,
20-
query
21+
query,
22+
headers
2123
);

src/rest/forex/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { auth } from "../transport/request";
1+
import { auth, IHeaders } from "../transport/request";
22

33
import { IAggsQuery, IAggs } from "../stocks/aggregates";
44
import {
@@ -47,13 +47,14 @@ export interface IForexClient {
4747
timespan: string,
4848
from: string,
4949
to: string,
50-
query?: IAggsQuery
50+
query?: IAggsQuery,
51+
headers?: IHeaders
5152
) => Promise<IAggs>;
5253
aggregatesGroupedDaily: (
5354
date: string,
5455
query?: IAggsGroupedDailyQuery
5556
) => Promise<IAggsGroupedDaily>;
56-
summaries: (query?: ISummariesQuery) => Promise<ISummaries>;
57+
summaries: (query?: ISummariesQuery, headers?: IHeaders) => Promise<ISummaries>;
5758
conversion: (
5859
from: string,
5960
to: string,
@@ -79,11 +80,12 @@ export interface IForexClient {
7980

8081
export const forexClient = (
8182
apiKey: string,
82-
apiBase = "https://api.polygon.io"
83+
apiBase = "https://api.polygon.io",
84+
headers?: IHeaders
8385
): IForexClient => ({
84-
aggregates: auth(apiKey, aggregates, apiBase),
86+
aggregates: auth(apiKey, aggregates, apiBase, headers),
8587
aggregatesGroupedDaily: auth(apiKey, aggregatesGroupedDaily, apiBase),
86-
summaries: auth(apiKey, summaries, apiBase),
88+
summaries: auth(apiKey, summaries, apiBase, headers),
8789
conversion: auth(apiKey, conversion, apiBase),
8890
quotes: auth(apiKey, quotes, apiBase),
8991
lastQuote: auth(apiKey, lastQuote, apiBase),

0 commit comments

Comments
 (0)