Project

forex

0.0
No commit activity in last 3 years
No release in over 3 years
Forex Rates for traders using a simple DSL for parsing
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0
>= 0

Runtime

 Project Readme

Forex

Code Climate Build Status Dependency Status Gem Version

Provides a simple DSL for managing Foreign Exchange rates (forex) for various traders (Inspired by CurrrencyJA).

Installation

Add this line to your application's Gemfile:

gem 'forex'

And then execute:

$ bundle

Or install it yourself as:

$ gem install forex

Usage

To add a new trader, create a new file at lib/forex/traders/<country-code>/<trader-name>.rb with the following contents:

Forex::Trader.define "NCB" do |t|
  t.base_currency  = "JMD"
  t.name           = "National Commercial Bank"
  t.endpoint       = "http://www.jncb.com/rates/foreignexchangerates"
  t.twitter_handle = "@ncbja"

  t.rates_parser = ->(doc) do # doc is a nokogiri document
    # process the doc and return rates hash in the following format

    # {
    #   "USD" => {
    #     :buy_cash => 102.0,
    #     :buy_draft => 103.3,
    #     :sell_cash => 105.0
    #   },
    #   # ...
    # }
  end
end

# Rates may be fetched for a specific trader
Forex::Trader.all['BNS'].fetch

TabularRates

TabularRates allows you to simplify the process of parsing a table of rates. Simply find the table and pass it along with options of what values are in which columns (zero indexed).

For example:

  #...

  t.rates_parser = ->(doc) do # doc is a nokogiri document

    options = {
      currency_code: 1,
      sell_cash: 2,
      buy_cash: 4,
      buy_draft: 3,
    }

    table = doc.css(".rates table").first
    
    translations = {
      'US$' => 'USD',
      'TT$' => 'TTD',
    }

    # translations are optional
    Forex::TabularRates.new(table, options).parse_rates(translations)
  end

  #...

TODO

  • Make it possible to have the same trader in multiple countries
  • Add other traders in Jamaica

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