diff --git a/lib/exchange/trocador/trocador_exchange_provider.dart b/lib/exchange/trocador/trocador_exchange_provider.dart index 457757ea7..49503a1d0 100644 --- a/lib/exchange/trocador/trocador_exchange_provider.dart +++ b/lib/exchange/trocador/trocador_exchange_provider.dart @@ -40,6 +40,7 @@ class TrocadorExchangeProvider extends ExchangeProvider { static const newRatePath = '/api/new_rate'; static const createTradePath = 'api/new_trade'; static const tradePath = 'api/trade'; + static const coinPath = 'api/coin'; String _lastUsedRateId; @override @@ -134,9 +135,34 @@ class TrocadorExchangeProvider extends ExchangeProvider { {required CryptoCurrency from, required CryptoCurrency to, required bool isFixedRateMode}) async { - //TODO: implement limits from trocador api + + final params = { + 'api_key': apiKey, + 'ticker': from.title.toLowerCase(), + 'name': from.name, + }; + + final String apiAuthority = shouldUseOnionAddress ? await _getAuthority() : clearNetAuthority; + final uri = Uri.https(apiAuthority, coinPath, params); + + final response = await get(uri); + + if (response.statusCode != 200) { + throw Exception('Unexpected http status: ${response.statusCode}'); + } + + final responseJSON = json.decode(response.body) as List; + + if (responseJSON.isEmpty) { + throw Exception('No data'); + } + + final coinJson = responseJSON.first as Map; + + return Limits( - min: 0.0, + min: coinJson['minimum'] as double, + max: coinJson['maximum'] as double, ); }