Add limit query to trocador
Godwin Asuquo committed
Feb 28, 2023 at 18:12 UTC
8419767c4f39dc33cd3ac974322bb826d3e0ddd1
1 file changed
+28
-2
lib/exchange/trocador/trocador_exchange_provider.dart
+28
-2
@@ -40,6 +40,7 @@ class TrocadorExchangeProvider extends ExchangeProvider {
40
static const newRatePath = '/api/new_rate';
41
static const createTradePath = 'api/new_trade';
42
static const tradePath = 'api/trade';
43
+ static const coinPath = 'api/coin';
44
String _lastUsedRateId;
45
46
@override
@@ -134,9 +135,34 @@ class TrocadorExchangeProvider extends ExchangeProvider {
135
{required CryptoCurrency from,
136
required CryptoCurrency to,
137
required bool isFixedRateMode}) async {
137
- //TODO: implement limits from trocador api
138
+
139
+ final params = <String, String> {
140
+ 'api_key': apiKey,
141
+ 'ticker': from.title.toLowerCase(),
142
+ 'name': from.name,
143
+ };
144
+
145
+ final String apiAuthority = shouldUseOnionAddress ? await _getAuthority() : clearNetAuthority;
146
+ final uri = Uri.https(apiAuthority, coinPath, params);
147
+
148
+ final response = await get(uri);
149
+
150
+ if (response.statusCode != 200) {
151
+ throw Exception('Unexpected http status: ${response.statusCode}');
152
+ }
153
+
154
+ final responseJSON = json.decode(response.body) as List<dynamic>;
155
+
156
+ if (responseJSON.isEmpty) {
157
+ throw Exception('No data');
158
+ }
159
+
160
+ final coinJson = responseJSON.first as Map<String, dynamic>;
161
+
162
+
163
return Limits(
139
- min: 0.0,
164
+ min: coinJson['minimum'] as double,
165
+ max: coinJson['maximum'] as double,
166
);
167
}
168