An open API service indexing awesome lists of open source software.

https://github.com/pangz-lab/coingecko_client

CoinGecko API Client for the Dart Language
https://github.com/pangz-lab/coingecko_client

api-client bitcoin btc client coingecko coingecko-api-client coingecko-coupon coingeckoapi crypto crypto-client crypto-price cryptocurrency dart dart-api-client dart-coingecko-api-client eth ethereum verus vrsc

Last synced: about 2 months ago
JSON representation

CoinGecko API Client for the Dart Language

Awesome Lists containing this project

README

        

![version](https://img.shields.io/badge/version-v1.2.2-blue)
![coverage](https://img.shields.io/badge/coverage-100%25-success)
![sdk](https://img.shields.io/badge/sdk-v2.19.3-blue)
![license](https://img.shields.io/badge/license-BSD--3-blue)
[![GitHub issues by-label](https://img.shields.io/github/issues/badges/shields/open)](https://github.com/pangz-lab/coingecko_client/issues)


chat on Discord


follow on witter

# coingecko_client

## CoinGecko API client for Dart





A simple and intuitive package for the [CoinGecko REST API Service](https://www.coingecko.com/en/api/documentation) ( v3 ).



βš”οΈ Why this β“πŸ€¨πŸ€”
---


&nbsp

βœ”οΈ 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.

&nbsp

#### πŸ’‘ You can go directly to the [examples](https://github.com/pangz-lab/coingecko_client/tree/master/example) and see for yourself.

___

Table of Contents
---------------
1. [API Version Support](#api-version-support)
2. [Requirements](#requirements)
3. [Installation](#installation)
4. [Usage](#usage)
- [Sample Usage](#sample-usage)
5. [Endpoints](#endpoints)
- [ping](#-ping)
- [coins](#-coins)
- [exchanges](#-exchanges)
- [simple](#-simple)
- [derivatives](#-derivatives)
- [indexes](#-indexes)
- [nfts](#-nfts)
- [contract](#-contract)
- [asset_platforms](#-asset_platforms)
- [categories](#-categories)
- [global](#-global)
- [exchange rates](#-exchange-rates)
- [companies](#-companies)
- [trending](#-trending)
- [search](#-search)
6. [Issues / Bugs / Improvements](#-issues--bugs--improvements)
7. [Contacts](#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 )
```yaml
coingecko_client: ^1.2.2
```

Go to pub.dev for more details.

---

# Usage
- Import the library and initialize the client class.
```dart
import 'package:coingecko_client/coingecko_client.dart';

final client = CoinGeckoClient();
```
- 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**.
```dart
final coinHistory = await client.coins.getHistory(
id: 'bitcoin',
date: DateTime.now()
);
```
- 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.
```dart
print(coinHistory);
print(coinHistory.name);
```
- 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
---
```dart
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;
}
}
}
```
- Look at the [sample code](https://github.com/pangz-lab/coingecko_client/blob/master/example/coingecko_client_sample.dart).
- HTTP status code other than [200](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/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](https://github.com/pangz-lab/coingecko_client/tree/master/example") for more examples.

___

# Endpoints
## [ Community ]

# [🌐](#table-of-contents) ping
### πŸ“€ */ping*
```dart
client.ping.getResult();
```

___

# [🌐](#table-of-contents) coins
### πŸ“€ */coins/list*
```dart
client.coins.getBasicList();
```
### πŸ“€ */coins/{id}/history*
```dart
client.coins.getHistory(
id: 'bitcoin',
date: DateTime.now()
);
```
### πŸ“€ */coins/markets*
```dart
client.coins.getMarketList(
vsCurrency: Currencies.php
);
```
### πŸ“€ */coins/{id}*
```dart
client.coins.getInfo(id: 'verus-coin');
```
### πŸ“€ */coins/{id}/tickers*
```dart
client.coins.getTickers(id: 'bitcoin');
```
### πŸ“€ */coins/{id}/market_chart*
```dart
client.coins.getMarketHistory(
id: 'bitcoin',
vsCurrency: Currencies.php,
days: DataRange.in1Day,
interval: 'daily'
);
```
### πŸ“€ */coins/{id}/market_chart/range*
```dart
client.coins.getMarketHistoryWithDateRange(
id: 'bitcoin',
vsCurrency: Currencies.php,
from: DateTime.fromMillisecondsSinceEpoch(1392577232),
to: DateTime.fromMillisecondsSinceEpoch(1396587232)
);
```
### πŸ“€ */coins/{id}/ohlc*
```dart
client.coins.getOhlcList(
id: 'bitcoin',
vsCurrency: Currencies.php,
days: DataRange.max
);
```

## **[ πŸ’°PRO Endpoints ]**
### πŸ“€ */coins/list/new*
```dart
client.coins.getNewList();
```
### πŸ“€ */coins/top_gainers_losers*
```dart
client.coins.getTopGainersAndLosers(
vsCurrency: Currencies.php,
duration: CoinDuration.in14Days,
topCoins: CoinRanking.top300
);
```

___

# [🌐](#table-of-contents) exchanges
### πŸ“€ */exchanges*
```dart
client.exchanges.getList();
```
### πŸ“€ */exchanges/list*
```dart
client.exchanges.getBasicList();
```
### πŸ“€ */exchanges/{id}*
```dart
client.exchanges.getInfo(id: 'binance');
```
### πŸ“€ */exchanges/{id}/tickers*
```dart
client.exchanges.getTickerList(
id: 'binance',
coinIds: ['bitcoin', 'ethereum'],
includeExchangeLogo: true,
page: 1,
depth: true,
order: ExchangeDataOrdering.trustScoreDesc
);
```
### πŸ“€ */exchanges/{id}/volume_chart*
```dart
client.exchanges.getVolumeChartList(
id: 'binance',
days: DataRange.in1Day
);
```

___

# [🌐](#table-of-contents) simple
### πŸ“€ */simple/price*
```dart
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
);
```
### πŸ“€ */simple/token_price/{id}*
```dart
client.simple.getTokenPrice(
id: 'avalanche',
contractAddresses: ['0x2098fABE9C82eb5280AF4841a5000f373E99a498'],
vsCurrencies: [ CryptoCurrencies.btc, CryptoCurrencies.eth ],
includeMarketCap: true,
include24hrVol: true,
include24hrChange: true,
includeLastUpdatedAt: true,
precision: 18
);
```
### πŸ“€ */simple/supported_vs_currencies*
```dart
client.simple.getSupportedVsCurrencies();
```

___

# [🌐](#table-of-contents) derivatives
### πŸ“€ */derivatives*
```dart
client.derivatives.getList(
includeTickers: DerivativesTickers.unexpired
);
```
### πŸ“€ */derivatives/exchanges*
```dart
client.derivatives.getExchangeList(
order: DerivativesExchangeOrdering.nameAsc,
perPage: 10,
page: 2
);
```
### πŸ“€ */derivatives/exchanges/{id}*
```dart
client.derivatives.getExchange(
id: "bybit",
includeTickers: DerivativesTickers.unexpired
);
```
### πŸ“€ */derivatives/exchanges/list*
```dart
client.derivatives.getExchangeBasicInfoList();
```

___

# [🌐](#table-of-contents) indexes
### πŸ“€ */indexes*
```dart
client.indexes.getList(
perPage: 10,
page: 2
);
```
### πŸ“€ */indexes/{market_id}/{id}*
```dart
client.indexes.getInfo(
marketId: 'bybit',
id: 'HOT',
);
```
### πŸ“€ */indexes/list*
```dart
client.indexes.getBasicInfo();
```

___

# [🌐](#table-of-contents) nfts
### πŸ“€ */nfts/list*
```dart
client.nfts.getBasicList(
perPage: 10,
page: 2
);
```
### πŸ“€ */nfts/{id}*
```dart
client.nfts.getInfo(
id: 'meebits',
);
```
### πŸ“€ */nfts/{asset_platform_id}/contract/{contract_address}*
```dart
client.nfts.getContractInfo(
assetPlatformId: 'ethereum',
contractAddress: '0x36F379400DE6c6BCDF4408B282F8b685c56adc60',
);
```

___

# [🌐](#table-of-contents) contract
### πŸ“€ */coins/{id}/contract/{contract_address}/market_chart*
```dart
client.contract.getMarketHistory(
id: 'ethereum',
contractAddress: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
vsCurrency: Currencies.jpy,
days: DataRange.in2Weeks,
);
```
### πŸ“€ */coins/{id}/contract/{contract_address}/market_chart/range*
```dart
client.contract.getMarketHistoryWithDateRange(
id: 'ethereum',
contractAddress: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
vsCurrency: Currencies.php,
from: DateTime.fromMillisecondsSinceEpoch(1683175446, isUtc: true),
to: DateTime.fromMillisecondsSinceEpoch(1683262856, isUtc: true),
);
```

___

# [🌐](#table-of-contents) asset_platforms
### πŸ“€ */asset_platforms*
```dart
client.assetPlatforms.getList();
```

# [🌐](#table-of-contents) categories
### πŸ“€ */coins/categories/list*
```dart
client.categories.getBasicList();
```
### πŸ“€ */coins/categories*
```dart
client.categories.getList(
order: CoinCategoriesDataOrdering.marketCapAsc
);
```

___

# [🌐](#table-of-contents) global
### πŸ“€ */global*
```dart
client.global.getCryptoInfo();
```
### πŸ“€ */global/decentralized_finance_defi*
```dart
client.global.getDefiInfo();
```

___

# [🌐](#table-of-contents) exchange rates
### πŸ“€ */exchange_rates*
```dart
client.exchangeRates.getList();
```

___

# [🌐](#table-of-contents) companies
### πŸ“€ */companies/public_treasury/{coin_id}*
```dart
client.companies.getList(
coinId: 'ethereum'
);
```

___

# [🌐](#table-of-contents) trending
### πŸ“€ */search/trending*
```dart
client.trending.getResult();
```

___

# [🌐](#table-of-contents) search
### πŸ“€ */search*
```dart
client.search.getResult(query: 'bybit');
```


🐞 Issues / Bugs / Improvements
---------------
- If you found any issues or bugs, [please raise it here](https://github.com/pangz-lab/coingecko_client/issues).
- 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



follow on witter