Skip to content

feat(currency_rates): add central bank tables as a rate provider - #2127

Open
cahthuranag wants to merge 1 commit into
yeti-switch:masterfrom
cahthuranag:feat/central-bank-rates
Open

cahthuranag wants to merge 1 commit into
yeti-switch:masterfrom
cahthuranag:feat/central-bank-rates

Conversation

@cahthuranag

Copy link
Copy Markdown

app/services/currency_rates/providers/ has Frankfurter (30 ECB currencies), Bank of Israel and NBU, so an installation billing in another country has no source for its own central bank's rate.

This adds one CrossRateBase provider, selected per currency like the others. Nothing is requested unless a currency uses it.

  • Reads one bank's latest table from https://allratestoday.com/api/open/central-bank/{bank}. currency_rates.central_bank_code in yeti_web.yml picks the bank (bcb, rbi); a missing code raises before any request.
  • Banks differ in orientation (EUR/USD, USD/INR), so the home currency is the one in most pairs.
  • A pair uses the published mid, otherwise the mean of buy and sell. Period averages are skipped.
  • A stale table raises, so existing rates stay in place.

Limits: one bank per installation, latest table only, no SUPPORTED_CURRENCIES since it depends on the bank.

Tested without the Rails app (no PostgreSQL here): the four provider specs pass on Ruby 3.2, rubocop 1.69 with the repo's cops is clean, and live ecb, rbi and sama tables match Frankfurter within 1%. make test and currency_spec.rb were not run.

Disclosure: I work on allratestoday.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant