搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.2

coingecko_api

提供對 CoinGecko API(版本 3)簡單存取的 Dart 套件

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1380
喜歡數
27
Pub 分數
145

安裝套件

flutter pub add coingecko_api

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

coingecko_api 套件為 Dart 與 Flutter 應用程式提供了一種簡單的方式來與 CoinGecko API(版本 3)互動。它讓開發者能夠取得即時的加密貨幣資料,包含價格、市場資訊、匯率等。此套件設計簡潔且可靠,支援所有主要平台:Android、iOS、Web、macOS、Windows 與 Linux。適合需要即時加密貨幣市場洞察的應用程式,將複雜的 HTTP 請求抽象成易用的方法。該套件於 GitHub 上維護,並可透過 Flutter 的 pub 套件管理器順暢整合。

適用情境

  • 獲取即時加密貨幣價格
  • 在儀表板中顯示市場趨勢
  • 建構加密貨幣投資組合追蹤器
  • 整合即時匯率資料
  • 監控令牌隨時間的效能

主要特色

  • 簡單、乾淨的 API 界面
  • 支援所有主要平台
  • 即時資料存取
  • 全面的端點覆蓋
  • 與 Flutter 的輕鬆整合

適合對象

  • 加密貨幣追蹤應用
  • 區塊鏈分析工具
  • 投資組合管理介面
  • Web3 應用後端
  • 關於加密貨幣的教育項目

使用建議

  • 需要網路連接以取得資料
  • 依 CoinGecko 條款,每分鐘有速率限制
  • 可能需要針對網路失敗進行錯誤處理
  • 依賴外部 API 的穩定性
  • 不適用於僅離線的應用程式

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Simple Dart wrapper for the CoinGecko API

Pub Points Pub Popularity Pub Likes

Table of contents

Installation

Add the dependency to your Dart / Flutter project:

dependencies:
  coingecko_api: ^2.0.0

Usage

  1. Create an instance of the API wrapper:
    CoinGeckoApi api = CoinGeckoApi();
    
  2. Use any methods provided by wrapper. The methods are divided into sections, just as the CoinGecko does.
    final marketChart = await api.coins.getCoinMarketChart(
      id: 'bitcoin',
      vsCurrency: 'usd',
      days: 7,
    );
    
  3. Work with the result as you see fit:
    if (!marketChart.isError) {
      marketChart.data.forEach((item) {
        print('Price: ${item.price}, Market Cap: ${item.marketCap}');
      });
    }
    

Documentation

All methods are asynchronous and use Future, so you need to use await to get the result.

Query results

The result of each method is a special object of type CoinGeckoResult. This is a kind of wrapper that allows you to first find out how successful the request was using its isError property. If isError is false, then we can use the data property of this object to get the processed data itself. Otherwise, we can view the error code and error message using properties errorCode and errorMessage.

Sections

All methods are divided into sections for easier understanding of the purpose of each method. To call any method, we first need to specify a section.

General scheme:

final result = await api./*section name*/./*method name*/(/*parameters*/);

All sections fully correspond to those in the CoinGecko API documentation itself: https://www.coingecko.com/api/documentation

Let's take a closer look at each of the sections and a set of methods in them. Each section will contain a table indicating the method, a short description of the method and the corresponding query string from the official CoinGecko website.

ping

Method name Description Query string
ping Check API server status. /ping

simple

Method name Description Query string
listPrices Get the current price of any cryptocurrencies in any other supported currencies that you need. /simple/price
listTokenPrices Get current price of tokens (using contract addresses) for a given platform in any other currency that you need. /simple/token_price/{id}
listSupportedVsCurrencies Get list of supported vs currencies. /simple/supported_vs_currencies

coins

Method name Description Query string
listCoins List all supported coins id, name and symbol. /coins/list
listCoinMarkets List all supported coins price, market cap, volume, and market related data. /coins/markets
getCoinData Get current data (name, price, market, ... including exchange tickers) for a coin. /coins/{id}
listCoinTickers Get coin tickers (paginated to 100 items). /coins/{id}/tickers
getCoinHistory Get historical data (name, price, market, stats) at a given date for a coin. /coins/{id}/history
getCoinMarketChart Get historical market data include price, market cap, and 24h volume (granularity auto). /coins/{id}/market_chart
getCoinMarketChartRanged Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto). /coins/{id}/market_chart/range
listCoinStatusUpdates Get status updates for a given coin. /coins/{id}/status_updates
getCoinOHLC Get coin's OHLC. /coins/{id}/ohlc

contract

Method name Description Query string
getContractTokenData Get coin info from contract address. /coins/{id}/contract/{contract_address}
getContractMarketChart Get historical market data include price, market cap, and 24h volume (granularity auto) from a contract address. /coins/{id}/contract/{contract_address}/market_chart
getContractMarketChartRanged Get historical market data include price, market cap, and 24h volume within a range of timestamp (granularity auto) from a contract address. /coins/{id}/contract/{contract_address}/market_chart/range

categories

Method name Description Query string
listCategoriesShort List all categories. /coins/categories/list
listCategories List all categories with market data. /coins/categories

nfts

Method name Description Query string
listNfts Get all supported NFTs with id, contract address, name, asset platform id and symbol. /nfts/list
getDataById Get all the NFT data (name, floor price, 24 hr volume...) based on the NFT collection id /nfts/{id}
getDataByContractAddress Get all the NFT data (name, floor price, 24 hr volume...) based on the NFT collection contract address and respective asset platform /nfts/{asset_platform_id}/contract/{contract_address}

exchanges

Method name Description Query string
listExchanges List all exchanges. /exchanges
listExchangesShort List all supported exchanges: id and name. /exchanges/list
getExchangeData Get exchange volume in BTC and top 100 tickers only. /exchanges/{id}
getExchangeTickers Get exchange tickers (paginated, 100 tickers per page). /exchanges/{id}/tickers
getExchangeVolumeChartData Get volume_chart data for a given exchange. /exchanges/{id}/volume_chart

derivatives

Method name Description Query string
listDerivatives List all derivative tickers. /derivatives
listDerivativeExchanges List all derivative exchanges. /derivatives/exchanges
getDerivativeExchange Show derivative exchange data. /derivatives/exchanges/{id}
listDerivativeExchangesShort List all derivative exchanges name and identifier. /derivatives/exchanges/list

asset_platforms

Method name Description Query string
listAssetPlatforms List all asset platforms (Blockchain networks). /asset_platforms

exchange_rates

Method name Description Query string
getBtcExchangeRates Get BTC-to-Currency exchange rates. /exchange_rates

search

Method name Description Query string
searchFor Search for coins, categories and markets listed on CoinGecko ordered by largest Market Cap first. /search

trending

Method name Description Query string
getSearchTrending Get trending search coins (Top-7) on CoinGecko in the last 24 hours. /search/trending

global

Method name Description Query string
getGlobalData Get cryptocurrency global data. /global
getGlobalDefiData Get cryptocurrency global decentralized finance(defi) data. /global/decentralized_finance_defi

companies

Method name Description Query string
getCompaniesData Get public companies data. /companies/public_treasury/{coin_id}

indexes

Method name Description Query string
listMarketIndexes List all market indexes. /indexes
getMarketIndex Get market index by market id and index id. /indexes/{market_id}/{id}
listMarketIndexesShort List market indexes id and name. /indexes/list

Full Example

final result = await api.coins.getCoinOHLC(
    id: 'bitcoin',
    vsCurrency: 'usd',
    days: 7,
);
if (!result.isError) {
    print('getCoinOHLC method returned result');
    result.data.forEach(
        (item) => print(
            '${item.timestamp}: open = ${item.open}, high = ${item.high}, low = ${item.low}, close = ${item.close}',
        ),
    );
} else {
    print('getCoinOHLC method returned error ${result.errorCode}: ${result.errorMessage}');
}

Tests

Each method is covered by a separate test using native dart testing platform dart test.

Roadmap

See the open issues for a list of proposed features and known issues.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Yegor Pelykh

E-mail: [yegor.dev@gmail.com](mailto:yegor.dev@gmail.com)

Project Link: github.com/yegor-pelykh/coingecko_api

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。