-
Notifications
You must be signed in to change notification settings - Fork 5.2k
feat: Add CoinGecko provider for real-time cryptocurrency data #7185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vishwamartur
wants to merge
4
commits into
OpenBB-finance:develop
Choose a base branch
from
vishwamartur:feature/coingecko-provider
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
204ebba
feat: Add CoinGecko provider for real-time cryptocurrency data
vishwamartur 73a38d1
fix: Address linting issues in CoinGecko provider
vishwamartur eae8fb3
fix: Improve test robustness for CI environment
vishwamartur 0fb3ad8
Merge branch 'develop' into feature/coingecko-provider
vishwamartur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
openbb_platform/core/openbb_core/provider/standard_models/crypto_price.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Crypto Real-time Price Standard Model.""" | ||
|
||
from datetime import datetime | ||
from typing import List, Optional, Set, Union | ||
|
||
from openbb_core.provider.abstract.data import Data | ||
from openbb_core.provider.abstract.query_params import QueryParams | ||
from openbb_core.provider.utils.descriptions import ( | ||
DATA_DESCRIPTIONS, | ||
QUERY_DESCRIPTIONS, | ||
) | ||
from pydantic import Field, field_validator | ||
|
||
|
||
class CryptoPriceQueryParams(QueryParams): | ||
"""Crypto Real-time Price Query.""" | ||
|
||
symbol: str = Field( | ||
description=QUERY_DESCRIPTIONS.get("symbol", "") | ||
+ " Can use coin IDs (bitcoin, ethereum) or symbols (btc, eth). Multiple symbols supported." | ||
) | ||
|
||
@field_validator("symbol", mode="before", check_fields=False) | ||
@classmethod | ||
def validate_symbol(cls, v: Union[str, List[str], Set[str]]): | ||
"""Convert field to lowercase for coin IDs.""" | ||
if isinstance(v, str): | ||
return v.lower().strip() | ||
return ",".join([symbol.lower().strip() for symbol in list(v)]) | ||
|
||
|
||
class CryptoPriceData(Data): | ||
"""Crypto Real-time Price Data.""" | ||
|
||
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", "") + " (Crypto)") | ||
name: Optional[str] = Field( | ||
default=None, description="Name of the cryptocurrency." | ||
) | ||
price: float = Field( | ||
description="Current price of the cryptocurrency.", | ||
json_schema_extra={"x-unit_measurement": "currency"}, | ||
) | ||
market_cap: Optional[float] = Field( | ||
default=None, | ||
description="Market capitalization.", | ||
json_schema_extra={"x-unit_measurement": "currency"}, | ||
) | ||
market_cap_rank: Optional[int] = Field( | ||
default=None, | ||
description="Market cap rank.", | ||
) | ||
volume_24h: Optional[float] = Field( | ||
default=None, | ||
description="24-hour trading volume.", | ||
json_schema_extra={"x-unit_measurement": "currency"}, | ||
) | ||
change_24h: Optional[float] = Field( | ||
default=None, | ||
description="24-hour price change in percentage.", | ||
json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100}, | ||
) | ||
last_updated: Optional[datetime] = Field( | ||
default=None, | ||
description="Last updated timestamp.", | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# OpenBB CoinGecko Provider | ||
|
||
This extension integrates the [CoinGecko](https://www.coingecko.com) data provider into the OpenBB Platform, providing comprehensive real-time and historical cryptocurrency data. | ||
|
||
## Installation | ||
|
||
To install the extension: | ||
|
||
```bash | ||
pip install openbb-coingecko | ||
``` | ||
|
||
## Coverage | ||
|
||
The following endpoints are covered by this extension: | ||
|
||
- `obb.crypto.price.historical` - Historical cryptocurrency price data | ||
- `obb.crypto.price.quote` - Real-time cryptocurrency prices | ||
- `obb.crypto.search` - Search for cryptocurrencies | ||
|
||
## Features | ||
|
||
### Real-time Data | ||
- Current cryptocurrency prices | ||
- Market capitalization data | ||
- 24-hour trading volume | ||
- 24-hour price changes | ||
- Last updated timestamps | ||
|
||
### Historical Data | ||
- Historical price charts | ||
- Market cap history | ||
- Volume data over time | ||
- Flexible date ranges | ||
- Multiple interval options | ||
|
||
### Search Functionality | ||
- Search cryptocurrencies by name or symbol | ||
- Get comprehensive coin information | ||
- Access to CoinGecko coin IDs for API calls | ||
|
||
## API Key Setup | ||
|
||
While CoinGecko offers a free tier, we recommend using an API key for production use: | ||
|
||
1. Visit [CoinGecko API Pricing](https://www.coingecko.com/en/api/pricing) | ||
2. Sign up for a Pro API plan | ||
3. Visit your [Developer Dashboard](https://www.coingecko.com/en/developers/dashboard) | ||
4. Copy your API key | ||
5. Add it to your OpenBB credentials as `coingecko_api_key` | ||
|
||
## Usage Examples | ||
|
||
### Real-time Prices | ||
|
||
```python | ||
from openbb import obb | ||
|
||
# Get current Bitcoin price | ||
result = obb.crypto.price.quote(symbol="bitcoin", provider="coingecko") | ||
|
||
# Get multiple cryptocurrencies with market data | ||
result = obb.crypto.price.quote( | ||
symbol="bitcoin,ethereum,cardano", | ||
vs_currency="usd", | ||
include_market_cap=True, | ||
include_24hr_vol=True, | ||
include_24hr_change=True, | ||
provider="coingecko" | ||
) | ||
``` | ||
|
||
### Historical Data | ||
|
||
```python | ||
# Get Bitcoin historical data for the last 30 days | ||
result = obb.crypto.price.historical( | ||
symbol="bitcoin", | ||
interval="30d", | ||
vs_currency="usd", | ||
provider="coingecko" | ||
) | ||
|
||
# Get historical data with specific date range | ||
result = obb.crypto.price.historical( | ||
symbol="ethereum", | ||
start_date="2024-01-01", | ||
end_date="2024-01-31", | ||
vs_currency="eur", | ||
provider="coingecko" | ||
) | ||
``` | ||
|
||
### Search Cryptocurrencies | ||
|
||
```python | ||
# Search for cryptocurrencies | ||
result = obb.crypto.search(query="bitcoin", provider="coingecko") | ||
|
||
# Get all available cryptocurrencies | ||
result = obb.crypto.search(provider="coingecko") | ||
``` | ||
|
||
## Supported Currencies | ||
|
||
The provider supports pricing in multiple fiat and cryptocurrency currencies: | ||
|
||
**Fiat:** USD, EUR, JPY, GBP, AUD, CAD, CHF, CNY, HKD, INR, KRW, MXN, NOK, NZD, PHP, PLN, RUB, SEK, SGD, THB, TRY, TWD, ZAR | ||
|
||
**Crypto:** BTC, ETH, LTC, BCH, BNB, EOS, XRP, XLM, LINK, DOT, YFI | ||
|
||
## Rate Limits | ||
|
||
- **Free API:** 10-50 calls/minute | ||
- **Pro API:** 500+ calls/minute (depending on plan) | ||
|
||
For production use, we recommend upgrading to a Pro plan to avoid rate limiting. | ||
|
||
## Data Sources | ||
|
||
CoinGecko aggregates data from over 400+ exchanges worldwide, providing comprehensive and reliable cryptocurrency market data. The platform tracks 10,000+ different crypto-assets and is one of the most trusted sources in the cryptocurrency space. | ||
|
||
## Support | ||
|
||
For issues related to this provider, please visit the [OpenBB Platform repository](https://github.com/OpenBB-finance/OpenBB). | ||
|
||
For CoinGecko API-specific questions, refer to the [CoinGecko API Documentation](https://docs.coingecko.com/reference/introduction). |
34 changes: 34 additions & 0 deletions
34
openbb_platform/providers/coingecko/openbb_coingecko/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""CoinGecko Provider Module.""" | ||
|
||
from openbb_core.provider.abstract.provider import Provider | ||
from openbb_coingecko.models.crypto_historical import CoinGeckoCryptoHistoricalFetcher | ||
from openbb_coingecko.models.crypto_price import CoinGeckoCryptoPriceFetcher | ||
from openbb_coingecko.models.crypto_search import CoinGeckoCryptoSearchFetcher | ||
|
||
coingecko_provider = Provider( | ||
name="coingecko", | ||
website="https://www.coingecko.com", | ||
description=( | ||
"CoinGecko is the world's largest independent cryptocurrency data aggregator " | ||
"with over 10,000+ different crypto-assets tracked across more than 400+ " | ||
"exchanges worldwide. CoinGecko provides real-time pricing, market data, " | ||
"and comprehensive cryptocurrency information." | ||
), | ||
credentials=["coingecko_api_key"], | ||
fetcher_dict={ | ||
"CryptoHistorical": CoinGeckoCryptoHistoricalFetcher, | ||
"CryptoPrice": CoinGeckoCryptoPriceFetcher, | ||
"CryptoSearch": CoinGeckoCryptoSearchFetcher, | ||
}, | ||
repr_name="CoinGecko", | ||
instructions=( | ||
"To get a CoinGecko API key:\n" | ||
"1. Visit https://www.coingecko.com/en/api/pricing\n" | ||
"2. Sign up for a Pro API plan (required for API key access)\n" | ||
"3. Once subscribed, visit your developer dashboard at " | ||
"https://www.coingecko.com/en/developers/dashboard\n" | ||
"4. Copy your API key and add it to your OpenBB credentials as 'coingecko_api_key'\n\n" | ||
"Note: CoinGecko offers a free tier with limited requests, " | ||
"but an API key is recommended for production use." | ||
), | ||
) |
1 change: 1 addition & 0 deletions
1
openbb_platform/providers/coingecko/openbb_coingecko/models/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""CoinGecko provider models.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"coingecko_api_key" -> "api_key"
Entering like this creates a duplication of the provider name.
OpenBBError:
[Error] -> Missing credential 'coingecko_coingecko_api_key'. Check https://www.coingecko.com to get it. Known more about how to set provider credentials at https://docs.openbb.co/platform/getting_started/api_keys.