mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[Enhancement] - Improve crypto router docs and examples (#6048)
* crypto search add validation for '-'-separated pairs * set default query value to None * improve /crypto description with custom examples * improve /crypto/price/historical description with custom examples * updated static for crypto menu * ignore line too long * linting --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
@@ -17,12 +17,15 @@ router.include_router(price_router)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@router.command(model="CryptoSearch")
|
||||
@router.command(
|
||||
model="CryptoSearch",
|
||||
examples=['obb.crypto.search("BTCUSD")', 'obb.crypto.search("ETH-USD")'],
|
||||
)
|
||||
async def search(
|
||||
cc: CommandContext,
|
||||
provider_choices: ProviderChoices,
|
||||
standard_params: StandardParams,
|
||||
extra_params: ExtraParams,
|
||||
) -> OBBject:
|
||||
"""Cryptocurrency Search. Search available cryptocurrency pairs."""
|
||||
"""Search available cryptocurrency pairs within a provider."""
|
||||
return await OBBject.from_query(Query(**locals()))
|
||||
|
||||
@@ -14,13 +14,21 @@ from openbb_core.app.router import Router
|
||||
router = Router(prefix="/price")
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
@router.command(model="CryptoHistorical")
|
||||
# pylint: disable=unused-argument,line-too-long
|
||||
@router.command(
|
||||
model="CryptoHistorical",
|
||||
examples=[
|
||||
'obb.crypto.price.historical("BTCUSD", start_date="2024-01-01", end_date="2024-01-31")',
|
||||
'obb.crypto.price.historical("ETH-USD", provider="yfinance", interval="1mo", start_date="2024-01-01", end_date="2024-12-31")', # noqa: E501
|
||||
'obb.crypto.price.historical("BTCUSD,ETH-USD", provider="yfinance", interval="1d", start_date="2024-01-01", end_date="2024-01-31")', # noqa: E501
|
||||
'obb.crypto.price.historical(["BTCUSD", "ETH-USD"], start_date="2024-01-01", end_date="2024-01-31")',
|
||||
],
|
||||
)
|
||||
async def historical(
|
||||
cc: CommandContext,
|
||||
provider_choices: ProviderChoices,
|
||||
standard_params: StandardParams,
|
||||
extra_params: ExtraParams,
|
||||
) -> OBBject:
|
||||
"""Cryptocurrency Historical Price. Cryptocurrency historical price data."""
|
||||
"""Get historical price data for cryptocurrency pair(s) within a provider."""
|
||||
return await OBBject.from_query(Query(**locals()))
|
||||
|
||||
@@ -35,7 +35,7 @@ class ROUTER_crypto(Container):
|
||||
provider: Optional[Literal["fmp"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject:
|
||||
"""Cryptocurrency Search. Search available cryptocurrency pairs.
|
||||
"""Search available cryptocurrency pairs within a provider.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -77,6 +77,8 @@ class ROUTER_crypto(Container):
|
||||
-------
|
||||
>>> from openbb import obb
|
||||
>>> obb.crypto.search()
|
||||
>>> obb.crypto.search("BTCUSD")
|
||||
>>> obb.crypto.search("ETH-USD")
|
||||
""" # noqa: E501
|
||||
|
||||
return self._run(
|
||||
|
||||
@@ -43,7 +43,7 @@ class ROUTER_crypto_price(Container):
|
||||
provider: Optional[Literal["fmp", "polygon", "tiingo", "yfinance"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject:
|
||||
"""Cryptocurrency Historical Price. Cryptocurrency historical price data.
|
||||
"""Get historical price data for cryptocurrency pair(s) within a provider.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -121,6 +121,10 @@ class ROUTER_crypto_price(Container):
|
||||
-------
|
||||
>>> from openbb import obb
|
||||
>>> obb.crypto.price.historical(symbol="BTCUSD")
|
||||
>>> obb.crypto.price.historical("BTCUSD", start_date="2024-01-01", end_date="2024-01-31")
|
||||
>>> obb.crypto.price.historical("ETH-USD", provider="yfinance", interval="1mo", start_date="2024-01-01", end_date="2024-12-31")
|
||||
>>> obb.crypto.price.historical("BTCUSD,ETH-USD", provider="yfinance", interval="1d", start_date="2024-01-01", end_date="2024-01-31")
|
||||
>>> obb.crypto.price.historical(["BTCUSD", "ETH-USD"], start_date="2024-01-01", end_date="2024-01-31")
|
||||
""" # noqa: E501
|
||||
|
||||
return self._run(
|
||||
|
||||
@@ -9,11 +9,21 @@ from openbb_core.provider.standard_models.crypto_search import (
|
||||
CryptoSearchQueryParams,
|
||||
)
|
||||
from openbb_fmp.utils.helpers import create_url, get_data_many
|
||||
from pydantic import Field
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
|
||||
class FMPCryptoSearchQueryParams(CryptoSearchQueryParams):
|
||||
"""FMP Crypto Search Query."""
|
||||
"""FMP Crypto Search Query.
|
||||
|
||||
Source: https://site.financialmodelingprep.com/developer/docs/cryptocurrency-historical-data-api
|
||||
"""
|
||||
|
||||
@field_validator("query", mode="after", check_fields=False)
|
||||
def validate_query(cls, v: str) -> str: # pylint: disable=no-self-argument
|
||||
"""Return the query."""
|
||||
if isinstance(v, str):
|
||||
return v.replace("-", "") if "-" in v else v
|
||||
return None
|
||||
|
||||
|
||||
class FMPCryptoSearchData(CryptoSearchData):
|
||||
@@ -49,7 +59,7 @@ class FMPCryptoSearchFetcher(
|
||||
|
||||
@staticmethod
|
||||
async def aextract_data(
|
||||
query: FMPCryptoSearchQueryParams,
|
||||
query: FMPCryptoSearchQueryParams, # pylint: disable=unused-argument
|
||||
credentials: Optional[Dict[str, str]],
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
@@ -66,7 +76,9 @@ class FMPCryptoSearchFetcher(
|
||||
|
||||
@staticmethod
|
||||
def transform_data(
|
||||
query: FMPCryptoSearchQueryParams, data: List[Dict], **kwargs: Any
|
||||
query: FMPCryptoSearchQueryParams, # pylint: disable=unused-argument
|
||||
data: List[Dict],
|
||||
**kwargs: Any,
|
||||
) -> List[FMPCryptoSearchData]:
|
||||
"""Return the transformed data."""
|
||||
cryptos = pd.DataFrame(data)
|
||||
|
||||
Reference in New Issue
Block a user