-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.js
48 lines (44 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const axios = require('axios')
const { mapping } = require('./mapping')
const { mapResponse } = require('./functions')
function callInvesting (pairId) {
return axios({
method: 'GET',
url: 'https://www.investing.com/common/modules/js_instrument_chart/api/data.php',
params: {
pair_id: pairId,
pair_interval: '86400', // 1 day
chart_type: 'area', // 'area', 'candlestick'
candle_count: '90', // days
volume_series: 'yes',
events: 'yes',
period: '1-year'
},
headers: {
'Referer': 'https://www.investing.com/',
'X-Requested-With': 'XMLHttpRequest'
}
})
}
async function investing (input) {
try {
if (!input) {
throw Error('Parameter input is required')
}
const endpoint = mapping[input]
if (!endpoint) {
throw Error(`No mapping found for ${input}, check mapping.js`)
}
const response = await callInvesting(endpoint.pairId)
if (!response.data.candles) {
throw Error('No response.data.candles found')
}
const results = mapResponse(response.data.candles)
// console.log(results)
return results
} catch (err) {
console.log(err.message)
}
}
// investing('equities/netflix,-inc.')
exports.investing = investing