Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new-unit] more currencies using other free exchange rate API #252

Open
adrianinsaval opened this issue Oct 5, 2023 · 6 comments
Open
Labels
enhancement New feature or request new-units Request for adding new units to the app

Comments

@adrianinsaval
Copy link

Description
A bigger pool of currencies would be nice. Personally would love to have PYG available, I read the disclaimer on the issue template and understand that this app is not in a position to pay for a service, however there are free services available with more currencies than the european central bank, see https://open.er-api.com/v6/latest and it's docs: https://www.exchangerate-api.com/docs/free
It's rate limited but the app wouldn't need to access it that often.
I would still leave the european bank as fallback API since it's more likely to stay free for posterity, but it would be nice to use this to support less popular currencies.

@adrianinsaval
Copy link
Author

chat gpt says to do this on https://github.com/ferraridamiano/ConverterNOW/blob/master/lib/models/currencies.dart

  Future<Currencies> downloadCurrencies() async {
    try {
      var response = await http.get(Uri.parse('https://open.er-api.com/v6/latest'));

      if (response.statusCode == 200) {
        var lastUpdate = DateFormat("yyyy-MM-dd").format(DateTime.now());
        Map<String, dynamic> data = json.decode(response.body);
        Map<String, double> exchangeRates = {'EUR': 1};

        // Update exchange rates from the API response
        for (var currency in defaultExchangeRates.keys) {
          if (currency != 'EUR' && data.containsKey(currency)) {
            exchangeRates[currency] = data[currency];
          }
        }

        pref.setString('currenciesRates', jsonEncode(exchangeRates));
        pref.setString('lastUpdateCurrencies', lastUpdate);
        return Currencies(
          exchangeRates: exchangeRates,
          lastUpdate: lastUpdate,
        );
      }
    } catch (e) {
      debugPrint(e.toString());
    }
    return readSavedCurrencies();
  }

no clue if that is even valid code. I think that API uses USD as base though, might need to change that or use https://open.er-api.com/v6/latest/EUR instead

@ferraridamiano
Copy link
Owner

It's rate limited but the app wouldn't need to access it that often.

The website you mention says that it includes 1.5k request in the free plan. This app has more than 1.5k MAU with only the installations from the play store.

At the moment the european central bank api is the most trustworthy service without such limitations. I will leave this open for further discussion and new ideas since this is one of the most requestes features.

@adrianinsaval
Copy link
Author

But I would imagine the limitation is by IP address not by app, how would it even know it's all from the same app

@ferraridamiano
Copy link
Owner

Isn't it related to the free API key?

@adrianinsaval
Copy link
Author

adrianinsaval commented Oct 7, 2023

I assume you looked at the "Free API" card, look at the "Open API" instead. No API key is required, each request would be associated with each individual user not the app itself. The european bank is most definitely the most trustworthy source, but it would be nice to have this as an option for more obscure currencies.

@ferraridamiano
Copy link
Owner

Oh, right! Yes, technically it is feasible. Maybe we could use the ECB for the current currencies and this service for the other one. I will take a look, if you want to submit a PR I can review it

@ferraridamiano ferraridamiano added enhancement New feature or request new-units Request for adding new units to the app labels Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new-units Request for adding new units to the app
Projects
None yet
Development

No branches or pull requests

2 participants