Django currencies with historical exchange rates
Project description
Django currencies with historical exchange rates
This is a fairly minimal Django app that renders amounts of currencies, stores historical exchange rates in the database, and performs currency conversion.
When working with any historical multi-currency data, one often needs to be able to perform exchange rate calculations with historical rates. This allows the conversion to be accurately reproduced in the future.
Exchange Rates are stored in a simple database table, with 1 row per rate per date. Conversions can be done directly, or across a base currency using 2 rates.
Formatting is defined by iso4217
.
Exchange Rate data can be sourced from:
- The European ECB Reference Rates
- openexchangerates.org (requires free registration)
Installation
- Install
django-historical-currencies
in your Python environment. - Add
historical_currencies
toINSTALLED_APPS
in yoursettings.py
. - Import yesterday's exchange rates to get started:
manage.py import_ecb_exchangerates --daily
. - Configure a periodic task (e.g. cron, systemd timer, celery beat) to import daily exchange rates.
Settings
MAX_EXCHANGE_RATE_AGE
: How many days old can an exchange rate be treated as current?
Optional settings, only required for OpenExchangeRates.org import:
OPEN_EXCHANGE_RATES_APP_ID
: OpenExchangeRates App ID.OPEN_EXCHANGE_RATES_BASE_CURRENCY
: Base currency.
Usage
In code, amounts can be converted using the
historical_currencies.exchange.exchange()
method.
In templates, this module represents financial amounts as tuple of
(Decimal, str(currency-code))
. The recommended approach is to add
properties to your Django models to return this tuple for amounts.
In a template the amount can be displayed or converted:
{% load currency_format %}
Assuming my_amount = (Decimal(10), 'USD')
Display:
{{ my_amount|currency }}
-> 10.00 USD
Exchange at the latest rate:
{{ my_amount|exchange:"EUR" }}
-> 9.06 EUR
License
This Django app is available under the terms of the ISC license, see
LICENSE
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-historical-currencies-0.0.1.post1.tar.gz
.
File metadata
- Download URL: django-historical-currencies-0.0.1.post1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c13b5f96945f75a5ff0a9d15fffad3d846b3c9c56e6774a4706bfebf1e1e0ea |
|
MD5 | 81c92e77ccdee4851817deadd37e5194 |
|
BLAKE2b-256 | 922fb567a7c6df74f87f371b802d14231238647ef8fc03ce07aeb2950e53700e |
File details
Details for the file django_historical_currencies-0.0.1.post1-py3-none-any.whl
.
File metadata
- Download URL: django_historical_currencies-0.0.1.post1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 464197e72a6f7dd56ade4acc375fa7468f4dd3cf32a4e78f51ffd3421369c662 |
|
MD5 | ed7ceb41c2c7c2962285a07efd43b069 |
|
BLAKE2b-256 | e7e1e9875693623b3a64c4ab400d55d5e4ce69b97ad02e9045804df1ec52a7fd |