Created
March 4, 2013 06:00
-
-
Save colindean/5080263 to your computer and use it in GitHub Desktop.
Get BTC price history from BitcoinCharts and output in ledger prices_db format
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 | |
# Set these to what you'd like | |
symbol = "mtgoxUSD" | |
ledger_currency = "$" | |
ledger_btc = "BTC" | |
start_date = "2013-01-01" | |
end_date = Time.now.to_i | |
# shouldn't really need to change anything after here | |
require 'open-uri' | |
require 'csv' | |
url = "http://bitcoincharts.com/t/trades.csv?symbol=%s&start=%d&end=%d" % [symbol, Date.parse(start_date).to_time.to_i, end_date] | |
puts "D %s1,000.00\nN %s" % [ledger_currency, ledger_currency] | |
CSV.foreach open(url) do |line| | |
time = line[0].to_i | |
price = line[1].to_f | |
amount = line[2].to_f | |
puts "P %s %s %s%f" % [ | |
Time.at(time).strftime("%Y-%m-%d %H:%M:%S"), | |
ledger_btc, | |
ledger_currency, | |
price | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment