jaw-sh / stream-nexus

Unified multicast stream chat overlay.
24 stars 8 forks source link

Exchange Rates #18

Closed jaw-sh closed 2 days ago

jaw-sh commented 8 months ago

The free exchange rate API I used was consumed by API Layer that I refuse to use because (1) they limit to 10 requests per month which is unsatisfactory, and (2) they require HTTP without SSL.

The best alternative I've seen is the EU Central Bank. https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html

This can easily be used to roughly convert any value to US by taking the USD exchange rate and multiplying that to any other exchange rate value.

They publish exchange rates in a .csv.zip file. The two downsides over the free API I was using is 1) ECB does not publish EUR to RUB (the old one did). 2) ECB does not publish Cryptocurrency information (while the old free one API layer destroyed did).

y-a-t-s commented 7 months ago

https://openexchangerates.org/ looks good. Their free tier uses USD as the base and is capped at 1000 requests per month. The JSON response looks almost identical to that of the previous API so it would be a minimal rewrite. They have a rate for BTC but I don't see any other popular ones included.

Sample response

{
  "disclaimer": "Usage subject to terms: https://openexchangerates.org/terms",
  "license": "https://openexchangerates.org/license",
  "timestamp": 1704034800,
  "base": "USD",
  "rates": {
    "AED": 3.6728,
    "AFN": 70.770205,
    "ALL": 93.709012,
    "AMD": 405.227858,
    "ANG": 1.805708,
    "AOA": 828.8,
    "ARS": 809.509745,
    "AUD": 1.467352,
    "AWG": 1.8,
    "AZN": 1.7,
    "BAM": 1.769074,
    "BBD": 2,
    "BDT": 109.954323,
    "BGN": 1.77201,
    "BHD": 0.37755,
    "BIF": 2853.953645,
    "BMD": 1,
    "BND": 1.321876,
    "BOB": 6.923251,
    "BRL": 4.8525,
    "BSD": 1,
    "BTC": 0.000023533811,
    "BTN": 83.344948,
    "BWP": 13.430419,
    "BYN": 3.307856,
    "BZD": 2.019538,
    "CAD": 1.32635,
    "CDF": 2735.191936,
    "CHF": 0.840895,
    "CLF": 0.032056,
    "CLP": 884.52806,
    "CNH": 7.12908,
    "CNY": 7.0798,
    "COP": 3881.32605,
    "CRC": 520.555748,
    "CUC": 1,
    "CUP": 25.75,
    "CVE": 99.737688,
    "CZK": 22.38225,
    "DJF": 178.390824,
    "DKK": 6.7547,
    "DOP": 58.106828,
    "DZD": 134.326,
    "EGP": 30.980055,
    "ERN": 15,
    "ETB": 56.424408,
    "EUR": 0.904527,
    "FJD": 2.19495,
    "FKP": 0.784929,
    "GBP": 0.784929,
    "GEL": 2.685,
    "GGP": 0.784929,
    "GHS": 11.987698,
    "GIP": 0.784929,
    "GMD": 67.325,
    "GNF": 8614.748244,
    "GTQ": 7.837728,
    "GYD": 209.777931,
    "HKD": 7.81005,
    "HNL": 24.720727,
    "HRK": 6.82642,
    "HTG": 132.124292,
    "HUF": 345.981734,
    "IDR": 15390.1,
    "ILS": 3.615395,
    "IMP": 0.784929,
    "INR": 83.21895,
    "IQD": 1311.476074,
    "IRR": 42105,
    "ISK": 136.013795,
    "JEP": 0.784929,
    "JMD": 154.79171,
    "JOD": 0.7096,
    "JPY": 141.02502648,
    "KES": 157.2973,
    "KGS": 89.0853,
    "KHR": 4092.983177,
    "KMF": 445.149612,
    "KPW": 900,
    "KRW": 1294.53,
    "KWD": 0.308082,
    "KYD": 0.834969,
    "KZT": 457.808534,
    "LAK": 20576.345995,
    "LBP": 15058.314301,
    "LKR": 324.508163,
    "LRD": 188.475008,
    "LSL": 18.503369,
    "LYD": 4.774094,
    "MAD": 9.916964,
    "MDL": 17.33255,
    "MGA": 4616.711633,
    "MKD": 55.732438,
    "MMK": 2104.01623,
    "MNT": 3450,
    "MOP": 8.061869,
    "MRU": 39.29266,
    "MUR": 44.2577,
    "MVR": 15.4,
    "MWK": 1686.578604,
    "MXN": 16.9712,
    "MYR": 4.595,
    "MZN": 63.899991,
    "NAD": 18.503369,
    "NGN": 898.286694,
    "NIO": 36.669532,
    "NOK": 10.216308,
    "NPR": 133.351706,
    "NZD": 1.581278,
    "OMR": 0.38569,
    "PAB": 1,
    "PEN": 3.699788,
    "PGK": 3.78816,
    "PHP": 55.399998,
    "PKR": 278.728402,
    "PLN": 3.936774,
    "PYG": 7298.567286,
    "QAR": 3.653023,
    "RON": 4.5066,
    "RSD": 105.984351,
    "RUB": 89.249994,
    "RWF": 1261.362945,
    "SAR": 3.75,
    "SBD": 8.427507,
    "SCR": 13.541009,
    "SDG": 601,
    "SEK": 10.07275,
    "SGD": 1.3207,
    "SHP": 0.784929,
    "SLL": 20969.5,
    "SOS": 572.565962,
    "SRD": 36.7455,
    "SSP": 130.26,
    "STD": 22281.8,
    "STN": 22.160915,
    "SVC": 8.766677,
    "SYP": 2512.53,
    "SZL": 18.492154,
    "THB": 34.25542,
    "TJS": 10.965764,
    "TMT": 3.51,
    "TND": 3.06425,
    "TOP": 2.330633,
    "TRY": 29.476298,
    "TTD": 6.800235,
    "TWD": 30.68355,
    "TZS": 2521.826057,
    "UAH": 38.094523,
    "UGX": 3787.247341,
    "USD": 1,
    "UYU": 39.111755,
    "UZS": 12361.97774,
    "VES": 35.845686,
    "VND": 24268.902622,
    "VUV": 118.722,
    "WST": 2.8,
    "XAF": 593.330932,
    "XAG": 0.04202829,
    "XAU": 0.00048476,
    "XCD": 2.70255,
    "XDR": 0.746506,
    "XOF": 593.330932,
    "XPD": 0.00090852,
    "XPF": 107.938804,
    "XPT": 0.00100578,
    "YER": 250.249998,
    "ZAR": 18.300655,
    "ZMW": 25.783548,
    "ZWL": 322
  }
}

balupton commented 2 weeks ago

You could cache the exchange rates right, only updating them weekly?

y-a-t-s commented 3 days ago

Have we decided on an API yet?

For crypto exchange rates, coinlayer's free tier does 100 requests per month, with USD as the target currency, and has SSL. I know they're an APILayer service, but it doesn't seem to have the same downsides you outline above. Plus, once we get fiat rates sorted out, we could convert crypto rates to any currency other than USD if we wanted to.

You could cache the exchange rates right, only updating them weekly?

I had a branch at one point that wrote most recent rate data to a json file to use as a fallback, but it never got merged in. I think it's worth having such a backup once the API host is figured out.

jaw-sh commented 3 days ago

how about the ecb exchange rate and a fixed rate for rub.

y-a-t-s commented 3 days ago

Sounds good. I'll take a look at it.