untitled notebook

node v10.24.1
version: 1.0.0
endpointsharetweet
var fetch = require('node-fetch'); let tmpPrices; let galaPrices; let ethPrices; let batPrices; coingeckogalaURL = 'https://api.coingecko.com/api/v3/coins/ethereum/contract/0x15d4c048f83bd7e37d49ea4c83a07267ec4203da/market_chart/range?vs_currency=usd&from=1601078400&to=' + Date.now(); coingeckoethURL = 'https://api.coingecko.com/api/v3/coins/ethereum/market_chart/range?vs_currency=usd&from=1601078400&to=' + Date.now(); coingeckobatURL = 'https://api.coingecko.com/api/v3/coins/ethereum/contract/0x0d8775f648430679a709e98d2b0cb6250d2887ef/market_chart/range?vs_currency=usd&from=1601078400&to=' + Date.now(); async function getPrices(cgurl) { try { var req = await fetch(cgurl); var response = await req.json(); tmpPrices = await response.prices; } catch (e) { console.error(e) } } getPrices(coingeckogalaURL).then(() => { galaPrices = tmpPrices; }) getPrices(coingeckoethURL).then(() => { ethPrices = tmpPrices; }) getPrices(coingeckobatURL).then(() => { batPrices = tmpPrices; }) fetch('https://api.etherscan.io/api?module=account&action=tokentx&address=0x880a0b37dd55608983b54448d9f42a1d47ad33a4&startblock=0&endblock=999999999&sort=asc&apikey=YourApiKeyToken') .then(response => response.json()) .then(data => { var fourhundredk = 0; var sixhundredk = 0; var onethreethreem = 0; var twothousandusd = 0; var batsales = 0; var received = data.result.filter(function (tx) { return tx.to === '0x880a0b37dd55608983b54448d9f42a1d47ad33a4'; }); var recGala = received.filter(function (tx) { return tx.tokenName === 'Gala'; }); var recBAT = received.filter(function (tx) { return tx.tokenName === 'BAT'; }); for(let tokentransfer of recGala) { formattedValue = (tokentransfer.value/Math.pow(10, tokentransfer.tokenDecimal)).toFixed(tokentransfer.tokenDecimal); timestamp = parseInt(tokentransfer.timeStamp); if (timestamp > 1599955200 && timestamp < 1600171200) { if (formattedValue > 399999) { fourhundredk = fourhundredk + Math.floor(formattedValue/400000) } } if (timestamp > 1600171200 && timestamp < 1600551000) { if (formattedValue > 599999) { sixhundredk = sixhundredk + Math.floor(formattedValue/600000) } } if (timestamp > 1600551000 && timestamp < 1601127000) { if (formattedValue > 1329999) { onethreethreem = onethreethreem + Math.floor(formattedValue/1330000) } } if (timestamp > 1601127000) { var tmptimestamp = new Date(timestamp*1000) var tmpmidnight = Date.UTC(tmptimestamp.getUTCFullYear(), tmptimestamp.getUTCMonth(), tmptimestamp.getUTCDate(),'00','00','00') var tmpprice; for(var i = 0; i < galaPrices.length; i++) { price = galaPrices[i] if (price[0] == tmpmidnight) { tmpprice = price; } } if (Math.floor(formattedValue/(2000/tmpprice[1])) > 30) { console.log('found: ' + formattedValue); console.log(tokentransfer); console.log(Math.floor(formattedValue/(2000/tmpprice[1]))); } if (tmpprice) { twothousandusd = twothousandusd + Math.floor(formattedValue/(2000/tmpprice[1])); tmpprice = 0; } } } for(let tokentransfer of recBAT) { formattedValue = (tokentransfer.value/Math.pow(10, tokentransfer.tokenDecimal)).toFixed(tokentransfer.tokenDecimal); timestamp = parseInt(tokentransfer.timeStamp); var tmptimestamp = new Date(timestamp*1000) var tmpmidnight = Date.UTC(tmptimestamp.getUTCFullYear(), tmptimestamp.getUTCMonth(), tmptimestamp.getUTCDate(),'00','00','00') var tmpprice; for(var i = 0; i < batPrices.length; i++) { price = batPrices[i] if (price[0] == tmpmidnight) { tmpprice = price; } } if (tmpprice) { batsales = batsales + Math.floor(formattedValue/(2000/tmpprice[1])); tmpprice = 0; } } console.log('400k: ' + fourhundredk); console.log('600k: ' + sixhundredk); console.log('1.33m: ' + onethreethreem); console.log('2kUSD: ' + twothousandusd); console.log('BAT: ' + batsales); }).catch(error => console.error(error)) fetch('https://api.etherscan.io/api?module=account&action=txlist&address=0x880a0b37dd55608983b54448d9f42a1d47ad33a4&startblock=0&endblock=99999999&sort=asc&apikey=SJEX4JJA5UCDIAXS2B1DV1KTF72QB47P5U') .then(response => response.json()) .then(data => { var ethsales = 0; var received = data.result.filter(function (tx) { return tx.to === '0x880a0b37dd55608983b54448d9f42a1d47ad33a4'; }); for(let ethtransfer of received) { formattedValue = (ethtransfer.value/Math.pow(10, 18)).toFixed(18); timestamp = parseInt(ethtransfer.timeStamp); var tmptimestamp = new Date(timestamp*1000) var tmpmidnight = Date.UTC(tmptimestamp.getUTCFullYear(), tmptimestamp.getUTCMonth(), tmptimestamp.getUTCDate(),'00','00','00') var tmpprice; for(var i = 0; i < ethPrices.length; i++) { price = ethPrices[i] if (price[0] == tmpmidnight) { tmpprice = price; } } if (tmpprice) { ethsales = ethsales + Math.floor(formattedValue/(2000/tmpprice[1])); tmpprice = 0; } } console.log('ETH: ' + ethsales); }).catch(error => console.error(error))
Loading…

no comments

    sign in to comment