Skip to main content

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:

Installation

  1. Install django-historical-currencies in your Python environment.
  2. Add historical_currencies to INSTALLED_APPS in your settings.py.
  3. Import yesterday's exchange rates to get started: manage.py import_ecb_exchangerates --daily.
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-historical-currencies-0.0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-historical-currencies-0.0.1.tar.gz.

File metadata

File hashes

Hashes for django-historical-currencies-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3f671fdf7d1a476a5b0f6bce0e730d648b8cd2f07a76299ce1ef6a1abd686bbc
MD5 600dfe67b488fd3364e11670b487babb
BLAKE2b-256 3810e8cfb4824ab85defaa1576e232a12afbf26dcb6df865f3f3ad2c443970aa

See more details on using hashes here.

File details

Details for the file django_historical_currencies-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_historical_currencies-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 605a7ad52bc493b142a0024d9fd05e70d788d16c6cc32921eba03e277d28b255
MD5 b509a3d9f3312bdd8fc381f0e244c903
BLAKE2b-256 59d83f68f5451f5e668c41ef83b7758794aa5b1caecbb0c6eacea76e0c7d91d3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page