diff --git a/README.md b/README.md index 4524460..a149f7b 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/index.d.ts b/index.d.ts index e7953c3..3948613 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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, diff --git a/index.js b/index.js index e9c7d92..8872775 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -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'); diff --git a/package-lock.json b/package-lock.json index 3063a70..47166ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "investing-com-api", - "version": "4.3.1", + "version": "4.3.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "investing-com-api", - "version": "4.3.1", + "version": "4.3.2", "license": "MIT", "dependencies": { "puppeteer": "^19.3.0" diff --git a/package.json b/package.json index e0402a0..7511686 100644 --- a/package.json +++ b/package.json @@ -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": {