-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (52 loc) · 1.48 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require('express');
const notifier = require('node-notifier');
const app = express();
require('dotenv').config();
const monit = async() => {
// Imports
const perf = require('execution-time')()
const { providers } = require('ethers')
const Uniswap = require('./src/exchanges/uniswap')
// Instances
const provider = new providers.InfuraProvider('homestead', {
projectId: process.env.INFURA_PROJECT_ID,
projectSecret: process.env.INFURA_PROJECT_SECRET,
})
const uniswap = new Uniswap(provider)
// Functions
const logPrice = (message, price) => console.log(message, price.toSignificant(10))
// Get prices
perf.start()
const wethDai = uniswap.getPrice({
from: 'weth',
to: 'dai',
})
const wbtcDai = uniswap.getPrice({
from: 'wbtc',
to: 'dai',
})
const btcEthTrade = uniswap.getTrade({
from: 'wbtc',
to: 'weth',
amount: 1,
})
await Promise.all([
wethDai,
wbtcDai,
btcEthTrade,
])
const ethPrice = await wethDai;
console.log(`Response delay: ${perf.stop().preciseWords}`)
notifier.notify({
'title': 'Current ETH Price',
'ETH Price': 'ETH Price Notifier',
'message': `Current ETH price is $${ethPrice.toSignificant(10)}`,
'wait': true,
'icon': './src/icon/ethereum.png',
})
}
const main = () => {
monit();
setInterval(monit, 60000);
}
app.listen(5000, main);