-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhandler.js
More file actions
30 lines (25 loc) · 762 Bytes
/
handler.js
File metadata and controls
30 lines (25 loc) · 762 Bytes
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
const axios = require('axios');
const sendMail = require('./sendMail.js');
const CONSTANTS = require('./constants');
module.exports.mmiAlert = async () => {
const url =
'https://api.tickertape.in/mmi/now';
try {
const response = await axios.get(url);
const mmi = Math.trunc(response.data.data.currentValue);
let zone;
const extremeGreed = mmi > CONSTANTS.MMI_UPPER_BOUND;
const extremeFear = mmi < CONSTANTS.MMI_LOWER_BOUND;
if (extremeGreed) {
zone = CONSTANTS.ZONES.GREED;
await sendMail(zone, mmi);
} else if (extremeFear) {
zone = CONSTANTS.ZONES.FEAR;
await sendMail(zone, mmi);
}
return null;
} catch (error) {
console.log('An error occurred:');
console.log(error);
}
};