Help:CurrencyExchange

From Liquipedia Commons Wiki

The CurrencyExchange extension is meant to provide easy access to exchange rates. The data is sourced from the exchangerate.host. Currently the following currencies are supported within their respective valid date range:

The source of the extension's data contains occasional gaps. In order to mitigate this, the extension will attempt to automatically search for a relevant data point for nearby dates. If the gap is too large, the extension will error out.

Usage of the extension is fairly easy. There is both a parser function and a Lua interface available. The functions have 4 parameters:

  1. amount the value of the original currency (a number)
  2. base_currency the original currency abbreviation (as one of the allowed currencies from above)
  3. converted_currency the currency you want it converted into (as one of the allowed currencies from above)
  4. date (in the form yyyy-mm-dd, if the chosen date is in the future, the extension will use today's date)
 {{#currencyexchange: 1 | 2 | 3 | 4 }}

Note that the date given can be partial, as long as it is in one of the following formats:

yyyy-mm-??
yyyy-??-??
yyyy-mm-XX
yyyy-XX-XX

The date will then default to the last day in the given range.

An example call could look something like {{#currencyexchange:100|USD|EUR|2018-10-29}} and would return 87.727. The Lua version works fairly similar, the same call would look something like local convertedValue = mw.ext.CurrencyExchange.currencyexchange( 100, 'USD', 'EUR', '2018-10-29' )

In case of an error, the parser function will provide an explicit error message. The Lua version will instead return false.