A Python module to fetch cryptocurrency prices from CoinMarketCap API and forex prices from ExchangeRate API
Project description
Coinmarketcap Exchangerate API
A Python module to fetch cryptocurrency prices from CoinMarketCap API and forex prices from ExchangeRate API.
Features
- Fetch cryptocurrency prices from CoinMarketCap API
- Fetch forex prices from ExchangeRate API
- Automatic detection of cryptocurrency vs forex tickers
- Support for API keys via environment variables or direct assignment
- Easy to use and integrate into your projects
Installation
pip install coinmarketcap-exchangerate
Usage
Basic Usage
from coinmarketcap_exchangerate import PriceFetcher
# Initialize the fetcher
fetcher = PriceFetcher()
# Provide tickers as a list
tickers = ['BTC', 'ETH', 'EUR', 'JPY', 'DOT']
# Fetch prices
prices = fetcher.fetch_prices(tickers)
# Print results
for ticker, price in prices:
print(f"{ticker}: {name}: {price}")
Using API Keys
You can provide API keys in two ways:
Method 1: Environment Variables (.env file)
Create a .env file in your project root:
CMC_API_KEY=your_coinmarketcap_api_key
ER_API_KEY=your_exchangerate_api_key
Then use as:
import os
from dotenv import load_dotenv
from coinmarketcap_exchangerate import PriceFetcher
# Load environment variables
load_dotenv()
cmc_api_key = os.getenv('CMC_API_KEY')
er_api_key = os.getenv('ER_API_KEY')
fetcher = PriceFetcher(cmc_api_key, er_api_key)
prices = fetcher.fetch_prices(['BTC', 'EUR'])
Method 2: Direct Assignment - not recommended
from coinmarketcap_exchangerate import PriceFetcher
# Provide API key as variable
cmc_api_key = 'your api key'
er_api_key = 'your api key'
fetcher = PriceFetcher(cmc_api_key, er_api_key)
prices = fetcher.fetch_prices(['BTC', 'EUR'])
Without API Keys (Default)
If no API keys are provided, the module will use:
- CoinMarketCap sandbox API (with limited requests)
- Default ExchangeRate API endpoint
from coinmarketcap_exchangerate import PriceFetcher
fetcher = PriceFetcher()
prices = fetcher.fetch_prices(['BTC', 'EUR'])
Return Format
The fetch_prices() method returns a list of tuples in the format:
[
('EUR', 'Euro', 0.980),
('JPY', 'Japanese Yen', 0.005),
('BTC', 'Bitcoin', 78000.0),
('ETH', 'Ethereum', 3500.0),
('DOT', 'Polkadot', 7.5)
]
Each tuple contains the ticker symbol, currency name and its price in USD.
Requirements
- Python 3.10+
- requests
API Documentation
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coinmarketcap_exchangerate-1.0.0.tar.gz.
File metadata
- Download URL: coinmarketcap_exchangerate-1.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51029419f8fb4588841a0772bc47584bf14ef5cbc125e38365b7c95925ab44f5
|
|
| MD5 |
0e30e24d130f58d702f75f73a68089f6
|
|
| BLAKE2b-256 |
5483610fdf5000964382a3b1f15ed2997c670151c5afb6bad404df7412561c15
|
File details
Details for the file coinmarketcap_exchangerate-1.0.0-py3-none-any.whl.
File metadata
- Download URL: coinmarketcap_exchangerate-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bc63f60858790941747c8ffd56b82ba3aff32dc9de6646b6cc672ea3a92e678
|
|
| MD5 |
6b8d101082d89e4204951af42367ef2f
|
|
| BLAKE2b-256 |
59cdb4c256e01bf4c4afa94c39fd7eb667831282edc2d132b2d33d714226861e
|