Project

oanda_bank

0.0
No commit activity in last 3 years
No release in over 3 years
["Ruby Money::Bank interface for OANDA currency rate data"]
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0
~> 0.7
~> 2.9
~> 1.18

Runtime

<= 6.5.1, ~> 6.0
~> 1.0
 Project Readme

oanda_bank

Ruby Money::Bank interface for OANDA currency rate data

This gem extends Money::Bank::VariableExchange with Money::Bank::OANDA to give you access to OANDA fxTrade exchange rates.

What rates are available?

Any pair of currencies that are both part of the money gem and part of a tradeable instrument in your fxTrade account. In addition, if there is no tradeable instrument containing both of your currencies the gem will attempt to go through USD. For example, CAD -> SEK is supported because although there is no CAD/SEK instrument, there exist both USD/CAD and USD/SEK instruments.

Usage

require 'oanda_bank'

oanda_bank = Money::Bank::OANDA.new(ENV['FXTRADE_ACCOUNT_ID'], ENV['FXTRADE_ACCESS_TOKEN'])

# Call this before calculating exchange rates
# This will download the rates from OANDA
oanda_bank.update_rates!

# Exchange 100 USD to CAD
# API is the same as the money gem
oanda_bank.exchange_with(Money.new(10000, :USD), :CAD)

# Set as default bank to do arithmetic and comparisons on Money objects
Money.default_bank = oanda_bank
money1 = Money.new(10)
money1.bank # oanda_bank

Money.us_dollar(10000).exchange_to(:CAD)
'1'.to_money(:USD) > '1'.to_money(:CAD) # true

# Refresh rates after some number of seconds (by default, rates are only updated when you call update_rates!)
oanda_bank.ttl_in_seconds = 3600 # Cache rates for one hour

Testing

If you'd like to contribute code or modify this gem, you can run the test suite with:

gem install oanda_bank --dev
bundle exec rspec

Contributing

  1. Fork this repo and make changes in your own copy
  2. Add a test if applicable and run the existing tests with rspec to make sure they pass
  3. Commit your changes and push to your fork git push origin master
  4. Create a new pull request and submit it back to me