Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var request = require('request-promise')
var addresses = []
var thetotal = 0
var c = 0
var ethusd;
var batusd;
var zrxusd;
var repusd;
var prices = {}
var adds = {}
adds['ETH'] = '0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5'
adds['BAT'] = '0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E'
adds['ZRX'] = '0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407'
adds['REP'] = '0x158079ee67fce2f58472a96584a73c7ab9ac95c1'
adds['USDC'] = '0x39aa39c021dfbae8fac545936693ac917d5e7563'
adds['DAI'] = '0xf5dce57282a584d2746faf1593d3121fcac444dc'
prices['0x39aa39c021dfbae8fac545936693ac917d5e7563'] = 1
prices['0xf5dce57282a584d2746faf1593d3121fcac444dc'] = 1
setTimeout(async function() {
var eth = await request('https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=USD')
prices['0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5'] = JSON.parse(eth)[0].price_usd
var bat = await request('https://api.coinmarketcap.com/v1/ticker/basic-attention-token/?convert=USD')
prices['0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E'] = JSON.parse(bat)[0].price_usd
var zrx = await request('https://api.coinmarketcap.com/v1/ticker/0x/?convert=USD')
prices['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407'] = JSON.parse(zrx)[0].price_usd
var rep = await request('https://api.coinmarketcap.com/v1/ticker/augur/?convert=USD')
prices['0x158079ee67fce2f58472a96584a73c7ab9ac95c1'] = JSON.parse(rep)[0].price_usd
}, 1)
setInterval(async function() {
try {
var eth = await request('https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=USD')
prices['0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5'] = JSON.parse(eth)[0].price_usd
var bat = await request('https://api.coinmarketcap.com/v1/ticker/basic-attention-token/?convert=USD')
prices['0x6C8c6b02E7b2BE14d4fA6022Dfd6d75921D90E4E'] = JSON.parse(bat)[0].price_usd
var zrx = await request('https://api.coinmarketcap.com/v1/ticker/0x/?convert=USD')
prices['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407'] = JSON.parse(zrx)[0].price_usd
var rep = await request('https://api.coinmarketcap.com/v1/ticker/augur/?convert=USD')
prices['0x158079ee67fce2f58472a96584a73c7ab9ac95c1'] = JSON.parse(rep)[0].price_usd
} catch (err) {
console.log(err)
}
}, 60 * 1000 * 5)
async function doit() {
try {
var r = await request('https://api.compound.finance/api/v2/account')
var j = JSON.parse(r)
for (var a in j.accounts) {
if (j.accounts[a].health.value < 1 && !addresses.includes(j.accounts[a].address)) {
var bhighest = 0
var bwinner;
var swinner;
var shighest = 0
for (var t in j.accounts[a].tokens) {
var amt = j.accounts[a].tokens[t].borrow_balance_underlying.value * prices[j.accounts[a].tokens[t].address]
if (amt > bhighest) {
bhighest = amt
bwinner = j.accounts[a].tokens[t].address
}
}
for (var t in j.accounts[a].tokens) {
var amt = j.accounts[a].tokens[t].supply_balance_underlying.value * prices[j.accounts[a].tokens[t].address]
if (amt > shighest) {
shighest = amt
swinner = j.accounts[a].tokens[t].address
}
}
var ml = shighest;
if (bhighest * 1.05 * 0.5 > shighest) {
ml = ml * 0.95;
}
if (ml > bhighest * 0.5) {
ml = bhighest * 0.5;
}
addresses.push(j.accounts[a].address)
console.log('addresses')
console.log(addresses)
console.log('ml: ' + ml)
console.log('shighest: ' + shighest)
console.log('bhighest: ' + bhighest)
console.log('swinner: ' + swinner)
thetotal += ml * 0.05
c += 1
console.log('datetime: ' + new Date())
console.log('total: ' + thetotal)
console.log('count: ' + c)
console.log('average: ' + thetotal / c)
}
}
doit()
} catch (err) { //console.log(err)
setTimeout(function() {
doit()
}, 30000)
}
}
setTimeout(function() {
doit()
}, 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.