Skip to content

Python currency exchange rate package with a JSON database to reduce dependence on API availability

License

Notifications You must be signed in to change notification settings

PorkyC/local-forex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

local-forex

A free python package to help get started in building and interacting with a local database of currency exchange rates.

Dictionary based currency exchange rate package

  • Rates provided by Bank of Canada. Includes function for fetching and saving latest rates using BoC API
  • Offline JSON historical database reduces reliance on external API availability (records to 2017-01-03, TODO: extend historical records)
  • ~24 modern currencies supported

Installation

pip install local-forex
cd local-forex
pip install -r requirements.txt

Example conversion

import local_forex

fx = local_forex.ForexRates()

# Example conversion rate query for USD/EUR on December 02, 2020
from datetime import datetime
rate = fx.get_conversion_rate(base="USD", quote="EUR", date=datetime(2020,12,02))

Backfilling rates

  • backfill.py is included for convenience. Run Mon-Fri after 16:30EST to update database daily (e.g. Launchd on MacOS).
online_rates = fx.fetch_boc_rates()
fx.update_from_boc_rates(online_rates)
fx.save_rates_to_file()

About

Python currency exchange rate package with a JSON database to reduce dependence on API availability

Topics

Resources

License

Stars

Watchers

Forks

Languages