-
-
Save eliyastein/111c95b2f9fc42bd2099b195417d8569 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)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment