#bravotrader Possibile trovare criptovalute da XX% in anticipo? Vediamo!
⊳
Come promesso ecco i risultati della cripto sfida per trovare il miglior trader di criptovalute. Grazie a tutti, in particolare chi ha avuto il coraggio di partecipare.
Codice aggiornato
import fetch from 'node-fetch'
console.log('Crypto stats! by @luigi-tecnologo')
export async function getListOfSymbolWithPerc(list) {
let listPerc = []
for (const symbol in list) {
const data = await getSymbolWithPerc(symbol)
}
return listPerc
}
export async function getSymbol(symbol, ts) {
const initialTs = Math.round(ts / 1000)
const res = await fetch(`https://min-api.cryptocompare.com/data/pricehistorical?fsym=${symbol}&tsyms=BTC,USD,EUR&ts=${initialTs}&extraParams=your_app_name`)
const json = await res.json()
try {
console.log(`${ts} ${symbol} ${json[symbol].EUR}`)
} catch(e){
console.log('err ', symbol, e)
}
return {
symbol: symbol,
EUR: (json[symbol].EUR)
}
}
export async function getSymbolWithPerc(symbol, tsNew, tsOld) {
const resNew = await getSymbol(symbol, tsNew)
const resOld = await getSymbol(symbol, tsOld)
const vn = resNew.EUR
const vv = resOld.EUR
const perc = Math.round((vn - vv) / vv * 100)
console.log(`${symbol} `, perc)
return {
...resNew,
EURold: vv,
perc,
}
}
const main = async () => {
const response = await fetch('https://api.coinmarketcap.com/v1/ticker/')
const allCoins = await response.json()
let cryptos = allCoins.slice(0, 300).map(coin => coin.symbol)
// NOTE: symbol conversion for cryptocompare API
cryptos = cryptos
.map(x => x === 'MIOTA' ? 'IOT' : x)
.map(x => x === 'WAX' ? null : x)
.map(x => x === 'ACT' ? 'ACT*' : x)
.filter(x => x !== null)
const arr = []
for (const symbol of cryptos) {
const data = await getSymbolWithPerc(symbol, new Date('2018-01-10').valueOf(), new Date('2018-01-09').valueOf())
arr.push(data)
}
const sorted = arr.filter((e) => Number.isFinite(e.perc))
.sort((a, b) => {
return (a.perc > b.perc) ? -1 : 1
})
.slice(0,100)
console.log("The winner is: \n", sorted)
}
// no in test!!
main()
Installazione
Richiede NodeJS installato e l'esecuzione dei seguenti comandi
sudo npm install -g npx
npm install
npx babel-node cryptostats.js
yes good bro @luigi-tecnologo
Bella iniziativa... anche se era veramente difficile azzeccarle!
ottimo video