All Projects → alexprengere → currencyconverter

alexprengere / currencyconverter

Licence: Apache-2.0 license
A Python currency converter using the European Central Bank data.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to currencyconverter

php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (-89.24%)
Mutual labels:  currency, exchange-rates
javascript-forex-quotes
JavaScript Library for fetching realtime forex quotes.
Stars: ✭ 38 (-75.95%)
Mutual labels:  currency
Coinc
💰💱Alfred Workflow for currencies conversion
Stars: ✭ 38 (-75.95%)
Mutual labels:  currency
addons-konos
Konos Chilean Addons
Stars: ✭ 16 (-89.87%)
Mutual labels:  currency
currency
A currency computations package.
Stars: ✭ 52 (-67.09%)
Mutual labels:  currency
crypto-monitor
Monitor the crypto currency rate
Stars: ✭ 71 (-55.06%)
Mutual labels:  currency
dukascopy-tools
✨ Download historical price tick data for Crypto, Stocks, ETFs, CFDs, Forex via CLI and Node.js ✨
Stars: ✭ 128 (-18.99%)
Mutual labels:  exchange-rates
persian
Some utilities for Persian language in Go (Golang)
Stars: ✭ 65 (-58.86%)
Mutual labels:  currency
Rates
A currency rate converter App.
Stars: ✭ 13 (-91.77%)
Mutual labels:  currency
currency-format
The «Price Format» extension for Magento 2
Stars: ✭ 18 (-88.61%)
Mutual labels:  currency
pesa
A JS money lib whose precision goes up to 11 (and beyond).
Stars: ✭ 38 (-75.95%)
Mutual labels:  currency
frontend
Cambiatus Web based frontend using Elm
Stars: ✭ 25 (-84.18%)
Mutual labels:  currency
stockholm
💵 Modern Python library for working with money and monetary amounts. Human friendly and flexible approach for development. 100% test coverage + built-in support for GraphQL and Protocol Buffers transports using current best-practices.
Stars: ✭ 26 (-83.54%)
Mutual labels:  currency
Credits
Credits(CRDS) - An Evolving Currency For An Evolving Society
Stars: ✭ 14 (-91.14%)
Mutual labels:  currency
django-prices-openexchangerates
openexchangerates.org support for django-prices
Stars: ✭ 33 (-79.11%)
Mutual labels:  currency
Flutter-Basic
โค้ดประกอบเนื้อหา Flutter เบื้องต้น
Stars: ✭ 39 (-75.32%)
Mutual labels:  exchange-rates
nis-python-client
Python client for NEM NIS API (https://nemproject.github.io). XEM\NEM\Crypto
Stars: ✭ 16 (-89.87%)
Mutual labels:  currency
rescript-intl
ReScript wrapper on top of JavaScript's Intl
Stars: ✭ 18 (-88.61%)
Mutual labels:  currency
money-parser
Price and currency parsing utility
Stars: ✭ 26 (-83.54%)
Mutual labels:  currency
Guide-to-Swift-Numbers-Sample-Code
Xcode Playground Sample Code for the Flight School Guide to Swift Numbers
Stars: ✭ 92 (-41.77%)
Mutual labels:  currency

https://raw.githubusercontent.com/alexprengere/currencyconverter/master/logo/cc3.png

actions cratev crated

This is a currency converter that uses historical rates against a reference currency (Euro). It is compatible with Python3.6+.

Currency data sources

The default source is the European Central Bank. This is the ECB historical rates for 42 currencies against the Euro since 1999. It can be downloaded here: eurofxref-hist.zip. The converter can use different sources as long as the format is the same.

Note that the currency converter does not query the API in real time, to avoid the overhead of the HTTP request. It uses embedded data in the library, which might not be up to date. If you need the latest data, please refer to the data section.

Installation

You can install directly after cloning:

$ python setup.py install --user

Or use the Python package:

$ pip install --user currencyconverter

Command line tool

After installation, you should have currency_converter in your $PATH:

$ currency_converter 100 USD --to EUR
100.000 USD = 87.512 EUR on 2016-05-06

Python API

Create once the currency converter object:

>>> from currency_converter import CurrencyConverter
>>> c = CurrencyConverter()

Convert from EUR to USD using the last available rate:

>>> c.convert(100, 'EUR', 'USD') # doctest: +SKIP
137.5...

Default target currency is EUR:

>>> c.convert(100, 'EUR')
100.0
>>> c.convert(100, 'USD') # doctest: +SKIP
72.67...

You can change the date of the rate:

>>> from datetime import date # datetime works too
>>> c.convert(100, 'EUR', 'USD', date=date(2013, 3, 21))
129...

Data

You can use your own currency file, as long as it has the same format (ECB):

from currency_converter import ECB_URL, SINGLE_DAY_ECB_URL

# Load the packaged data (might not be up to date)
c = CurrencyConverter()

# Download the full history, this will be up to date. Current value is:
# https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip
c = CurrencyConverter(ECB_URL)

# Dowload only the latest available day. Current value is:
# https://www.ecb.europa.eu/stats/eurofxref/eurofxref.zip
c = CurrencyConverter(SINGLE_DAY_ECB_URL)

# Load your custom file
c = CurrencyConverter('./path/to/currency/file.csv')

Since the raw data is updated only once a day, it might be better to only download it once a day:

import os.path as op
import urllib.request
from datetime import date

from currency_converter import ECB_URL, CurrencyConverter

filename = f"ecb_{date.today():%Y%m%d}.zip"
if not op.isfile(filename):
    urllib.request.urlretrieve(ECB_URL, filename)
c = CurrencyConverter(filename)

Fallbacks

Some rates are missing:

>>> c.convert(100, 'BGN', date=date(2010, 11, 21))
Traceback (most recent call last):
RateNotFoundError: BGN has no rate for 2010-11-21

But we have a fallback mode for those, using a linear interpolation of the closest known rates, as long as you ask for a date within the currency date bounds:

>>> c = CurrencyConverter(fallback_on_missing_rate=True)
>>> c.convert(100, 'BGN', date=date(2010, 11, 21))
51.12...

The fallback method can be configured with the fallback_on_missing_rate_method parameter, which currently supports "linear_interpolation" and "last_known" values.

We also have a fallback mode for dates outside the currency bounds:

>>> c = CurrencyConverter()
>>> c.convert(100, 'EUR', 'USD', date=date(1986, 2, 2))
Traceback (most recent call last):
RateNotFoundError: 1986-02-02 not in USD bounds 1999-01-04/2016-04-29
>>>
>>> c = CurrencyConverter(fallback_on_wrong_date=True)
>>> c.convert(100, 'EUR', 'USD', date=date(1986, 2, 2)) # fallback to 1999-01-04
117.89...

Decimal

If you need exact conversions, you can use the decimal option to use decimal.Decimal internally when parsing rates. This will slow down the load time by a factor 10 though.

>>> c = CurrencyConverter(decimal=True)
>>> c.convert(100, 'EUR', 'USD', date=date(2013, 3, 21))
Decimal('129.100')

Other attributes

  • bounds lets you know the first and last available date for each currency
>>> first_date, last_date = c.bounds['USD']
>>> first_date
datetime.date(1999, 1, 4)
>>> last_date # doctest: +SKIP
datetime.date(2016, 11, 14)
  • currencies is a set containing all available currencies
>>> c.currencies # doctest: +SKIP
set(['SGD', 'CAD', 'SEK', 'GBP', ...
>>> 'AAA' in c.currencies
False
>>> c.convert(100, 'AAA')
Traceback (most recent call last):
ValueError: AAA is not a supported currency
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].