Created
May 23, 2017 21:10
-
-
Save bplunkert/c77b65f624770fcdc1e9968f4f9a9107 to your computer and use it in GitHub Desktop.
Cryptocurrency portfolio checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
balances = { | |
'BTC' => 0, | |
'DASH' => 0, | |
'ETH' => 0, | |
'LTC' => 0, | |
'NMC' => 0, | |
'XMR' => 0 | |
} | |
require 'httparty' | |
require 'json' | |
usd_prices = { | |
'BTC' => JSON.parse(HTTParty.get('https://apiv2.bitcoinaverage.com/exchanges/gdax').to_s)['symbols']['BTCUSD']['last'], | |
'DASH' => JSON.parse(HTTParty.get('https://api.cryptowat.ch/markets/kraken/dashusd/price').to_s)['result']['price'], | |
'ETH' => JSON.parse(HTTParty.get('https://apiv2.bitcoinaverage.com/exchanges/gdax').to_s)['symbols']['ETHUSD']['last'], | |
'LTC' => JSON.parse(HTTParty.get('https://api.cryptowat.ch/markets/kraken/ltcusd/price').to_s)['result']['price'], | |
'NMC' => JSON.parse(HTTParty.get('https://api.cryptowat.ch/markets/btce/nmcusd/price').to_s)['result']['price'], | |
'XMR' => JSON.parse(HTTParty.get('https://api.cryptowat.ch/markets/kraken/xmrusd/price').to_s)['result']['price'] | |
} | |
usd_balances = balances.collect{|coin, coin_balance| [coin, (coin_balance * usd_prices[coin])]}.to_h | |
total_balance = usd_balances.values.reduce(0, :+) | |
usd_balances.each do |coin, balance| | |
puts "#{coin}: $#{sprintf("%.2f", balance)} / #{sprintf("%.2f", 100*balance/total_balance)}%" if balance != 0 | |
end | |
puts "Total Portfolio Balance: #{sprintf("%.2f", total_balance)}" |
@yrral86 I made a repo for this, so feel free to fork it: https://github.com/bplunkert/portfolio_checker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to report a bug... this script gives prices in USD, not BTC.