Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crypto_arbitrer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto_arbitrer

  • 0.0.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Travis Build Status

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 19 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc