Created
February 7, 2018 16:34
-
-
Save abachman/a127b6b8e3975c7028914e558d487e67 to your computer and use it in GitHub Desktop.
cryptocurrency inflation reporter
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
# My attempt to understand inflation in the mineable cryptocurrency markets. | |
# | |
# Every day mineable coins (e.g., Bitcoin, Ethereum, Litecoin, and | |
# Bitcoin Cash) add coins to their total market cap. Coins are produced by | |
# mining, miners have real fiat bills, therefore miners have to convert coins | |
# to fiat in order to continue mining. | |
# | |
# Selling new coins into the existing market means an equivalent amount of fiat | |
# needs to be added in order to keep the price flat. NOTE: selling new coins | |
# for fiat also requires real-currency markets to be available for exchange, | |
# but that's a separate problem. | |
# | |
# For the top 4 coins, what's the rough estimate daily inflation? | |
# | |
# Block data retrieved from https://bitinfocharts.com Feb 2018 | |
# | |
# Example run: | |
# | |
# $ RELOAD=1 ruby coin-calc.rb | |
# | |
# LOADING CURRENCY PAIRS FROM GDAX | |
# | |
# Coin Last Price | |
# ------------------------ | |
# BTC 8124.20 | |
# ETH 811.51 | |
# LTC 148.66 | |
# BCH 994.49 | |
# | |
# ======================================== | |
# | |
# DAILY NEW COIN VALUE | |
# | |
# Coin $ value | |
# ------------------------ | |
# BTC $14,197,631 | |
# ETH $15,023,484 | |
# LTC $2,140,704 | |
# BCH $1,864,668 | |
# ------------------------ | |
# Total $33,226,488 | |
# | |
require 'net/https' | |
require 'json' | |
DAY = 24 * 60 * 60 | |
# in coins in seconds in USD | |
coins = { | |
btc: { reward: 12.5, block_time: 10.3* 60, price: 8221 }, | |
eth: { reward: 3.0, block_time: 14, price: 825 }, | |
ltc: { reward: 25.0, block_time: 2.5 * 60, price: 150 }, | |
bch: { reward: 12.5, block_time: 9.6 * 60, price: 1002 }, | |
} | |
if ENV['RELOAD'] == '1' | |
puts | |
puts "LOADING CURRENCY PAIRS FROM GDAX" | |
puts | |
puts "%-8s%16s" % ['Coin', 'Last Price'] | |
puts "-" * 24 | |
%w(BTC-USD ETH-USD LTC-USD BCH-USD).each do |pid| | |
uri = URI("https://api.gdax.com/products/#{ pid }/stats") | |
body = Net::HTTP.get(uri) # => String | |
if body | |
resp = JSON.parse(body) | |
coin = pid.split('-')[0].downcase.to_sym | |
coins[coin][:price] = Float(resp['last']) | |
puts "%-8s%16s" % [coin.upcase, resp['last'].gsub(/(\d+\.\d{2}).+/, '\1')] | |
else | |
puts "ERROR!" | |
end | |
sleep 1 | |
end | |
puts | |
puts "=" * 40 | |
puts | |
end | |
def daily_value(coin) | |
blocks_per_day = DAY / coin[:block_time] | |
block_value = coin[:reward] * coin[:price] | |
block_value * blocks_per_day | |
end | |
def format(number) | |
left, right = number.round(2).to_s.split(".".freeze) | |
left.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/) do |digit_to_delimit| | |
"#{digit_to_delimit}," | |
end | |
'$' + left | |
end | |
puts "DAILY NEW COIN VALUE" | |
puts | |
puts "%-8s%16s" % ['Coin', '$ value'] | |
puts "-" * 24 | |
total = 0 | |
%w(btc eth ltc bch).each do |name| | |
label = name.upcase | |
coin = coins[name.to_sym] | |
dv = daily_value(coin) | |
puts "%-8s%16s" % [label, format(dv)] | |
total += dv | |
end | |
puts "-" * 24 | |
puts "%-8s%16s" % ['Total', format(total)] | |
puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment