This repository was archived by the owner on Jan 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphavantage.js
More file actions
51 lines (50 loc) · 1.92 KB
/
alphavantage.js
File metadata and controls
51 lines (50 loc) · 1.92 KB
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
49
50
51
const https = require('https');
let APIKey;
module.exports = {
timeSeriesMonthly: (equity) => {
return timeSeries(equity, 'TIME_SERIES_MONTHLY', 'Monthly Time Series')
},
timeSeriesMonthlyAdjusted: (equity) => {
return timeSeries(equity, 'TIME_SERIES_MONTHLY_ADJUSTED', 'Monthly Adjusted Time Series')
},
timeSeriesWeekly: (equity) => {
return timeSeries(equity, 'TIME_SERIES_WEEKLY', 'Weekly Time Series')
},
timeSeriesWeeklyAdjusted: (equity) => {
return timeSeries(equity, 'TIME_SERIES_WEEKLY_ADJUSTED', 'Weekly Adjusted Time Series')
},
timeSeriesDaily: (equity) => {
return timeSeries(equity, 'TIME_SERIES_DAILY', 'Time Series (Daily)')
},
timeSeriesDailyAdjusted: (equity) => {
return timeSeries(equity, 'TIME_SERIES_DAILY_ADJUSTED', 'Time Series (Daily)')
},
timeSeriesDailyFull: (equity) => {
return new Promise((res, rej) => {
https.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=' + equity + '&apikey=' + APIKey + '&outputsize=full', (req) => {
let arr = [];
req.on('data', d => arr.push(d));
req.on('end', () => res(JSON.parse(arr.join(''))['Time Series (Daily)']));
});
});
},
timeSeriesDailyAdjustedFull: (equity) => {
return new Promise((res, rej) => {
https.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=' + equity + '&apikey=' + APIKey + '&outputsize=full', (req) => {
let arr = [];
req.on('data', d => arr.push(d));
req.on('end', () => res(JSON.parse(arr.join(''))['Time Series (Daily)']));
});
});
},
key: ''
}
async function timeSeries(equity, func, data) {
return new Promise((res, rej) => {
https.get('https://www.alphavantage.co/query?function=' + func + '&symbol=' + equity + '&apikey=' + APIKey, (req) => {
let arr = [];
req.on('data', d => arr.push(d));
req.on('end', () => res(JSON.parse(arr.join(''))[data]));
});
});
}