pub fn py_get_exchange_rate(
from_currency: &str,
to_currency: &str,
price_type: PriceType,
quotes_bid: HashMap<String, f64>,
quotes_ask: HashMap<String, f64>,
) -> PyResult<Option<Decimal>>Expand description
Calculates the exchange rate between two currencies using provided bid and ask quotes.
This function builds a graph of direct conversion rates from the quotes and searches for a
conversion path whose accumulated rate is representable as a positive Decimal.
If a path calculation is unrepresentable, the search may examine every simple path. In the
worst case, this takes exponential time in dense graphs, even when a valid route exists.
Identical from_currency and to_currency return a rate of one without inspecting the quotes.
Returns Ok(None) when no path is found and all quote and path calculations are representable.
ยงErrors
Returns an error if:
quotes_bidorquotes_askis empty.quotes_bidandquotes_asklengths are not equal.price_typeis equal toLastorMark(cannot calculate from quotes).- The bid or ask side of a pair is missing.
- No rate is found, and a calculation for any supplied pair or searched path overflows or underflows to zero.