Last active
March 3, 2017 09:30
-
-
Save tallakt/7b1919e16735df1e3f293cf3c0efb775 to your computer and use it in GitHub Desktop.
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 | |
require 'net/http' | |
require 'json' | |
def get_json(url) | |
uri = URI(url) | |
JSON.parse(Net::HTTP.get uri) | |
end | |
def get_asset_eur(asset) | |
uri = URI("https://api.cryptonator.com/api/ticker/#{asset}-EUR") | |
get_json(uri)["ticker"]["price"].to_f | |
end | |
def get_eur_to_fiat(fiat) | |
case fiat | |
when "EUR" | |
1.0 | |
else | |
fixer = get_json "http://api.fixer.io/latest?symbols=#{fiat}" | |
fixer["rates"][fiat].to_f | |
end | |
end | |
# | |
# main script | |
# | |
from_asset = ARGV.shift.upcase | |
to_fiat = ARGV.shift.upcase | |
amount = ARGV.shift.to_f | |
converted = amount * get_asset_eur(from_asset) * get_eur_to_fiat(to_fiat) | |
puts "#{amount} #{from_asset} is #{converted} #{to_fiat}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment