-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Nasdaq new components #18158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Nasdaq new components #18158
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
...onents/nasdaq_data_link_time_series_and_table_data_/actions/export-table/export-table.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import app from "../../nasdaq_data_link_time_series_and_table_data_.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "nasdaq_data_link_time_series_and_table_data_-export-table", | ||
name: "Export Table (Bulk Download)", | ||
description: "Exports an entire table or a filtered subset as a zipped CSV file. Returns a download link for the data. Premium subscribers can use this feature up to 60 times per hour. [See the documentation](https://docs.data.nasdaq.com/docs/large-table-download)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
publisher: { | ||
propDefinition: [ | ||
app, | ||
"publisher", | ||
], | ||
}, | ||
table: { | ||
propDefinition: [ | ||
app, | ||
"table", | ||
], | ||
}, | ||
columns: { | ||
propDefinition: [ | ||
app, | ||
"columns", | ||
({ | ||
publisher, table, | ||
}) => ({ | ||
publisher, | ||
table, | ||
}), | ||
], | ||
}, | ||
filters: { | ||
type: "object", | ||
label: "Row Filters", | ||
description: "Filter rows based on column values. Use column names as keys and values to filter by. For example: `{ \"ticker\": \"SPY\", \"date\": \"2024-01-01\" }`. Only filterable columns can be used (check table metadata).", | ||
optional: true, | ||
}, | ||
filterOperators: { | ||
type: "object", | ||
label: "Filter Operators", | ||
description: "Apply operators to filters. Format: `{ \"column.operator\": \"value\" }`. Available operators: `.gt` (greater than), `.lt` (less than), `.gte` (greater than or equal), `.lte` (less than or equal). Example: `{ \"date.gte\": \"2024-01-01\", \"date.lte\": \"2024-12-31\" }`", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
publisher, | ||
table, | ||
columns, | ||
filters, | ||
filterOperators, | ||
} = this; | ||
|
||
const response = await app.tableData({ | ||
$, | ||
publisher, | ||
table, | ||
params: { | ||
"qopts.export": true, | ||
...utils.parseJson(filters), | ||
...utils.parseJson(filterOperators), | ||
...(Array.isArray(columns) && columns?.length | ||
? { | ||
"qopts.columns": columns.join(","), | ||
} | ||
: undefined | ||
), | ||
}, | ||
}); | ||
|
||
const status = response?.datatable_bulk_download?.file?.status; | ||
const link = response?.datatable_bulk_download?.file?.link; | ||
|
||
if (status === "fresh" && link) { | ||
$.export("$summary", `Table ${publisher}/${table} is ready for download. The download link is valid for 30 minutes.`); | ||
|
||
} else if (status === "creating" || status === "regenerating") { | ||
$.export("$summary", `Export job for table ${publisher}/${table} is ${status}. Please retry in a few moments to get the download link.`); | ||
|
||
} else { | ||
$.export("$summary", `Export initiated for table ${publisher}/${table}`); | ||
} | ||
|
||
return response; | ||
}, | ||
}; |
81 changes: 81 additions & 0 deletions
81
...ts/nasdaq_data_link_time_series_and_table_data_/actions/get-table-data/get-table-data.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import app from "../../nasdaq_data_link_time_series_and_table_data_.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "nasdaq_data_link_time_series_and_table_data_-get-table-data", | ||
name: "Get Table Data", | ||
description: "Retrieves data from a specific Nasdaq Data Link table with automatic pagination. Supports filtering by columns and rows. [See the documentation](https://docs.data.nasdaq.com/docs/tables-1)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
publisher: { | ||
propDefinition: [ | ||
app, | ||
"publisher", | ||
], | ||
}, | ||
table: { | ||
propDefinition: [ | ||
app, | ||
"table", | ||
], | ||
}, | ||
columns: { | ||
propDefinition: [ | ||
app, | ||
"columns", | ||
({ | ||
publisher, table, | ||
}) => ({ | ||
publisher, | ||
table, | ||
}), | ||
], | ||
}, | ||
filters: { | ||
type: "object", | ||
label: "Row Filters", | ||
description: "Filter rows based on column values. Use column names as keys and values to filter by. For example: `{ \"ticker\": \"SPY\", \"date\": \"2024-01-01\" }`. Only filterable columns can be used (check table metadata).", | ||
optional: true, | ||
}, | ||
filterOperators: { | ||
type: "object", | ||
label: "Filter Operators", | ||
description: "Apply operators to filters. Format: `{ \"column.operator\": \"value\" }`. Available operators: `.gt` (greater than), `.lt` (less than), `.gte` (greater than or equal), `.lte` (less than or equal). Example: `{ \"date.gte\": \"2024-01-01\", \"date.lte\": \"2024-12-31\" }`", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
publisher, | ||
table, | ||
columns, | ||
filters, | ||
filterOperators, | ||
} = this; | ||
|
||
const response = await app.paginate({ | ||
fn: app.tableData, | ||
args: { | ||
$, | ||
publisher, | ||
table, | ||
params: { | ||
...utils.parseJson(filters), | ||
...utils.parseJson(filterOperators), | ||
...(Array.isArray(columns) && columns?.length | ||
? { | ||
"qopts.columns": columns.join(","), | ||
} | ||
: undefined | ||
), | ||
}, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}); | ||
|
||
$.export("$summary", `Successfully retrieved ${response.length} records`); | ||
return response; | ||
}, | ||
}; |
40 changes: 40 additions & 0 deletions
40
...q_data_link_time_series_and_table_data_/actions/get-table-metadata/get-table-metadata.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import app from "../../nasdaq_data_link_time_series_and_table_data_.app.mjs"; | ||
|
||
export default { | ||
key: "nasdaq_data_link_time_series_and_table_data_-get-table-metadata", | ||
name: "Get Table Metadata", | ||
description: "Retrieves metadata for a specific Nasdaq Data Link table, including column names, types, filterable columns, and primary keys. [See the documentation](https://docs.data.nasdaq.com/docs/tables-1)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
publisher: { | ||
propDefinition: [ | ||
app, | ||
"publisher", | ||
], | ||
}, | ||
table: { | ||
propDefinition: [ | ||
app, | ||
"table", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
publisher, | ||
table, | ||
} = this; | ||
|
||
const response = await app.tableMetadata({ | ||
$, | ||
publisher, | ||
table, | ||
}); | ||
|
||
$.export("$summary", `Successfully retrieved metadata for table \`${publisher}/${table}\``); | ||
return response; | ||
}, | ||
}; |
44 changes: 44 additions & 0 deletions
44
components/nasdaq_data_link_time_series_and_table_data_/common/utils.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const parseJson = (input, maxDepth = 100) => { | ||
const seen = new WeakSet(); | ||
const parse = (value) => { | ||
if (maxDepth <= 0) { | ||
return value; | ||
} | ||
if (typeof(value) === "string") { | ||
// Only parse if the string looks like a JSON object or array | ||
const trimmed = value.trim(); | ||
if ( | ||
(trimmed.startsWith("{") && trimmed.endsWith("}")) || | ||
(trimmed.startsWith("[") && trimmed.endsWith("]")) | ||
) { | ||
try { | ||
return parseJson(JSON.parse(value), maxDepth - 1); | ||
} catch (e) { | ||
return value; | ||
} | ||
} | ||
return value; | ||
} else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) { | ||
if (seen.has(value)) { | ||
return value; | ||
} | ||
seen.add(value); | ||
return Object.entries(value) | ||
.reduce((acc, [ | ||
key, | ||
val, | ||
]) => Object.assign(acc, { | ||
[key]: parse(val), | ||
}), {}); | ||
} else if (Array.isArray(value)) { | ||
return value.map((item) => parse(item)); | ||
} | ||
return value; | ||
}; | ||
|
||
return parse(input); | ||
}; | ||
|
||
export default { | ||
parseJson, | ||
}; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
103 changes: 99 additions & 4 deletions
103
...ata_link_time_series_and_table_data_/nasdaq_data_link_time_series_and_table_data_.app.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,106 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "nasdaq_data_link_time_series_and_table_data_", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
publisher: { | ||
type: "string", | ||
label: "Publisher Code", | ||
description: "The publisher code (e.g., `MER`, `ETFG`, `AR`, `NDAQ`). This is the first part of the datatable code. If the code is `MER/F1`, then `MER` is the publisher code and `F1` is the table code.", | ||
}, | ||
table: { | ||
type: "string", | ||
label: "Table Code", | ||
description: "The table code (e.g., `F1`, `FUND`, `MWCS`, `RTAT10`). This is the second part of the datatable code. If the code is `MER/F1`, then `F1` is the table code.", | ||
}, | ||
columns: { | ||
type: "string[]", | ||
label: "Columns", | ||
description: "Request data from specific columns. If you want to query for multiple columns, include the column names as array items", | ||
optional: true, | ||
async options({ | ||
publisher, table, | ||
}) { | ||
if (!publisher || !table) { | ||
return []; | ||
} | ||
const { datatable: { columns } } = await this.tableMetadata({ | ||
publisher, | ||
table, | ||
}); | ||
return columns.map(({ name }) => name); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
getUrl(path) { | ||
return `https://data.nasdaq.com/api/v3${path}`; | ||
}, | ||
getHeaders(headers) { | ||
return { | ||
...headers, | ||
"Accept": "application/json", | ||
"X-Api-Token": this.$auth.api_key, | ||
}; | ||
}, | ||
makeRequest({ | ||
$ = this, path, headers, ...args | ||
} = {}) { | ||
return axios($, { | ||
...args, | ||
url: this.getUrl(path), | ||
headers: this.getHeaders(headers), | ||
}); | ||
}, | ||
tableMetadata({ | ||
publisher, table, ...args | ||
}) { | ||
return this.makeRequest({ | ||
path: `/datatables/${publisher}/${table}/metadata.json`, | ||
...args, | ||
}); | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
tableData({ | ||
publisher, table, ...args | ||
}) { | ||
return this.makeRequest({ | ||
path: `/datatables/${publisher}/${table}.json`, | ||
...args, | ||
}); | ||
}, | ||
async paginate({ | ||
fn, args = {}, maxRequests = 3, | ||
} = {}) { | ||
let allData = []; | ||
let cursorId = null; | ||
let requestCount = 0; | ||
let hasMorePages = true; | ||
|
||
while (hasMorePages && requestCount < maxRequests) { | ||
const response = await fn({ | ||
...args, | ||
params: { | ||
...args.params, | ||
"qopts.per_page": 100, | ||
...(cursorId | ||
? { | ||
"qopts.cursor_id": cursorId, | ||
} | ||
: undefined | ||
), | ||
}, | ||
}); | ||
|
||
const pageData = response?.datatable?.data || []; | ||
allData = allData.concat(pageData); | ||
|
||
cursorId = response?.meta?.next_cursor_id; | ||
hasMorePages = !!cursorId; | ||
requestCount++; | ||
} | ||
|
||
return allData; | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.