Skip to content

Instantly share code, notes, and snippets.

@amanelis
Last active June 24, 2016 16:27
Show Gist options
  • Save amanelis/844f53055cfbea2ec0f646c5742bd9ad to your computer and use it in GitHub Desktop.
Save amanelis/844f53055cfbea2ec0f646c5742bd9ad to your computer and use it in GitHub Desktop.
Stock prices with a bonus of Bitcoin at the end
require 'json'
require 'open-uri'
class Stocks
def self.get_by_symbols(symbols)
return symbols.inject([]) { |memo, sym|
result = JSON.parse(open("http://dev.markitondemand.com/MODApis/Api/v2/Quote/json?symbol=#{sym}").read)
memo << {symbol: result['Symbol'], lastPrice: result['LastPrice']}
}
end
end
class Bitcoin
def self.get_last_price
return JSON.parse(open('https://api.bitcoinaverage.com/all').read)['USD']['averages']['last']
end
end
puts Stocks.get_by_symbols(['msft', 'aapl', 'c'])
puts Bitcoin.get_last_price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment