Finance manager
Лабораторна робота №2 - Документація коду
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
CurrencyConverter Class Reference

Handles currency conversion with automatic exchange rate updates from API. More...

#include <CurrencyConverter.h>

Public Member Functions

double convert (double amount, const std::string &from, const std::string &to)
 
void updateRate (const std::string &currency, double rate)
 
bool fetchRatesFromAPI (const std::string &base="")
 Fetches exchange rates from the configured API.
 
bool fetchRatesForCurrencies (const std::vector< std::string > &currencies, const std::string &base="")
 Fetches exchange rates for specific currencies.
 
void fetchRatesFromAPIAsync (std::function< void(bool)> callback, const std::string &base="")
 
bool updateRatesIfNeeded ()
 Automatically updates rates if cache has expired.
 
void setApiUrl (const std::string &url)
 Sets a custom API URL (for different exchange rate providers)
 
void setApiKey (const std::string &key)
 Sets API key for services that require authentication.
 
bool isCacheValid () const
 Checks if cached rates are still valid.
 

Public Attributes

std::string baseCurrency = "USD"
 
std::map< std::string, double > exchangeRate
 
std::string apiKey
 
std::string apiUrl = "https://api.exchangerate-api.com/v4/latest/"
 
std::chrono::system_clock::time_point lastUpdate
 
std::chrono::minutes cacheTimeout {60}
 

Detailed Description

Handles currency conversion with automatic exchange rate updates from API.

Supports fetching exchange rates from external APIs and converting between currencies. Uses cpr (C++ Requests) library for HTTP requests to banking/financial APIs.

Member Function Documentation

◆ convert()

double CurrencyConverter::convert ( double  amount,
const std::string &  from,
const std::string &  to 
)
inline

◆ fetchRatesForCurrencies()

bool CurrencyConverter::fetchRatesForCurrencies ( const std::vector< std::string > &  currencies,
const std::string &  base = "" 
)

Fetches exchange rates for specific currencies.

Parameters
currenciesVector of currency codes to fetch
baseBase currency code (default: uses baseCurrency member)
Returns
true if rates were successfully fetched

◆ fetchRatesFromAPI()

bool CurrencyConverter::fetchRatesFromAPI ( const std::string &  base = "")

Fetches exchange rates from the configured API.

Parameters
baseBase currency code (default: uses baseCurrency member)
Returns
true if rates were successfully fetched and updated

◆ fetchRatesFromAPIAsync()

void CurrencyConverter::fetchRatesFromAPIAsync ( std::function< void(bool)>  callback,
const std::string &  base = "" 
)

◆ isCacheValid()

bool CurrencyConverter::isCacheValid ( ) const
inline

Checks if cached rates are still valid.

Returns
true if rates are fresh (within cache timeout)

◆ setApiKey()

void CurrencyConverter::setApiKey ( const std::string &  key)
inline

Sets API key for services that require authentication.

Parameters
keyAPI key string

◆ setApiUrl()

void CurrencyConverter::setApiUrl ( const std::string &  url)
inline

Sets a custom API URL (for different exchange rate providers)

Parameters
urlAPI endpoint URL

◆ updateRate()

void CurrencyConverter::updateRate ( const std::string &  currency,
double  rate 
)
inline

◆ updateRatesIfNeeded()

bool CurrencyConverter::updateRatesIfNeeded ( )

Automatically updates rates if cache has expired.

Returns
true if rates were updated (or already fresh)

Member Data Documentation

◆ apiKey

std::string CurrencyConverter::apiKey

◆ apiUrl

std::string CurrencyConverter::apiUrl = "https://api.exchangerate-api.com/v4/latest/"

◆ baseCurrency

std::string CurrencyConverter::baseCurrency = "USD"

◆ cacheTimeout

std::chrono::minutes CurrencyConverter::cacheTimeout {60}

◆ exchangeRate

std::map<std::string, double> CurrencyConverter::exchangeRate

◆ lastUpdate

std::chrono::system_clock::time_point CurrencyConverter::lastUpdate

The documentation for this class was generated from the following files: