Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Last active December 22, 2015 06:19
Show Gist options
  • Select an option

  • Save dmerrick/6430655 to your computer and use it in GitHub Desktop.

Select an option

Save dmerrick/6430655 to your computer and use it in GitHub Desktop.
bitcoin_earnings
#!/usr/bin/env ruby
require 'open-uri'
require 'json' # ruby 1.9+
if $DEBUG
# development gems
require 'rubygems'
require 'awesome_print'
require 'pry'
end
# take a command line argument if provided
address = ARGV.first || "1JT86GVai2r7sixvsJfJxNWHon9Dep2erh"
# cost of the mining rig
cost_of_miner = 0.4416 # BTC
# save the current time
time = DateTime.now.strftime(" %H:%M %-m/%-d/%Y ")
time = "-" * 10 + time + "-" * 10
# find current BTC->USD exchange rate (weighted average)
current_value_url = 'http://api.bitcoinaverage.com/no-mtgox/ticker/USD'
usd_json = JSON.parse(URI.parse(current_value_url).read)
current_value = usd_json["last"].to_f
# find total BTC mined
bitcoin_stats_url = "http://eligius.st/~luke-jr/raw/7/balances.json"
btc_json = JSON.parse(URI.parse(bitcoin_stats_url).read)
total_mined = btc_json[address]["balance"].to_i * 0.00000001
total_mined = total_mined.round(10)
# ROI stats
break_even = cost_of_miner - total_mined
break_even_progress = ((total_mined / cost_of_miner) * 100.0).round(2)
# approximate USD earned, rounded to 2 decimal places
total_earned = (current_value * total_mined).round(2).to_s
total_earned += "0" if total_earned.to_s.split('.').last.size != 2
puts time
puts "Approximate BTC mined: #{total_mined}"
puts "USD rate (current avg.): $#{current_value}"
puts "-" * time.size
puts "Progress to positive ROI: #{break_even_progress}%"
puts "BTC left to positive ROI: #{break_even}"
puts "-" * time.size
puts "Approximate USD earned: $#{total_earned}"
puts "-" * time.size
@dmerrick
Copy link
Copy Markdown
Author

dmerrick commented Sep 3, 2013

Example output:

---------- 16:46 9/3/2013 ----------
Approximate BTC mined: 0.01617622
USD rate (current avg.): $136.77
------------------------------------
Progress to positive ROI: 3.66%
BTC left to positive ROI: 0.42542378
------------------------------------
Approximate USD earned: $2.21
------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment