pycoingecko

repository·master·Indexed 22 days ago

https://github.com/man-c/pycoingecko

A Python wrapper for the CoinGecko API that provides access to cryptocurrency market data, prices, and other endpoints. It supports Public, Demo, and Pro API access levels and includes methods for Simple, Coins, Exchange, and NFT API endpoint groups.

Tokens
1.7K
Snippets
7
Records
9
Agent score
28%

What's inside pycoingecko

  1. How to pass parameters to API methods

    master

    When calling methods in pycoingecko, you can pass optional parameters exactly as they are named in the official CoinGecko API documentation.

    Parameter Types:

    • Lists: Use Python lists for parameters that accept multiple comma-separated values (e.g., ids=['bitcoin', 'ethereum']).
    • Booleans: Use Python bool (True, False) or str ('true', 'false') for boolean type arguments.
  2. Initialize the CoinGeckoAPI client

    master

    Depending on your API access level, initialize the CoinGeckoAPI class differently:

    • Public API (Free): No API key required.
    • Public API (with Demo Key): Use the demo_api_key parameter.
    • Pro API: Use the api_key parameter.

    Note: The demo_api_key corresponds to the x-cg-demo-api-key header in the CoinGecko API.

    from pycoingecko import CoinGeckoAPI
    
    # Public API
    cg = CoinGeckoAPI()
    
    # Public API with demo key
    cg = CoinGeckoAPI(demo_api_key='YOUR_DEMO_API_KEY')
    
    # Pro API
    cg = CoinGeckoAPI(api_key='YOUR_PRO_API_KEY')
  3. Install pycoingecko

    master

    You can install the pycoingecko wrapper via PyPI or from the source code.

    Via PyPI:

    pip install -U pycoingecko

    From source:

    git clone https://github.com/man-c/pycoingecko.git
    cd pycoingecko
    python3 setup.py install
  4. Get cryptocurrency prices with get_price()

    master

    Use get_price() to retrieve the current price of cryptocurrencies in specified currencies.

    Required parameters:

    • ids: The ID of the cryptocurrency (or a list of IDs).
    • vs_currencies: The target currency (or a list of currencies).

    Example usage with lists and optional parameters:

    # Single ID and single currency
    cg.get_price(ids='bitcoin', vs_currencies='usd')
    
    # Multiple IDs and multiple currencies using lists
    cg.get_price(ids=['bitcoin', 'litecoin', 'ethereum'], vs_currencies=['usd', 'eur'])
    
    # Including optional market data (using booleans)
    cg.get_price(ids='bitcoin', vs_currencies='usd', include_market_cap=True, include_24hr_vol=True)
  5. Reference: Simple API endpoints

    master

    The following methods are available for the /simple/ endpoint group:

    • get_price(): Get current price of cryptocurrencies.
    • get_token_price(): Get current price of tokens using contract addresses.
    • get_supported_vs_currencies(): Get list of supported vs_currencies.
    cg.get_price()
    cg.get_token_price()
    cg.get_supported_vs_currencies()
  6. Reference: Coins API endpoints

    master

    The following methods are available for the /coins/ endpoint group:

    • get_coins_list(): List all supported coins (id, name, symbol).
    • get_coin_top_gainers_losers(): [Pro API] Query top 30 coins by price gain/loss.
    • get_coins_list_new(): [Pro API] Query the latest 200 listed coins.
    • get_coins_markets(): List all supported coins with market data.
    • get_coin_by_id(): Get current data for a specific coin.
    • get_coin_ticker_by_id(): Get coin tickers (paginated).
    • get_coin_history_by_id(): Get historical data at a given date.
    • get_coin_market_chart_by_id(): Get historical market data (price, market cap, volume).
    • get_coin_market_chart_range_by_id(): Get historical market data within a timestamp range.
    • get_coin_ohlc_by_id(): Get OHLC chart data.
    • get_coin_ohlc_by_id_range(): [Pro API] Get OHLC chart within a timestamp range.
    • get_coin_circulating_supply_chart(): [Pro API] Query historical circulating supply.
    • get_coin_circulating_supply_chart_range(): [Pro API] Query historical circulating supply within a range.
    • get_coin_total_supply_chart(): [Pro API] Query historical total supply.
    • get_coin_total_supply_chart_range(): [Pro API] Query historical total supply within a range.
  7. Reference: Exchange API endpoints

    master

    The following methods are available for the /exchanges/ endpoint group:

    • get_exchanges_list(): List all exchanges.
    • get_exchanges_id_name_list(): List all supported markets id and name.
    • get_exchanges_by_id(): Get exchange volume in BTC and top 100 tickers.
    • get_exchanges_tickers_by_id(): Get exchange tickers (paginated).
    • get_exchanges_volume_chart_by_id(): Get volume chart data for an exchange.
    • get_exchanges_volume_chart_by_id_within_time_range(): [Pro API] Query historical volume chart data in BTC within a UNIX timestamp range.
    cg.get_exchanges_list()
    cg.get_exchanges_id_name_list()
    cg.get_exchanges_by_id()
    cg.get_exchanges_tickers_by_id()
    cg.get_exchanges_volume_chart_by_id()
    cg.get_exchanges_volume_chart_by_id_within_time_range()
  8. Reference: NFT API endpoints

    master

    The following methods are available for the /nfts/ endpoint group:

    • get_nfts_list(): List all supported NFT ids (paginated).
    • get_nfts_by_id(): Get current data for an NFT collection.
    • get_nfts_collection_by_asset_platform_id_and_contract_address(): Get NFT collection data via contract address.
    • get_nfts_markets(): [Pro API] Query supported NFT collections with market data.
    • get_nfts_market_chart_by_id(): [Pro API] Query historical market data for an NFT collection.
    • get_ntfs_market_chart_by_asset_platform_id_and_contract_address(): [Pro API] Query historical market data for an NFT collection via contract address.
    • get_nfts_tickers_by_id(): [Pro API] Query latest floor price and 24h volume across marketplaces.
    cg.get_nfts_list()
    cg.get_nfts_by_id()
    cg.get_nfts_collection_by_asset_platform_id_and_contract_address()
    cg.get_nfts_markets()
    cg.get_nfts_market_chart_by_id()
    cg.get_ntfs_market_chart_by_asset_platform_id_and_contract_address()
    cg.get_nfts_tickers_by_id()