Skip to content

Instantly share code, notes, and snippets.

@colindean
Created July 13, 2012 04:27
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save colindean/3102716 to your computer and use it in GitHub Desktop.
Quickly shows the most reasonable USD lowest asker and highest bidder from bitcoincharts.com
#!/usr/bin/env ruby
require "open-uri"
require "json"
#get the data
j = JSON.parse open("http://bitcoincharts.com/t/markets.json").read
#only USD, only active exchanges, and only where there's a bid and ask
j.select! {|x| x["currency"] == "USD" and x["volume"] > 0 and !x["ask"].nil? and !x["bid"].nil?}
#sort, need lowest ask and highest bidder
ask = j.sort {|x,y| x["ask"] <=> y["ask"]}
bid = j.sort {|x,y| x["bid"] <=> y["bid"]}
puts "highest bidder:"
puts bid.last
puts "lowest seller:"
puts ask.first
puts "spread opportunity:"
puts spread = bid.last["bid"] - ask.first["ask"]
puts p = spread / bid.last["bid"] * 100
puts "worth it! buy at #{ask.first["symbol"]}, sell at #{bid.last["symbol"]}" if p >= 6
puts "not worth it" if p < 6
2.times { puts "" }
gox = j.select {|x| x["symbol"] == "mtgoxUSD"}
cbx = j.select {|x| x["symbol"] == "cbxUSD"}
puts "cbx ask:"
puts a = cbx.first["ask"]
puts "gox bid:"
puts b = gox.first["bid"]
puts "diff:"
puts s = (b-a)/b*100
puts "buy at cbx and sell at gox?"
if s > 6
puts "yes"
else
puts "no"
end
2.times { puts "" }
puts "gox ask:"
puts a = gox.first["ask"]
puts "cbx bid:"
puts b = cbx.first["bid"]
puts "diff:"
puts s = (b-a)/b*100
puts "buy at gox and sell at cbx?"
if s > 6
puts "yes"
else
puts "no"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment