forex method
The forex method is used to get the forex rates for a given stock symbol.
The fromCurrency
argument is used to specify the from currency to convert.
The toCurrency
argument is used to specify the to currency to convert.
// Get forex rates for EUR to USD
final client = BavestRestClient(api_key);
final forex = client.forex('EUR', 'USD');
Implementation
@override
Future<Forex> forex(String fromCurrency, String toCurrency) async {
const url = '$_baseUrl/fx/quote';
final params = {
'from': fromCurrency,
'to': toCurrency,
};
var response = await _post(url, params);
if (_isSuccess(response)) {
return Forex.fromJson(jsonDecode(response!.data));
}
throw Exception(
"could not receive forex data for $fromCurrency to $toCurrency");
}