Created
January 28, 2014 20:46
-
-
Save nickjacob/8676037 to your computer and use it in GitHub Desktop.
check and update buy/sell price on coinbase
This file contains 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 | |
# get coinbase price | |
### | |
require 'coinbase' | |
require 'optparse' | |
# your API key - https://coinbase.com/docs/api/authentication | |
COINBASE_API = '' | |
UP_ARROW = "\u25B2".encode('utf-8') | |
DOWN_ARROW = "\u25BC".encode('utf-8') | |
if __FILE__ == $0 | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage #{$0}: [amount] [interval] [-b|--bare - price only]" | |
opts.on "-b", "--bare", "bare (price only) output" do |v| | |
options[:bare] = v | |
end | |
end.parse! | |
coinbase = Coinbase::Client.new(COINBASE_API) | |
amount = (ARGV[0] || 1).to_f | |
rate = (ARGV[1] || 5).to_i | |
buy_price = coinbase.buy_price(amount).to_f | |
sell_price = coinbase.sell_price(amount).to_f | |
if options[:bare] | |
puts "#{ buy_price }\t#{sell_price}" | |
else | |
puts "[ MONITORING #{ amount } btc @#{ rate }s ]" | |
last_buy = buy_price | |
last_sell = sell_price | |
while true do | |
buy_price = coinbase.buy_price(amount).to_f | |
sell_price = coinbase.sell_price(amount).to_f | |
sell_change = "" | |
buy_change = "" | |
if last_buy < buy_price | |
buy_change = UP_ARROW | |
elsif last_buy > buy_price | |
buy_change = DOWN_ARROW | |
end | |
if last_sell < sell_price | |
sell_change = UP_ARROW | |
elsif last_sell > sell_price | |
sell_change = DOWN_ARROW | |
end | |
system('clear') | |
puts "-------- COINBASE PRICE --------" | |
puts " amount: #{ amount }btc" | |
puts " buy price : $#{ buy_price} #{ buy_change }" | |
puts " sell price : $#{ sell_price} #{ sell_change }" | |
puts "--------------------------------" | |
last_buy = buy_price | |
last_sell = sell_price | |
sleep(rate) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment