Skip to content

Latest commit

 

History

History
123 lines (93 loc) · 2.74 KB

README.md

File metadata and controls

123 lines (93 loc) · 2.74 KB

CBAR Rates

PyPI - Version PyPI - Python Version PyPI - Downloads License

A Python library to work with Azerbaijani manat (AZN) official exchange rates based on CBAR (The Central Bank of the Republic of Azerbaijan).

Features

  • Retrieve official CBAR exchange rates for the Azerbaijani manat (AZN).
  • Compare exchange rates between two dates and calculate differences.
  • Filter results by specific currency codes (e.g., USD, EUR).

Requirements

  • Python 3.7 or higher
  • requests library

Installation

Install the library using pip:

pip install cbar-rates --upgrade

For isolated installations, use a virtual environment:

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install cbar-rates

Examples

Usage of get_rates()

from datetime import date
import cbar

rates_date = date.today()
currencies = ["USD", "EUR"]

rates = cbar.get_rates(rates_date, currencies)

print(rates)
# Output:
{
    "date": "18.11.2024",
    "currencies": {
        "USD": {
            "nominal": "1",
            "rate": 1.7
        },
        "EUR": {
            "nominal": "1",
            "rate": 1.7919
        },
    }
}

Usage of get_rates_with_diff()

from datetime import date
import cbar

previous_date = date(2024, 11, 25)
date_ = date(2024, 11, 26)
currencies = ["USD", "EUR"]

rates = cbar.get_rates_with_diff(previous_date, date_, currencies)

print(rates)
# Output:
{
    "previous_date": "25.11.2024",
    "date": "26.11.2024",
    "currencies": {
        "USD": {
            "nominal": "1",
            "previous_rate": 1.7,
            "rate": 1.7,
            "difference": 0.0,
        },
        "EUR": {
            "nominal": "1",
            "previous_rate": 1.7814,
            "rate": 1.7815,
            "difference": 0.0001,
        },
    }
}

Usage of convert()

from datetime import date
import cbar

amount = 100
from_currency = "USD"
to_currency = "AZN"
conversion_date = date(2024, 11, 25)

converted_amount = cbar.convert(amount, from_currency, to_currency, conversion_date)

print(converted_amount)
# Output:
170.0  # 1 USD = 1.7 AZN

You can find all available currency codes on the CBAR website

License

This project is licensed under the MIT License.