0 purchases
coingecko client
coingecko_client #
CoinGecko API client for Dart #
A simple and intuitive package for the CoinGecko REST API Service ( v3 ).
⚔️ Why this ❓🤨🤔 #
✔️ fully tested ( see test coverage ).
✔️ simple and easy to use.
✔️ almost all results are converted to model/dto/entity ( so you don't need to worry about making your own model classes ).
✔️ fully documented.
✔️ actively being developed and supported.
💡 You can go directly to the examples and see for yourself.
Table of Contents #
API Version Support
Requirements
Installation
Usage
Sample Usage
Endpoints
ping
coins
exchanges
simple
derivatives
indexes
nfts
contract
asset_platforms
categories
global
exchange rates
companies
trending
search
Issues / Bugs / Improvements
Contacts
API Version Support #
✔️ API v3
✔️ Community
Requirements #
✔️ dart sdk: >= 2.19.3
Installation #
Add the dependency to your Dart / Flutter project:
( in pubspec.yaml file under the dependencies, add the following )
coingecko_client: ^1.2.2
copied to clipboard
Go to pub.dev for more details.
Usage #
Import the library and initialize the client class.
import 'package:coingecko_client/coingecko_client.dart';
final client = CoinGeckoClient();
copied to clipboard
Use any of the client properties to access the services. (use coins)
All results are returned from a Future object so async/await is necessary.
final coinHistory = await client.coins.getHistory(
id: 'bitcoin',
date: DateTime.now()
);
copied to clipboard
The following sample just prints the property so just do yours here.
💡 TIP : Most editors(especially VS Code) supports object reflection. You can hover on the result object to conveniently get all the available properties you can use.
print(coinHistory);
print(coinHistory.name);
copied to clipboard
Result varies depending on the endpoint.
It's recommended to wrap it within a try/catch block to handle the runtime errors - not only because it's part of the package design but also the ideal way to do this.
Sample Usage #
import 'package:coingecko_client/coingecko_client.dart';
void main() async {
try {
final client = CoinGeckoClient();
final coinHistory = await client.coins.getHistory(
id: 'bitcoin',
date: DateTime.now()
);
print(coinHistory);
print(coinHistory.name);
} on Exception catch (e, _) {
/// Exception handling
/// All runtime exceptions will go here.
/// All http status code other than 200 will also be here.
/// [Sample error handling]
print("error occured");
if(e is NetworkRequestException) {
print(e.statusCode);
} else {
rethrow;
}
}
}
copied to clipboard
Look at the sample code.
HTTP status code other than 200 will be raised as an exception. i.e. 404 or 429.
Non-error status codes such as >= 201, 3xx or 1xx will still be treated as an exception as the API service does not require methods other than GET request.
This might change in the future but it's not part of their service as of now. (YAGNI)
Check here for more examples.
Endpoints #
[ Community ] #
🌐 ping #
📤 /ping #
client.ping.getResult();
copied to clipboard
🌐 coins #
📤 /coins/list #
client.coins.getBasicList();
copied to clipboard
📤 /coins/{id}/history #
client.coins.getHistory(
id: 'bitcoin',
date: DateTime.now()
);
copied to clipboard
📤 /coins/markets #
client.coins.getMarketList(
vsCurrency: Currencies.php
);
copied to clipboard
📤 /coins/{id} #
client.coins.getInfo(id: 'verus-coin');
copied to clipboard
📤 /coins/{id}/tickers #
client.coins.getTickers(id: 'bitcoin');
copied to clipboard
📤 /coins/{id}/market_chart #
client.coins.getMarketHistory(
id: 'bitcoin',
vsCurrency: Currencies.php,
days: DataRange.in1Day,
interval: 'daily'
);
copied to clipboard
📤 /coins/{id}/market_chart/range #
client.coins.getMarketHistoryWithDateRange(
id: 'bitcoin',
vsCurrency: Currencies.php,
from: DateTime.fromMillisecondsSinceEpoch(1392577232),
to: DateTime.fromMillisecondsSinceEpoch(1396587232)
);
copied to clipboard
📤 /coins/{id}/ohlc #
client.coins.getOhlcList(
id: 'bitcoin',
vsCurrency: Currencies.php,
days: DataRange.max
);
copied to clipboard
[ 💰PRO Endpoints ] #
📤 /coins/list/new #
client.coins.getNewList();
copied to clipboard
📤 /coins/top_gainers_losers #
client.coins.getTopGainersAndLosers(
vsCurrency: Currencies.php,
duration: CoinDuration.in14Days,
topCoins: CoinRanking.top300
);
copied to clipboard
🌐 exchanges #
📤 /exchanges #
client.exchanges.getList();
copied to clipboard
📤 /exchanges/list #
client.exchanges.getBasicList();
copied to clipboard
📤 /exchanges/{id} #
client.exchanges.getInfo(id: 'binance');
copied to clipboard
📤 /exchanges/{id}/tickers #
client.exchanges.getTickerList(
id: 'binance',
coinIds: ['bitcoin', 'ethereum'],
includeExchangeLogo: true,
page: 1,
depth: true,
order: ExchangeDataOrdering.trustScoreDesc
);
copied to clipboard
📤 /exchanges/{id}/volume_chart #
client.exchanges.getVolumeChartList(
id: 'binance',
days: DataRange.in1Day
);
copied to clipboard
🌐 simple #
📤 /simple/price #
client.simple.getCoinPrice(
ids: ['bitcoin', 'ethereum', 'verus-coin'],
vsCurrencies: [ Currencies.jpy, Currencies.usd, Currencies.php ],
includeMarketCap: true,
include24hrVol: true,
include24hrChange: true,
includeLastUpdatedAt: true,
precision: 18
);
copied to clipboard
📤 /simple/token_price/{id} #
client.simple.getTokenPrice(
id: 'avalanche',
contractAddresses: ['0x2098fABE9C82eb5280AF4841a5000f373E99a498'],
vsCurrencies: [ CryptoCurrencies.btc, CryptoCurrencies.eth ],
includeMarketCap: true,
include24hrVol: true,
include24hrChange: true,
includeLastUpdatedAt: true,
precision: 18
);
copied to clipboard
📤 /simple/supported_vs_currencies #
client.simple.getSupportedVsCurrencies();
copied to clipboard
🌐 derivatives #
📤 /derivatives #
client.derivatives.getList(
includeTickers: DerivativesTickers.unexpired
);
copied to clipboard
📤 /derivatives/exchanges #
client.derivatives.getExchangeList(
order: DerivativesExchangeOrdering.nameAsc,
perPage: 10,
page: 2
);
copied to clipboard
📤 /derivatives/exchanges/{id} #
client.derivatives.getExchange(
id: "bybit",
includeTickers: DerivativesTickers.unexpired
);
copied to clipboard
📤 /derivatives/exchanges/list #
client.derivatives.getExchangeBasicInfoList();
copied to clipboard
🌐 indexes #
📤 /indexes #
client.indexes.getList(
perPage: 10,
page: 2
);
copied to clipboard
📤 /indexes/{market_id}/{id} #
client.indexes.getInfo(
marketId: 'bybit',
id: 'HOT',
);
copied to clipboard
📤 /indexes/list #
client.indexes.getBasicInfo();
copied to clipboard
🌐 nfts #
📤 /nfts/list #
client.nfts.getBasicList(
perPage: 10,
page: 2
);
copied to clipboard
📤 /nfts/{id} #
client.nfts.getInfo(
id: 'meebits',
);
copied to clipboard
📤 /nfts/{asset_platform_id}/contract/{contract_address} #
client.nfts.getContractInfo(
assetPlatformId: 'ethereum',
contractAddress: '0x36F379400DE6c6BCDF4408B282F8b685c56adc60',
);
copied to clipboard
🌐 contract #
📤 /coins/{id}/contract/{contract_address}/market_chart #
client.contract.getMarketHistory(
id: 'ethereum',
contractAddress: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
vsCurrency: Currencies.jpy,
days: DataRange.in2Weeks,
);
copied to clipboard
📤 /coins/{id}/contract/{contract_address}/market_chart/range #
client.contract.getMarketHistoryWithDateRange(
id: 'ethereum',
contractAddress: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
vsCurrency: Currencies.php,
from: DateTime.fromMillisecondsSinceEpoch(1683175446, isUtc: true),
to: DateTime.fromMillisecondsSinceEpoch(1683262856, isUtc: true),
);
copied to clipboard
🌐 asset_platforms #
📤 /asset_platforms #
client.assetPlatforms.getList();
copied to clipboard
🌐 categories #
📤 /coins/categories/list #
client.categories.getBasicList();
copied to clipboard
📤 /coins/categories #
client.categories.getList(
order: CoinCategoriesDataOrdering.marketCapAsc
);
copied to clipboard
🌐 global #
📤 /global #
client.global.getCryptoInfo();
copied to clipboard
📤 /global/decentralized_finance_defi #
client.global.getDefiInfo();
copied to clipboard
🌐 exchange rates #
📤 /exchange_rates #
client.exchangeRates.getList();
copied to clipboard
🌐 companies #
📤 /companies/public_treasury/{coin_id} #
client.companies.getList(
coinId: 'ethereum'
);
copied to clipboard
🌐 trending #
📤 /search/trending #
client.trending.getResult();
copied to clipboard
🌐 search #
📤 /search #
client.search.getResult(query: 'bybit');
copied to clipboard
🐞 Issues / Bugs / Improvements #
If you found any issues or bugs, please raise it here.
For urgent fix, please chat directly to the discord channel and I'll find time to resolve it.
Should you decide to make your own change, create your own branch and raise a PR to the master branch and ping me.
Any suggestions or concerns, you can contact me directly using discord, twitter or email.
Contacts #
[email protected]
Pangz#4102
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.