[Enhancement] Add function examples to router. (#6042)

* options router

* fixedincome router

* futures router

* missing comma

* static assets

* futures router

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
Danglewood
2024-02-12 05:11:55 -08:00
committed by GitHub
parent 39888269b3
commit b867fc56de
15 changed files with 233 additions and 64 deletions

View File

@@ -14,23 +14,41 @@ router = Router(prefix="/futures")
# pylint: disable=unused-argument
@router.command(model="FuturesHistorical")
@router.command(
model="FuturesHistorical",
exclude_auto_examples=True,
examples=[
'obb.derivatives.futures.historical("ES", provider="yfinance")',
'#### Enter expiration dates as "YYYY-MM" ####',
'obb.derivatives.futures.historical("ES", provider="yfinance", expiration="2025-12")',
"#### Enter multiple symbols as a list. ####",
'obb.derivatives.futures.historical(["ES", "NQ", "ESZ24.CME", "NQZ24.CME"], provider="yfinance")',
],
)
async def historical(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Futures Historical Price. Futures historical data."""
"""Historical futures prices."""
return await OBBject.from_query(Query(**locals()))
@router.command(model="FuturesCurve")
@router.command(
model="FuturesCurve",
exclude_auto_examples=True,
examples=[
'obb.derivatives.futures.curve("NG", provider="yfinance")',
"#### Enter a date to get the term structure from a historical date. ####",
'obb.derivatives.futures.curve("NG", provider="yfinance", date="2023-01-01")',
],
)
async def curve(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Futures Historical Price. Futures historical data."""
"""Futures Term Structure, current or historical."""
return await OBBject.from_query(Query(**locals()))

View File

@@ -15,7 +15,15 @@ router = Router(prefix="/options")
# pylint: disable=unused-argument
@router.command(model="OptionsChains")
@router.command(
model="OptionsChains",
exclude_auto_examples=True,
examples=[
'chains = obb.derivatives.options.chains(symbol="AAPL", provider="intrinio").to_df()',
'#### Use the "date" parameter to get the end-of-day-data for a specific date, where supported. ####',
'eod_chains = obb.derivatives.options.chains(symbol="AAPL", date="2023-01-25", provider="intrinio").to_df()',
],
)
async def chains(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -26,7 +34,15 @@ async def chains(
return await OBBject.from_query(Query(**locals()))
@router.command(model="OptionsUnusual")
@router.command(
model="OptionsUnusual",
exclude_auto_examples=True,
examples=[
"options = obb.derivatives.options.unusual().to_df()",
'#### Use the "symbol" parameter to get the most recent activity for a specific symbol. ####',
'options = obb.derivatives.options.unusual(symbol="TSLA").to_df()',
],
)
async def unusual(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -379,11 +379,11 @@ def test_fixedincome_corporate_hqm(params, headers):
[({"start_date": "2023-01-01", "end_date": "2023-06-06", "maturity": "3m"})],
)
@pytest.mark.integration
def test_fixedincome_spreads_tmc(params, headers):
def test_fixedincome_spreads_tcm(params, headers):
params = {p: v for p, v in params.items() if v}
query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/fixedincome/spreads/tmc?{query_str}"
url = f"http://0.0.0.0:8000/api/v1/fixedincome/spreads/tcm?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
@@ -403,11 +403,11 @@ def test_fixedincome_spreads_tmc(params, headers):
],
)
@pytest.mark.integration
def test_fixedincome_spreads_tmc_effr(params, headers):
def test_fixedincome_spreads_tcm_effr(params, headers):
params = {p: v for p, v in params.items() if v}
query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/fixedincome/spreads/tmc_effr?{query_str}"
url = f"http://0.0.0.0:8000/api/v1/fixedincome/spreads/tcm_effr?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200

View File

@@ -348,10 +348,10 @@ def test_fixedincome_corporate_hqm(params, obb):
[({"start_date": "2023-01-01", "end_date": "2023-06-06", "maturity": "3m"})],
)
@pytest.mark.integration
def test_fixedincome_spreads_tmc(params, obb):
def test_fixedincome_spreads_tcm(params, obb):
params = {p: v for p, v in params.items() if v}
result = obb.fixedincome.spreads.tmc(**params)
result = obb.fixedincome.spreads.tcm(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
@@ -371,10 +371,10 @@ def test_fixedincome_spreads_tmc(params, obb):
],
)
@pytest.mark.integration
def test_fixedincome_spreads_tmc_effr(params, obb):
def test_fixedincome_spreads_tcm_effr(params, obb):
params = {p: v for p, v in params.items() if v}
result = obb.fixedincome.spreads.tmc_effr(**params)
result = obb.fixedincome.spreads.tcm_effr(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0

View File

@@ -15,7 +15,13 @@ router = Router(prefix="/corporate")
# pylint: disable=unused-argument
@router.command(model="ICEBofA")
@router.command(
model="ICEBofA",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.corporate.ice_bofa(index_type="yield_to_worst")',
],
)
async def ice_bofa(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -33,7 +39,13 @@ async def ice_bofa(
return await OBBject.from_query(Query(**locals()))
@router.command(model="MoodyCorporateBondIndex")
@router.command(
model="MoodyCorporateBondIndex",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.corporate.moody(index_type="baa")',
],
)
async def moody(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -50,7 +62,11 @@ async def moody(
return await OBBject.from_query(Query(**locals()))
@router.command(model="HighQualityMarketCorporateBond")
@router.command(
model="HighQualityMarketCorporateBond",
exclude_auto_examples=True,
examples=['obb.fixedincome.corporate.hqm(yield_curve="par")'],
)
async def hqm(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -67,7 +83,13 @@ async def hqm(
return await OBBject.from_query(Query(**locals()))
@router.command(model="SpotRate")
@router.command(
model="SpotRate",
exclude_auto_examples=True,
examples=[
"obb.fixedincome.corporate.spot_rates(maturity=[10,20,30,50])",
],
)
async def spot_rates(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -84,7 +106,13 @@ async def spot_rates(
return await OBBject.from_query(Query(**locals()))
@router.command(model="CommercialPaper")
@router.command(
model="CommercialPaper",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.corporate.commercial_paper(maturity="15d")',
],
)
async def commercial_paper(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -24,7 +24,13 @@ router.include_router(government_router)
router.include_router(corporate_router)
@router.command(model="SOFR")
@router.command(
model="SOFR",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.fixedincome.sofr(period="overnight")',
],
)
async def sofr(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -15,7 +15,13 @@ router = Router(prefix="/government")
# pylint: disable=unused-argument
@router.command(model="USYieldCurve")
@router.command(
model="USYieldCurve",
exclude_auto_examples=True,
examples=[
"obb.fixedincome.government.us_yield_curve(inflation_adjusted=True)",
],
)
async def us_yield_curve(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -26,7 +32,13 @@ async def us_yield_curve(
return await OBBject.from_query(Query(**locals()))
@router.command(model="EUYieldCurve")
@router.command(
model="EUYieldCurve",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.government.eu_yield_curve(yield_curve_type="spot_rate")',
],
)
async def eu_yield_curve(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -56,7 +68,13 @@ async def eu_yield_curve(
return await OBBject.from_query(Query(**locals()))
@router.command(model="TreasuryRates")
@router.command(
model="TreasuryRates",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.government.treasury_rates(provider="federal_reserve")',
],
)
async def treasury_rates(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -67,7 +85,14 @@ async def treasury_rates(
return await OBBject.from_query(Query(**locals()))
@router.command(model="TreasuryAuctions")
@router.command(
model="TreasuryAuctions",
exclude_auto_examples=True,
examples=[
"obb.fixedincome.government.treasury_auctions("
+ 'security_type="Bill", start_date="2022-01-01", end_date="2023-01-01',
],
)
async def treasury_auctions(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -78,7 +103,13 @@ async def treasury_auctions(
return await OBBject.from_query(Query(**locals()))
@router.command(model="TreasuryPrices")
@router.command(
model="TreasuryPrices",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.government.treasury_prices(date="2019-02-05")',
],
)
async def treasury_prices(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -15,7 +15,13 @@ router = Router(prefix="/rate")
# pylint: disable=unused-argument
@router.command(model="AMERIBOR")
@router.command(
model="AMERIBOR",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.ameribor(parameter="30_day_ma").to_df()',
],
)
async def ameribor(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -31,7 +37,13 @@ async def ameribor(
return await OBBject.from_query(Query(**locals()))
@router.command(model="SONIA")
@router.command(
model="SONIA",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.sonia(parameter="total_nominal_value")',
],
)
async def sonia(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -47,7 +59,13 @@ async def sonia(
return await OBBject.from_query(Query(**locals()))
@router.command(model="IORB")
@router.command(
model="IORB",
exclude_auto_examples=True,
examples=[
"obb.fixedincome.rate.iorb()",
],
)
async def iorb(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -63,7 +81,13 @@ async def iorb(
return await OBBject.from_query(Query(**locals()))
@router.command(model="FEDFUNDS")
@router.command(
model="FEDFUNDS",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.effr(parameter="daily", provider="fred").to_df()',
],
)
async def effr(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -79,7 +103,13 @@ async def effr(
return await OBBject.from_query(Query(**locals()))
@router.command(model="PROJECTIONS")
@router.command(
model="PROJECTIONS",
exclude_auto_examples=True,
examples=[
"obb.fixedincome.rate.effr_forecast(long_run=True)",
],
)
async def effr_forecast(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -96,7 +126,13 @@ async def effr_forecast(
return await OBBject.from_query(Query(**locals()))
@router.command(model="ESTR")
@router.command(
model="ESTR",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.estr(parameter="number_of_active_banks")',
],
)
async def estr(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -113,7 +149,13 @@ async def estr(
return await OBBject.from_query(Query(**locals()))
@router.command(model="EuropeanCentralBankInterestRates")
@router.command(
model="EuropeanCentralBankInterestRates",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.ecb(interest_rate_type="refinancing")',
],
)
async def ecb(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -132,7 +174,13 @@ async def ecb(
return await OBBject.from_query(Query(**locals()))
@router.command(model="DiscountWindowPrimaryCreditRate")
@router.command(
model="DiscountWindowPrimaryCreditRate",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.rate.dpcredit(start_date="2023-02-01", end_date="2023-05-01").to_df()',
],
)
async def dpcredit(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -15,8 +15,14 @@ router = Router(prefix="/spreads")
# pylint: disable=unused-argument
@router.command(model="TreasuryConstantMaturity")
async def tmc(
@router.command(
model="TreasuryConstantMaturity",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.fixedincome.spreads.tcm(maturity="2y")',
],
)
async def tcm(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
@@ -32,8 +38,14 @@ async def tmc(
return await OBBject.from_query(Query(**locals()))
@router.command(model="SelectedTreasuryConstantMaturity")
async def tmc_effr(
@router.command(
model="SelectedTreasuryConstantMaturity",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.fixedincome.spreads.tcm_effr(maturity="10y")',
],
)
async def tcm_effr(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
@@ -49,7 +61,13 @@ async def tmc_effr(
return await OBBject.from_query(Query(**locals()))
@router.command(model="SelectedTreasuryBill")
@router.command(
model="SelectedTreasuryBill",
exclude_auto_examples=True,
examples=[
'obb.fixedincome.fixedincome.spreads.treasury_effr(maturity="6m")',
],
)
async def treasury_effr(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -149,7 +149,9 @@ class ROUTER_derivatives_options(Container):
Example
-------
>>> from openbb import obb
>>> obb.derivatives.options.chains(symbol="AAPL")
>>> chains = obb.derivatives.options.chains(symbol="AAPL", provider="intrinio").to_df()
>>> #### Use the "date" parameter to get the end-of-day-data for a specific date, where supported. ####
>>> eod_chains = obb.derivatives.options.chains(symbol="AAPL", date="2023-01-25", provider="intrinio").to_df()
""" # noqa: E501
return self._run(
@@ -232,7 +234,9 @@ class ROUTER_derivatives_options(Container):
Example
-------
>>> from openbb import obb
>>> obb.derivatives.options.unusual()
>>> options = obb.derivatives.options.unusual().to_df()
>>> #### Use the "symbol" parameter to get the most recent activity for a specific symbol. ####
>>> options = obb.derivatives.options.unusual(symbol="TSLA").to_df()
""" # noqa: E501
return self._run(

View File

@@ -111,7 +111,7 @@ class ROUTER_fixedincome(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.sofr()
>>> obb.fixedincome.fixedincome.sofr(period="overnight")
""" # noqa: E501
return self._run(

View File

@@ -101,7 +101,7 @@ class ROUTER_fixedincome_corporate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.corporate.commercial_paper(maturity="30d", category="financial", grade="aa")
>>> obb.fixedincome.corporate.commercial_paper(maturity="15d")
""" # noqa: E501
return self._run(
@@ -184,7 +184,7 @@ class ROUTER_fixedincome_corporate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.corporate.hqm(yield_curve="spot")
>>> obb.fixedincome.corporate.hqm(yield_curve="par")
""" # noqa: E501
return self._run(
@@ -277,7 +277,7 @@ class ROUTER_fixedincome_corporate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.corporate.ice_bofa(index_type="yield")
>>> obb.fixedincome.corporate.ice_bofa(index_type="yield_to_worst")
""" # noqa: E501
return self._run(
@@ -364,7 +364,7 @@ class ROUTER_fixedincome_corporate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.corporate.moody(index_type="aaa")
>>> obb.fixedincome.corporate.moody(index_type="baa")
""" # noqa: E501
return self._run(
@@ -454,7 +454,7 @@ class ROUTER_fixedincome_corporate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.corporate.spot_rates(maturity=[10.0], category=['spot_rate'])
>>> obb.fixedincome.corporate.spot_rates(maturity=[10,20,30,50])
""" # noqa: E501
return self._run(

View File

@@ -97,7 +97,7 @@ class ROUTER_fixedincome_government(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.government.treasury_rates()
>>> obb.fixedincome.government.treasury_rates(provider="federal_reserve")
""" # noqa: E501
return self._run(
@@ -167,7 +167,7 @@ class ROUTER_fixedincome_government(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.government.us_yield_curve(inflation_adjusted=False)
>>> obb.fixedincome.government.us_yield_curve(inflation_adjusted=True)
""" # noqa: E501
return self._run(

View File

@@ -88,7 +88,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.ameribor()
>>> obb.fixedincome.rate.ameribor(parameter="30_day_ma").to_df()
""" # noqa: E501
return self._run(
@@ -168,7 +168,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.dpcredit()
>>> obb.fixedincome.rate.dpcredit(start_date="2023-02-01", end_date="2023-05-01").to_df()
""" # noqa: E501
return self._run(
@@ -254,7 +254,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.ecb(interest_rate_type="lending")
>>> obb.fixedincome.rate.ecb(interest_rate_type="refinancing")
""" # noqa: E501
return self._run(
@@ -334,7 +334,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.effr()
>>> obb.fixedincome.rate.effr(parameter="daily", provider="fred").to_df()
""" # noqa: E501
return self._run(
@@ -408,7 +408,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.effr_forecast()
>>> obb.fixedincome.rate.effr_forecast(long_run=True)
""" # noqa: E501
return self._run(
@@ -485,7 +485,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.estr()
>>> obb.fixedincome.rate.estr(parameter="number_of_active_banks")
""" # noqa: E501
return self._run(
@@ -641,7 +641,7 @@ class ROUTER_fixedincome_rate(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.rate.sonia()
>>> obb.fixedincome.rate.sonia(parameter="total_nominal_value")
""" # noqa: E501
return self._run(

View File

@@ -13,8 +13,8 @@ from typing_extensions import Annotated
class ROUTER_fixedincome_spreads(Container):
"""/fixedincome/spreads
tmc
tmc_effr
tcm
tcm_effr
treasury_effr
"""
@@ -22,7 +22,7 @@ class ROUTER_fixedincome_spreads(Container):
return self.__doc__ or ""
@validate
def tmc(
def tcm(
self,
start_date: Annotated[
Union[datetime.date, None, str],
@@ -88,11 +88,11 @@ class ROUTER_fixedincome_spreads(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.spreads.tmc(maturity="3m")
>>> obb.fixedincome.fixedincome.spreads.tcm(maturity="2y")
""" # noqa: E501
return self._run(
"/fixedincome/spreads/tmc",
"/fixedincome/spreads/tcm",
**filter_inputs(
provider_choices={
"provider": provider,
@@ -107,7 +107,7 @@ class ROUTER_fixedincome_spreads(Container):
)
@validate
def tmc_effr(
def tcm_effr(
self,
start_date: Annotated[
Union[datetime.date, None, str],
@@ -173,11 +173,11 @@ class ROUTER_fixedincome_spreads(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.spreads.tmc_effr(maturity="10y")
>>> obb.fixedincome.fixedincome.spreads.tcm_effr(maturity="10y")
""" # noqa: E501
return self._run(
"/fixedincome/spreads/tmc_effr",
"/fixedincome/spreads/tcm_effr",
**filter_inputs(
provider_choices={
"provider": provider,
@@ -259,7 +259,7 @@ class ROUTER_fixedincome_spreads(Container):
Example
-------
>>> from openbb import obb
>>> obb.fixedincome.spreads.treasury_effr(maturity="3m")
>>> obb.fixedincome.fixedincome.spreads.treasury_effr(maturity="6m")
""" # noqa: E501
return self._run(