getOracleData method
Implementation
Future<OracleUcoPrice> getOracleData({int timestamp = 0}) async {
final requestHeaders = <String, String>{
'Content-type': 'application/json',
'Accept': 'application/json',
};
final body = timestamp == 0
? '{"query": "query { oracleData { timestamp services { uco { eur, usd } } } }"}'
: '{"query": "query { oracleData(timestamp: $timestamp) { timestamp services { uco { eur, usd } } } }"}';
final responseHttp = await http.post(
Uri.parse('$endpoint/api'),
body: body,
headers: requestHeaders,
);
if (responseHttp.statusCode != 200) {
throw HttpException(responseHttp.toString());
}
final oracleDataResponse = oracleDataResponseFromJson(
responseHttp.body,
);
final uco = oracleDataResponse.data?.oracleData?.services?.uco;
return OracleUcoPrice(
timestamp: oracleDataResponse.data?.oracleData?.timestamp,
uco: Uco(
eur: uco!.eur,
usd: uco.usd,
),
);
}