CryptoArbitrer
Provides currency conversions across several fiat currencies and crypto currencies.
Exchange rates are fetch (and in some cases scraped)
from mtgox.com, btc-e.com, eldolarblue.net, rate-exchange.appspot.com and dolarparalelo.org.
Given some particular situations in both Venezuela and Argentina, an unofficial but de-facto exchange rate
is used for each country's currency (from dolarparalelo.org and eldolarblue.net respectively).
The supported fiat currencies are:
usd ars uyu brl clp sgd eur vef
The supported crypto currencies are:
btc ltc nmc nvc trc ppc ftc cnc
If you're just looking to use these rates quickly, they are available as a JSON api at http://cryptocueva.com
Installation
Add this line to your application's Gemfile:
gem 'crypto_arbitrer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install crypto_arbitrer
Usage
To get the exchange rate from United States Dollars to Argentine Pesos:
irb > CryptoArbitrer::Base.fetch('usd', 'ars')
=> {'sell' => 7.9, 'buy' => 8.0}
Prices are returned as 'sell' and 'buy' hashes, where 'sell' is the price at which you can sell the given currency (highest bid price) and 'buy' is the price at which is being offered to you by others (lowest ask price).
If you were to buy 10 Bitcoin paying with US Dollars, this is how much you would spend in US Dollars.
irb > 10 * CryptoArbitrer::Base.fetch('btc', 'usd')['buy']
=> 1107.7001 # USD
Caching and Rails
There is basic support for plugging in your own caching mechanism. Caching in Rails is as easy as creating an initializer
with the following code:
CryptoArbitrer::Base.cache_backend = lambda do |from, to, block|
Rails.cache.fetch([from, to], &block)
end
Essentially, you just make a lambda that would receive the currencies to convert from and to, and a block that would return the
exchange rate when called.
Keeping an updated cache is also rather simple, I have this short rake task running every 10 minutes:
namespace :exchange_rates do
desc "Recaches the exchange rates"
task recache: :environment do
CryptoArbitrer::Base.supported_conversions.each do |from, to|
# Notice the third argument to 'fetch', it forces the lookup, ignoring the existing cache.
rate = CryptoArbitrer::Base.fetch(from, to, true) rescue next
Rails.cache.delete([from, to])
Rails.cache.write([from, to], rate)
end
end
end
Docs available at: http://rubydoc.info/github/nubis/crypto_arbitrer/master/frames
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request