In this project you can extract current crypto market trends using the CoinMarketCap API. With this you can monitor and watch the crypto market.
- Read the official API documentation
- For the pro version, get an API Key on the Developper Portal
- Be sure to replace the API Key in sample code with your own.
Synopsis
CoinMarketCapAPI(api_key=None, [debug=False, logger=None, sandbox=False, version='v1'])
debug: set verbosity.sandbox: In case of default sandbox API key changes, see Issue #1.logger: you can give a custom logger.version: set the version in the URL, for futures version.
Methods
You have to pass to the following methods the parameters detailed in the official documentation.
| Methods and documentation | Endpoint (version) |
|---|---|
| 📄 cryptocurrency_map | /cryptocurrency/map |
| 📄 cryptocurrency_info | /cryptocurrency/info (v2) |
| 📄 cryptocurrency_listings_latest | /cryptocurrency/listings/latest |
| 📄 cryptocurrency_listings_historical | /cryptocurrency/listings/historical |
| 📄 cryptocurrency_quotes_latest | /cryptocurrency/quotes/latest (v2) |
| 📄 cryptocurrency_quotes_historical | /cryptocurrency/quotes/historical (v2) |
| 📄 cryptocurrency_marketpairs_latest | /cryptocurrency/market-pairs/latest (v2) |
| 📄 cryptocurrency_ohlcv_latest | /cryptocurrency/ohlcv/latest (v2) |
| 📄 cryptocurrency_ohlcv_historical | /cryptocurrency/ohlcv/historical (v2) |
| 📄 cryptocurrency_priceperformancestats_latest | /cryptocurrency/price-performance-stats/latest (v2) |
| 📄 cryptocurrency_categories | /cryptocurrency/categories |
| 📄 cryptocurrency_category | /cryptocurrency/category |
| 📄 cryptocurrency_airdrops | /cryptocurrency/airdrops |
| 📄 cryptocurrency_airdrop | /cryptocurrency/airdrop |
| 📄 cryptocurrency_trending_latest | /cryptocurrency/trending/latest |
| 📄 cryptocurrency_trending_mostvisited | /cryptocurrency/trending/most-visited |
| 📄 cryptocurrency_trending_gainerslosers | /cryptocurrency/trending/gainers-losers |
| 📄 exchange_map | /exchange/map |
| 📄 exchange_info | /exchange/info |
| 📄 exchange_listings_latest | /exchange/listings/latest |
| 📄 exchange_listings_historical | /exchange/listings/historical |
| 📄 exchange_quotes_latest | /exchange/quotes/latest |
| 📄 exchange_quotes_historical | /exchange/quotes/historical |
| 📄 exchange_marketpairs_latest | /exchange/market-pairs/latest |
| 📄 globalmetrics_quotes_latest | /global-metrics/quotes/latest |
| 📄 globalmetrics_quotes_historical | /global-metrics/quotes/historical |
| 📄 tools_priceconversion | /tools/price-conversion (v2) |
| 📄 tools_postman | /tools/postman |
| 📄 blockchain_statistics_latest | /blockchain/statistics/latest |
| 📄 fiat_map | /fiat/map |
| 📄 partners_flipsidecrypto_fcas_listings_latest | /partners/flipside-crypto/fcas/listings/latest |
| 📄 partners_flipsidecrypto_fcas_quotes_latest | /partners/flipside-crypto/fcas/quotes/latest |
| 📄 key_info | /key/info |
| 📄 content_posts_top | /content/posts/top |
| 📄 content_posts_latest | /content/posts/latest |
| 📄 content_posts_comments | /content/posts/comments |
| 📄 content_latest | /content/latest |
Additionnal Parameters
api_version(str): if given, will fetch the given version of the endpoint (default is equal to the given version in the CoinMarketCapAPI instance wich is actuallyv1). As mentioned in the list above, some endpoints are "v2" by default.
##CoinMarketCap API personal portfolio :
Assuming you want to get informations about bitcoin. First, read the documentation of the corresponding cryptocurrency_info endpoint. Then on your pc you can run the following python code to successfully make an api call and fetch the data via json.
local_currency = 'RUP'
local_symbol = '₹'
api_key = '______your___api__key___here_______'
headers = {'X-CMC_PRO_API_KEY': api_key}
base_url = 'https://pro-api.coinmarketcap.com'
global_url = base_url + '/v1/global-metrics/quotes/latest?convert=' + local_currency
request = requests.get(global_url, headers=headers)
results = request.json()For printing the json stucture :
print(json.dumps(results, sort_keys=True, indent=4))This will produce this output :
{
"data": {
"SHIB": {
"circulating_supply": 549063278876301.94,
"cmc_rank": 16,
"date_added": "2020-08-01T00:00:00.000Z",
"id": 5994,
"is_active": 1,
"is_fiat": 0,
"last_updated": "2023-01-15T10:52:00.000Z",
"max_supply": null,
"name": "Shiba Inu",
"num_market_pairs": 479,
"platform": {
"id": 1027,
"name": "Ethereum",
"slug": "ethereum",
"symbol": "ETH",
"token_address": "0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce"
},
"quote": {
"RUP": {
"fully_diluted_market_cap": 28475394314906.74,
"last_updated": "2023-01-15T10:53:00.000Z",
"market_cap": 26511556145837.676,
"market_cap_dominance": 0.5659,
"percent_change_1h": 0.16446258,
"percent_change_24h": -3.15290793,
"percent_change_30d": 5.22237647,
"percent_change_60d": 21.2201861,
"percent_change_7d": 6.67880658,
"percent_change_90d": 26.61817229,
"price": 0.048285065065898254,
"tvl": null,
"volume_24h": 1694991883075.3687,
"volume_change_24h": -44.0629
}
},
"self_reported_circulating_supply": null,
"self_reported_market_cap": null,
"slug": "shiba-inu",
"symbol": "SHIB",
"tags": [
"memes",
"ethereum-ecosystem",
"doggone-doggerel"
],
"total_supply": 589735030408322.8,
"tvl_ratio": null
}
},
"status": {
"credit_count": 1,
"elapsed": 26,
"error_code": 0,
"error_message": null,
"notice": null,
"timestamp": "2023-01-15T10:53:38.837Z"
}
}
you will finally your personal cryptocurrency portfolio by maintaining the csv file containing the ticker symbol and amount of the cryptocurrencies owned by you. In my Cryptocurrency_Portfolio directory there is my_portfolio.csv file. with python you can read the data from csv and can get the required information of cryptos through json structure.
The final result will look like :
Apart from that, we can also generate the alert, as per the limit set by the user via maintaing csv file. The required code and its description is in Cryto_Alert_System folder.
We can also list top 100 cryptocurrencies and sort them in three ways:
- Top 100 sorted by market cap
- Top 100 sorted by 24 hour percent change
- Top 100 sorted by 24 hour volume
Here we have used the listings endpoint of the API.
The result is below:
- 4 nov 2022: Version 0.5
- Changing the default API version to
v2for some endpoints :- /v2/cryptocurrency/info
- /v2/cryptocurrency/quotes/latest
- /v2/cryptocurrency/quotes/historical
- /v2/cryptocurrency/market-pairs/latest
- /v2/cryptocurrency/ohlcv/latest
- /v2/cryptocurrency/ohlcv/historical
- /v2/cryptocurrency/price-performance-stats/latest
- /v2/tools/price-conversion
- Changing the default API version to

