Skip to content

Commit

Permalink
docs: added an example of usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed Sep 30, 2021
1 parent 66c5f91 commit 529922a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:coingecko_api/coingecko_api.dart';

Future<void> main() async {
print(
'This example demonstrates receiving OHLC data (open, high, low, close) '
'from CoinGecko on the BTC/USD pair for the last 7 days.',
);
final api = CoinGeckoApi();
print('Calling method getCoinOHLC() ...');
final result = await api.coins.getCoinOHLC(
id: 'bitcoin',
vsCurrency: 'usd',
days: 7,
);
if (!result.isError) {
print('getCoinOHLC() results:');
result.data.forEach(
(item) => print(
'${item.timestamp}: open = ${item.open}, high = ${item.high}, low = ${item.low}, close = ${item.close}'),
);
print('Test method completed successfully.');
} else {
print('getCoinOHLC() method returned error:');
print('${result.errorCode}: ${result.errorMessage}');
print('Test method failed.');
}
}

0 comments on commit 529922a

Please sign in to comment.