-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·46 lines (33 loc) · 1.15 KB
/
app.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
// system dependencies
import AXIOS from "axios";
import dotenv from "dotenv";
import path from 'path';
// app modules
import { priceCheck } from './utils/business.js';
import { updateLogfile } from './utils/persistance.js';
// system setup
dotenv.config({ path: path.resolve() + "/.env" });
// app constants
const API = process.env.API;
const TRACKING_PAIR = process.env.TICKER_TRACKING_PAIRS;
const INTERVAL = process.env.TICKER_INTERVAL;
const PERCENTAGE_ALERT = process.env.TICKER_ALERT;
// app vars
var pairPrice = 0;
// app init log
console.log(`Getting data from ${API}`);
console.log(`Tracking ${TRACKING_PAIR} every ${INTERVAL / 1000} seconds`);
console.log(`Price alert percentage set to ${PERCENTAGE_ALERT}`);
// ticker start
setInterval(async () =>
AXIOS.get(`${API}${TRACKING_PAIR}`)
.then(response => {
if (priceCheck(PERCENTAGE_ALERT, pairPrice, response.data.ask))
{
pairPrice = response.data.ask;
console.log(`PRICE ALERT =====[ ${pairPrice} ]===== PRICE ALERT`);
updateLogfile(pairPrice);
}
})
.catch(error => {console.log(error)})
,INTERVAL);