Skip to content

Commit 950b927

Browse files
committed
[Components] polygon #15141
Sources - New Market Trade - New Market News - New Stock Price Summary Actions - Get Stock Price - Get Historical Prices - Get Company
1 parent d7a4a38 commit 950b927

File tree

14 files changed

+530
-382
lines changed

14 files changed

+530
-382
lines changed

components/polygon/actions/get-company-financials/get-company-financials.mjs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import {
2+
SORT_HISTORICAL_OPTIONS,
3+
SORT_OPTIONS, TIMEFRAME_OPTIONS,
4+
} from "../../common/constants.mjs";
15
import polygon from "../../polygon.app.mjs";
2-
import { axios } from "@pipedream/platform";
36

47
export default {
58
key: "polygon-get-company-financials",
69
name: "Get Company Financials",
710
description: "Retrieves financial details for a specific company by stock ticker. [See the documentation](https://polygon.io/docs/stocks/get_v3_reference_financials).",
8-
version: "0.0.{{ts}}",
11+
version: "0.0.1",
912
type: "action",
1013
props: {
1114
polygon,
@@ -15,9 +18,66 @@ export default {
1518
"stockTicker",
1619
],
1720
},
21+
filingDate: {
22+
type: "string",
23+
label: "Filing Date",
24+
description: `Query by the date when the filing with financials data was filed in **YYYY-MM-DD** format.
25+
\nBest used when querying over date ranges to find financials based on filings that happen in a time period.
26+
\nExamples:
27+
\nTo get financials based on filings that have happened after January 1, 2009 use the query param filing_date.gte=2009-01-01
28+
\nTo get financials based on filings that happened in the year 2009 use the query params filing_date.gte=2009-01-01&filing_date.lt=2010-01-01`,
29+
optional: true,
30+
},
31+
periodOfReportDate: {
32+
type: "string",
33+
label: "Period Of Report Date",
34+
description: "The period of report for the filing with financials data in **YYYY-MM-DD** format.",
35+
optional: true,
36+
},
37+
timeframe: {
38+
type: "string",
39+
label: "Timeframe",
40+
description: "Query by timeframe. Annual financials originate from 10-K filings, and quarterly financials originate from 10-Q filings. Note: Most companies do not file quarterly reports for Q4 and instead include those financials in their annual report, so some companies my not return quarterly financials for Q4",
41+
options: TIMEFRAME_OPTIONS,
42+
optional: true,
43+
},
44+
order: {
45+
type: "string",
46+
label: "Order",
47+
description: "Order results based on the `Sort` field.",
48+
options: SORT_OPTIONS,
49+
optional: true,
50+
},
51+
limit: {
52+
type: "integer",
53+
label: "Limit",
54+
description: "Limit the number of results returned.",
55+
optional: true,
56+
min: 1,
57+
max: 100,
58+
default: 10,
59+
},
60+
sort: {
61+
type: "string",
62+
label: "Sort",
63+
description: "Sort field used for ordering",
64+
options: SORT_HISTORICAL_OPTIONS,
65+
optional: true,
66+
},
1867
},
1968
async run({ $ }) {
20-
const financialDetails = await this.polygon.getFinancialDetails();
69+
const financialDetails = await this.polygon.getFinancialDetails({
70+
$,
71+
params: {
72+
stockTicker: this.stockTicker,
73+
filingDate: this.filingDate,
74+
periodOfReportDate: this.periodOfReportDate,
75+
timeframe: this.timeframe,
76+
order: this.order,
77+
limit: this.limit,
78+
sort: this.sort,
79+
},
80+
});
2181
$.export("$summary", `Successfully retrieved financial details for ${this.stockTicker}`);
2282
return financialDetails;
2383
},
Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import {
2+
SORT_OPTIONS,
3+
TIMESPAN_OPTIONS,
4+
} from "../../common/constants.mjs";
15
import polygon from "../../polygon.app.mjs";
2-
import { axios } from "@pipedream/platform";
36

47
export default {
58
key: "polygon-get-historical-prices",
69
name: "Get Historical Prices",
7-
description: "Fetches historical price data for a specified stock ticker within a date range. [See the documentation]()",
8-
version: "0.0.{{ts}}",
10+
description: "Fetches historical price data for a specified stock ticker within a date range. [See the documentation](https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__range__multiplier___timespan___from___to)",
11+
version: "0.0.1",
912
type: "action",
1013
props: {
1114
polygon,
@@ -15,22 +18,67 @@ export default {
1518
"stockTicker",
1619
],
1720
},
18-
fromDate: {
19-
propDefinition: [
20-
polygon,
21-
"fromDate",
22-
],
21+
multiplier: {
22+
type: "integer",
23+
label: "Multiplier",
24+
description: "The size of the timespan multiplier.",
25+
default: 1,
26+
},
27+
timespan: {
28+
type: "string",
29+
label: "Timespan",
30+
description: "The size of the time window.",
31+
options: TIMESPAN_OPTIONS,
2332
},
24-
toDate: {
33+
from: {
34+
type: "string",
35+
label: "From Date",
36+
description: "The start of the aggregate time window. Either a date with the format **YYYY-MM-DD** or a millisecond timestamp.",
37+
},
38+
to: {
39+
type: "string",
40+
label: "To Date",
41+
description: "The end of the aggregate time window. Either a date with the format **YYYY-MM-DD** or a millisecond timestamp.",
42+
},
43+
adjusted: {
2544
propDefinition: [
2645
polygon,
27-
"toDate",
46+
"adjusted",
2847
],
48+
optional: true,
49+
},
50+
sort: {
51+
type: "string",
52+
label: "Sort",
53+
description: "Sort the results by timestamp. asc will return results in ascending order (oldest at the top), desc will return results in descending order (newest at the top).",
54+
options: SORT_OPTIONS,
55+
optional: true,
56+
},
57+
limit: {
58+
type: "integer",
59+
label: "Limit",
60+
description: "Limits the number of base aggregates queried to create the aggregate results. Max 50000 and Default 5000. Read more about how limit is used to calculate aggregate results in our article on [Aggregate Data API Improvements](https://polygon.io/blog/aggs-api-updates).",
61+
optional: true,
62+
min: 1,
63+
max: 5000,
64+
defalt: 5000,
2965
},
3066
},
3167
async run({ $ }) {
32-
const response = await this.polygon.getHistoricalPriceData();
33-
$.export("$summary", `Fetched historical prices for ${this.stockTicker} from ${this.fromDate} to ${this.toDate}.`);
68+
const response = await this.polygon.getHistoricalPriceData({
69+
$,
70+
stockTicker: this.stockTicker,
71+
multiplier: this.multiplier,
72+
timespan: this.timespan,
73+
from: this.from,
74+
to: this.to,
75+
params: {
76+
adjusted: this.adjusted,
77+
sort: this.sort,
78+
limit: this.limit,
79+
},
80+
});
81+
$.export("$summary", `Fetched historical prices for ${this.stockTicker} from ${this.from} to ${this.to}.`);
3482
return response;
3583
},
3684
};
Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,51 @@
11
import polygon from "../../polygon.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "polygon-get-stock-price",
65
name: "Get Stock Price",
7-
description: "Retrieves the current price of a specified stock ticker. [See the documentation]()",
8-
version: "0.0.{{ts}}",
6+
description: "Get the open, close and afterhours prices of a stock symbol on a certain date. [See the documentation](https://polygon.io/docs/stocks/get_v1_open-close__stocksticker___date)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
polygon,
1211
stockTicker: {
1312
propDefinition: [
14-
"polygon",
13+
polygon,
1514
"stockTicker",
1615
],
1716
},
17+
date: {
18+
type: "string",
19+
label: "Date",
20+
description: "The date of the requested open/close in the format YYYY-MM-DD.",
21+
},
22+
adjusted: {
23+
propDefinition: [
24+
polygon,
25+
"adjusted",
26+
],
27+
optional: true,
28+
},
1829
},
1930
async run({ $ }) {
20-
const response = await this.polygon.getCurrentPrice();
21-
const currentPrice = response?.tickers?.[0]?.lastTrade?.p;
31+
try {
32+
33+
const response = await this.polygon.getCurrentPrice({
34+
$,
35+
date: this.date,
36+
stockTicker: this.stockTicker,
37+
params: {
38+
adjusted: this.adjusted,
39+
},
40+
});
2241

23-
$.export("$summary", `Current price of ${this.stockTicker} is $${currentPrice}`);
24-
return response;
42+
$.export("$summary", `Successfully fetched the price of ${this.stockTicker}`);
43+
return response;
44+
} catch ({ response }) {
45+
if (response.status === 404) {
46+
$.export("$summary", `No data found for ${this.stockTicker}`);
47+
return {};
48+
}
49+
}
2550
},
2651
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const TIMESPAN_OPTIONS = [
2+
"second",
3+
"minute",
4+
"hour",
5+
"day",
6+
"week",
7+
"month",
8+
"quarter",
9+
"year",
10+
];
11+
12+
export const TIMEFRAME_OPTIONS = [
13+
"annual",
14+
"quarterly",
15+
"ttm",
16+
];
17+
18+
export const SORT_OPTIONS = [
19+
"asc",
20+
"desc",
21+
];
22+
23+
export const SORT_HISTORICAL_OPTIONS = [
24+
"filing_date",
25+
"period_of_report_date",
26+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const parseNextPage = (nextUrl = null) => {
2+
if (nextUrl) {
3+
const url = new URL(nextUrl);
4+
nextUrl = url.searchParams.get("cursor");
5+
}
6+
return nextUrl;
7+
};

components/polygon/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/polygon",
3+
"version": "0.1.0",
4+
"description": "Pipedream Polygon Components",
5+
"main": "polygon.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"polygon"
9+
],
10+
"homepage": "https://pipedream.com/apps/polygon",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
17+
}
18+
}

0 commit comments

Comments
 (0)