read_latest_usd_per_source_currency

Documentation for eth_defi.feed.stablecoin_rate.read_latest_usd_per_source_currency function.

read_latest_usd_per_source_currency(currency_db_path, source_currency, coingecko_fetch_date, source='fawazahmed0', max_age_days=7)

Read the latest USD/source-currency FX rate from local DuckDB.

The currency API database stores raw rows as quote units per one base unit. With the production base usd this means, for example, EUR rows are EUR per 1 USD. Stablecoin depeg checks need USD per one source-currency unit, so this helper inverts the stored raw rate.

Parameters
  • currency_db_path (pathlib.Path) – DuckDB path populated by eth_defi.currency_api.

  • source_currency (str) – Lower-case source currency ticker, e.g. eur or jpy.

  • coingecko_fetch_date (datetime.date) – Calendar date of the CoinGecko token price fetch.

  • source (str) – Currency API source column to read.

  • max_age_days (int) – Maximum allowed age between the token price date and FX row date.

Returns

USD per one source-currency unit, or None when no local row exists.

Return type

Optional[eth_defi.feed.stablecoin_rate.SourceCurrencyRate]