man-c / pycoingecko

Python wrapper for the CoinGecko API
MIT License
1.04k stars 268 forks source link

Documentation Implementation: coins/markets #79

Closed raceee closed 1 year ago

raceee commented 1 year ago

The endpoint here supports request for multiple ids to get market information specific to the requested coins see here.

I have changed the function to reflect the ability described in the documentation.

man-c commented 1 year ago

Hi and thanks for contributing! The library already allows passing ids with multiple coins as comma-separated string or list. For example,

>>> import pycoingecko
>>> cg=pycoingecko.CoinGeckoAPI()

# example with ids as list
>>> cg.get_coins_markets(ids = ["bitcoin", "ethereum"], vs_currency = "usd")
[{'id': 'bitcoin', 'symbol': 'btc', 'name': 'Bitcoin', 'image': 'https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1547033579', 'current_price': 21854, 'market_cap': 422396689021, 'market_cap_rank': 1, 'fully_diluted_valuation': 459873511471, 'total_volume': 22042137979, 'high_24h': 22000, 'low_24h': 21665, 'price_change_24h': 182.81, 'price_change_percentage_24h': 0.84354, 'market_cap_change_24h': 1253835210, 'market_cap_change_percentage_24h': 0.29772, 'circulating_supply': 19288631.0, 'total_supply': 21000000.0, 'max_supply': 21000000.0, 'ath': 69045, 'ath_change_percentage': -68.28328, 'ath_date': '2021-11-10T14:24:11.849Z', 'atl': 67.81, 'atl_change_percentage': 32194.73763, 'atl_date': '2013-07-06T00:00:00.000Z', 'roi': None, 'last_updated': '2023-02-12T12:47:10.783Z'}, 
{'id': 'ethereum', 'symbol': 'eth', 'name': 'Ethereum', 'image': 'https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880', 'current_price': 1529.1, 'market_cap': 184986405812, 'market_cap_rank': 2, 'fully_diluted_valuation': 184986405812, 'total_volume': 5149735080, 'high_24h': 1544.33, 'low_24h': 1515.37, 'price_change_24h': 11.86, 'price_change_percentage_24h': 0.78169, 'market_cap_change_24h': 705695441, 'market_cap_change_percentage_24h': 0.38295, 'circulating_supply': 120504270.432735, 'total_supply': 120504270.432735, 'max_supply': None, 'ath': 4878.26, 'ath_change_percentage': -68.5467, 'ath_date': '2021-11-10T14:24:19.604Z', 'atl': 0.432979, 'atl_change_percentage': 354276.20842, 'atl_date': '2015-10-20T00:00:00.000Z', 'roi': {'times': 92.51759865833674, 'currency': 'btc', 'percentage': 9251.759865833674}, 'last_updated': '2023-02-12T12:48:08.458Z'}]

# example with ids as comma-separated string
>>> cg.get_coins_markets(ids = "bitcoin, ethereum", vs_currency = "usd")
[{'id': 'bitcoin', 'symbol': 'btc', 'name': 'Bitcoin', 'image': 'https://assets.coingecko.com/coins/images/1/large/bitcoin.png?1547033579', 'current_price': 21850, 'market_cap': 421886370913, 'market_cap_rank': 1, 'fully_diluted_valuation': 459317034705, 'total_volume': 21872903116, 'high_24h': 22000, 'low_24h': 21665, 'price_change_24h': 154.09, 'price_change_percentage_24h': 0.71023, 'market_cap_change_24h': 3896032686, 'market_cap_change_percentage_24h': 0.93209, 'circulating_supply': 19288668.0, 'total_supply': 21000000.0, 'max_supply': 21000000.0, 'ath': 69045, 'ath_change_percentage': -68.28328, 'ath_date': '2021-11-10T14:24:11.849Z', 'atl': 67.81, 'atl_change_percentage': 32194.73763, 'atl_date': '2013-07-06T00:00:00.000Z', 'roi': None, 'last_updated': '2023-02-12T12:54:56.811Z'}, 
{'id': 'ethereum', 'symbol': 'eth', 'name': 'Ethereum', 'image': 'https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880', 'current_price': 1527.13, 'market_cap': 184399158063, 'market_cap_rank': 2, 'fully_diluted_valuation': 184399158063, 'total_volume': 5165318243, 'high_24h': 1544.33, 'low_24h': 1515.37, 'price_change_24h': 7.74, 'price_change_percentage_24h': 0.50929, 'market_cap_change_24h': 1565251288, 'market_cap_change_percentage_24h': 0.85611, 'circulating_supply': 120504270.432735, 'total_supply': 120504270.432735, 'max_supply': None, 'ath': 4878.26, 'ath_change_percentage': -68.5467, 'ath_date': '2021-11-10T14:24:19.604Z', 'atl': 0.432979, 'atl_change_percentage': 354276.20842, 'atl_date': '2015-10-20T00:00:00.000Z', 'roi': {'times': 92.45997667379818, 'currency': 'btc', 'percentage': 9245.997667379817}, 'last_updated': '2023-02-12T12:55:11.718Z'}]