-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
68 lines (60 loc) · 2.5 KB
/
app.js
File metadata and controls
68 lines (60 loc) · 2.5 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require('dotenv').config()
const express = require('express')
const morgan = require('morgan')
const helmet = require('helmet')
const twitter = require('./twitter.js')
const uniswap = require('./uniswap.js')
const app = express()
app.use(helmet())
app.use(morgan('combined'))
app.use(express.static('public'))
app.use(express.json())
app.all(`*`, async (req, res) => {
try {
const ANT = await uniswap.getANT()
const BAT = await uniswap.getBAT()
const CVC = await uniswap.getCVC()
const DAI = await uniswap.getDAI()
const MKR = await uniswap.getMKR()
const FUN = await uniswap.getFUN()
const GNO = await uniswap.getGNO()
const KIN = await uniswap.getKIN()
const KNC = await uniswap.getKNC()
const LINK = await uniswap.getLINK()
const LOOM = await uniswap.getLOOM()
const MANA = await uniswap.getMANA()
const GUSD = await uniswap.getGUSD()
const NEXO = await uniswap.getNEXO()
const PAX = await uniswap.getPAX()
const obj = { ANT, BAT, CVC, DAI, FUN, GNO, GUSD, KIN, KNC, LINK, LOOM, MANA, MKR, NEXO, PAX }
for(let ticker of Object.keys(obj)) {
if(typeof(obj[ticker]) !== 'undefined') {
for(let transactions in obj[ticker]) {
if(typeof(obj[ticker][transactions].value) == 'undefined') {
continue
} else {
const alert = `${obj[ticker][transactions].value.toFixed(2)} $ETH traded for ${ticker}! Check it out at: https://etherscan.io/tx/${obj[ticker][transactions].hash}`
console.log(alert)
twitter.tweet(alert, (err, data, res) => {
if(err) {
console.log(err)
res.sendStatus(500)
} else {
console.log('Tweet sent!')
res.sendStatus(200)
}
})
}
}
} else {
console.log(ticker, ': No whales found.')
}
}
res.status(200).json({message: 'Success!'})
} catch({ message }) {
res.status(500).json({ message })
}
})
const listener = app.listen(process.env.PORT, () => {
console.log('Twitter bot is running on port ' + listener.address().port)
})