Skip to content

Commit

Permalink
Add pptrLaunchOptions, fix #90
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideViolante committed Feb 8, 2023
1 parent a407489 commit 1396e55
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Only input is required, other params are optional.
- **period** _String_: Period of time, window size. Default P1M (1 month). Valid values: P1D, P1W, P1M, P3M, P6M, P1Y, P5Y, MAX.
- **interval** _Number_: Interval between results. Default P1D (1 day). Valid values: PT1M, PT5M, PT15M, PT30M, PT1H, PT5H, P1D, P1W, P1M.
- **pointscount** _Number_: number of total results. Valid values seems to be 60, 70 or 120.
- **pptrLaunchOptions** _Any_: Puppeteer launch options, see [official website](https://pptr.dev/api/puppeteer.launchoptions).

### Run tests
`npm test`
Expand Down
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ declare module "investing-com-api" {
input: string,
period?: 'P1D' | 'P1W' | 'P1M' | 'P3M' | 'P6M' | 'P1Y' | 'P5Y' | 'MAX',
interval?: 'PT1M' | 'PT5M' | 'PT15M' | 'PT30M' | 'PT1H' | 'PT5H' | 'P1D' | 'P1W' | 'P1M',
pointscount?: 60 | 70 | 120
pointscount?: 60 | 70 | 120,
pptrLaunchOptions?: any,
): Promise<{
date: number,
value: number,
Expand Down
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ function checkParams(input, period, interval, pointscount) {
}

/**
* Call Investing
* Call Investing website
* @param {string} pairId Input string, see mapping.js keys, or provide a valid investing.com pairId
* @param {string} period Period of time, window size.
* Valid values: P1D, P1W, P1M, P3M, P6M, P1Y, P5Y, MAX
* @param {string} interval Interval between results.
* Valid values: PT1M, PT5M, PT15M, PT30M, PT1H, PT5H, P1D, P1W, P1M
* @param {number} pointscount Number of results returned. Valid values: 60, 70, 120
* @param {*} pptrLaunchOptions Puppeteer launch options, see https://pptr.dev/api/puppeteer.launchoptions
* @return {Array} An array of objects with date (timestamp) and value (number) properties
*/
async function callInvesting(pairId, period, interval, pointscount) {
const browser = await puppeteer.launch();
async function callInvesting(pairId, period, interval, pointscount, pptrLaunchOptions) {
const browser = await puppeteer.launch(pptrLaunchOptions);
const page = await browser.newPage();
// eslint-disable-next-line max-len
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36');
Expand All @@ -51,21 +52,22 @@ async function callInvesting(pairId, period, interval, pointscount) {
}

/**
* Call Investing
* Investing
* @param {string} input Input string, see mapping.js keys, or provide a valid investing.com pairId
* @param {string} period Period of time, window size. Default P1M (1 month)
* @param {string} [period] Period of time, window size. Default P1M (1 month)
* Valid values: P1D, P1W, P1M, P3M, P6M, P1Y, P5Y, MAX
* @param {string} interval Interval between results. Default P1D (1 day)
* @param {string} [interval] Interval between results. Default P1D (1 day)
* Valid values: PT1M, PT5M, PT15M, PT30M, PT1H, PT5H, P1D, P1W, P1M
* @param {number} pointscount Number of results returned, but depends on period and interval too.
* @param {number} [pointscount] Number of results returned, but depends on period and interval too.
* Valid values: 60, 70, 120
* @param {*} [pptrLaunchOptions] Puppeteer launch options, see https://pptr.dev/api/puppeteer.launchoptions
* @return {Array} An array of objects with date (timestamp) and value (number) properties
*/
async function investing(input, period = 'P1M', interval = 'P1D', pointscount = 120) {
async function investing(input, period = 'P1M', interval = 'P1D', pointscount = 120, pptrLaunchOptions) {
try {
checkParams(input, period, interval, pointscount);
const pairId = mapping[input]?.pairId || input;
const { data } = await callInvesting(pairId, period, interval, pointscount);
const { data } = await callInvesting(pairId, period, interval, pointscount, pptrLaunchOptions);
const results = mapResponse(data);
if (!results.length) {
throw Error('Wrong input or pairId');
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "investing-com-api",
"version": "4.3.1",
"version": "4.3.2",
"description": "Unofficial APIs for Investing.com website.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1396e55

Please sign in to comment.