Skip to content

Commit

Permalink
Rename variables, break lines
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlimacz committed Jan 4, 2025
1 parent 055f69e commit 833b45b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions beanprice/sources/ecbrates.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,45 +83,47 @@ def _get_quote(ticker, date):

# Get EUR rates by calling the API (or use defaults)
if base == "EUR" and symbol != "EUR":
EUR_to_symbol, symbol_rate_date, symbol_rate_precision = _get_rate_EUR_to_CCY(
eur_to_symbol, symbol_rate_date, symbol_rate_precision = _get_rate_EUR_to_CCY(
symbol, date
)
EUR_to_base = Decimal(1)
eur_to_base = Decimal(1)
base_rate_date = symbol_rate_date
base_rate_precision = 28
elif base != "EUR" and symbol == "EUR":
EUR_to_base, base_rate_date, base_rate_precision = _get_rate_EUR_to_CCY(
eur_to_base, base_rate_date, base_rate_precision = _get_rate_EUR_to_CCY(
base, date
)
EUR_to_symbol = Decimal(1)
eur_to_symbol = Decimal(1)
symbol_rate_date = base_rate_date
symbol_rate_precision = 28
else:
EUR_to_base, base_rate_date, base_rate_precision = _get_rate_EUR_to_CCY(
eur_to_base, base_rate_date, base_rate_precision = _get_rate_EUR_to_CCY(
base, date
)
EUR_to_symbol, symbol_rate_date, symbol_rate_precision = _get_rate_EUR_to_CCY(
eur_to_symbol, symbol_rate_date, symbol_rate_precision = _get_rate_EUR_to_CCY(
symbol, date
)

# Raise error if retrieved subrates for differnt dates
if base_rate_date != symbol_rate_date:
raise ECBRatesError(
f"Subrates for different dates: ({base}, {base_rate_date}) vs. ({symbol}, {symbol_rate_date})"
f"Subrates for different dates: ({base}, {base_rate_date}) \
vs. ({symbol}, {symbol_rate_date})"
)

# Calculate base -> symbol
if EUR_to_symbol is None or EUR_to_base is None:
if eur_to_symbol is None or eur_to_base is None:
raise ECBRatesError(
f"At least one of the subrates returned None: (EUR{symbol}: {EUR_to_symbol}, EUR{base}: {EUR_to_base})"
f"At least one of the subrates returned None: \
(EUR{symbol}: {eur_to_symbol}, EUR{base}: {eur_to_base})"
)

# Derive precision from sunrates (must be at least 5)
minimal_precision = 5
getcontext().prec = max(
minimal_precision, min(base_rate_precision, symbol_rate_precision)
)
price = EUR_to_symbol / EUR_to_base
price = eur_to_symbol / eur_to_base
time = parse(base_rate_date).replace(tzinfo=tz.tzutc())
return source.SourcePrice(price, time, symbol)

Expand Down

0 comments on commit 833b45b

Please sign in to comment.