Alternera.Resources.Finance.RateLookup (alternera_resources_finance v0.9.0)

Copy Markdown View Source

The exchange rates' calculations, generic actions of Finance.ExchangeRate that read as the caller and change nothing. The REST API serves each as GET …/exchange_rate/<action>?… and MCP as the calculation of that name of finance.exchange_rate:

  • convert: an amount in one currency, in another, at the rate on date (today when not given). The result is rounded half up to the to currency's decimals.
  • rate: the rate from one currency to another on date, today's when not given, for a price on an older day.
  • history: the pair's rate on every day of a period that has one (since to until, the last 90 days by default, at most 3660 days), oldest first.

A day's rate is the newest one on or before it, found one of three ways, the newest day winning and, on the same day, the first of them:

  1. a rate from from to to;
  2. a rate from to to from, inverted;
  3. a cross rate through a base both are quoted against on the same day (EUR→SEK and EUR→USD give SEK→USD), the way a feed of one base's rates is used for every pair. It is looked for among the newest 200 rates quoting either currency on or before the day (@cross_window): a daily feed's 100 days. When one currency has many newer quotes the other lacks (quoted against several bases, or the other's feed stopped), an older day that has both is past the window and the cross rate is not found.

history lists only the days that have a rate of one of those kinds, with no carrying forward. Every rate is answered to 10 decimals (a result is computed from the whole rate), with rate_date its day and via the base of a cross rate.