31 Cryptocurrencies — Week 1

Brett McLain
Aug 27, 2017 · 2 min read

The 365 day experiment has begun. I pulled the trigger. Instead of 30 cryptocurrencies as originally planned, I ended up purchasing 31. Oops. Small snippet of the hundreds of transactions that occurred:

Unfortunately I wasn’t able to get exactly $10 USD of each currency. No exchange that I’m aware of allows the purchase of these alt-coins with USD (except for major ones like bitcoin, ethereum, and litecoin); you must purchase bitcoin and use that to purchase other currencies. The value of bitcoin changes so frequently and rapidly that it was impossible to get the exact amount I wanted, but I got close:

Since I don’t want to manually update all this information every week, and generate charts and graphs for these blog posts, I built some d3.js charts that utilize CryptoCompare API’s to pull down price data. Here’s the script for pulling the data:

Github Repository

global.fetch = require(‘node-fetch’);
const cc = require(‘cryptocompare’);
const fs = require(‘fs’);
let wallet = JSON.parse(fs.readFileSync(process.argv[2], ‘utf8’));
let currencyMap = JSON.parse(fs.readFileSync(‘./currency-map.json’, ‘utf8’));
let symbols = [];
let res = [];
let date = new Date().toISOString().substring(0, 10);
for (let symbol in wallet) {
symbols.push(symbol);
}
cc.priceMulti(symbols, [‘USD’])
.then(prices => {
for (let symbol in prices) {
wallet[symbol].position_usd = wallet[symbol].quantity * prices[symbol].USD;
let asset = {
date: date,
symbol: symbol,
name: currencyMap[symbol],
quantity: wallet[symbol].quantity,
price: prices[symbol].USD,
position: wallet[symbol].quantity * prices[symbol].USD
};
res.push(asset);
}
fs.writeFileSync(‘../data/’+date.replace(/-/g,’’)+’.json’, JSON.stringify(res));
})
.catch(console.error);

Usage:

node calculate.js wallet.json

Example input file (wallet.json):

{
“BTC”: {
“quantity”: 10,
}
}

Example output:

{
“date”:”2017–08–23",
“symbol”:”BTC”,
“name”:”Bitcoin”,
“quantity”:0.00248323,
“price”:4182.83,
“position”:10.386928940899999
}

The d3.js code loads the JSON generated by this script and displays the relevant charts. I’m working on creating better charts for future updates, but that might be a ways off. I have a cron job that runs this script every night to capture the value of my portfolio every day. Each week I will post an update, including some fancier charts! You can see the d3 code in the html folder of the github repo.

Callback Hell

Magpie Programmer. Shiny? Shiny!

)

Brett McLain

Written by

http://blog.mclain.ca

Callback Hell

Magpie Programmer. Shiny? Shiny!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade