Merge branch 'feature/remove_unused_validators' into feature/check_comma_string

This commit is contained in:
montezdesousa
2024-02-12 13:47:02 +00:00
31 changed files with 422 additions and 134 deletions

View File

@@ -24,6 +24,7 @@ class HistoricalDividendsQueryParams(QueryParams):
)
@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def upper_symbol(cls, v: str) -> str:
"""Convert symbol to uppercase."""
return v.upper()

View File

@@ -21,9 +21,9 @@ class WorldNewsQueryParams(QueryParams):
"""World News Query."""
limit: NonNegativeInt = Field(
default=20,
default=2500,
description=QUERY_DESCRIPTIONS.get("limit", "")
+ " Here its the no. of articles to return.",
+ " The number of articles to return.",
)
start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date", "")
@@ -38,7 +38,7 @@ class WorldNewsQueryParams(QueryParams):
"""Populate start date if empty."""
if not v:
now = datetime.now().date()
v = now - relativedelta(years=1)
v = now - relativedelta(weeks=2)
return v
@field_validator("end_date", mode="before")
@@ -55,11 +55,11 @@ class WorldNewsData(Data):
date: datetime = Field(
description=DATA_DESCRIPTIONS.get("date", "")
+ " Here it is the published date of the news."
+ " The published date of the article."
)
title: str = Field(description="Title of the news.")
title: str = Field(description="Title of the article.")
images: Optional[List[Dict[str, str]]] = Field(
default=None, description="Images associated with the news."
default=None, description="Images associated with the article."
)
text: Optional[str] = Field(default=None, description="Text/body of the news.")
url: Optional[str] = Field(default=None, description="URL of the news.")
text: Optional[str] = Field(default=None, description="Text/body of the article.")
url: Optional[str] = Field(default=None, description="URL to the article.")

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

@@ -76,6 +76,7 @@ def headers():
"source": "bloomberg.com",
"start_date": None,
"end_date": None,
"offset": 0,
}
),
],

View File

@@ -75,6 +75,7 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
"source": "bloomberg.com",
"start_date": None,
"end_date": None,
"offset": 0,
}
),
],

View File

@@ -14,7 +14,13 @@ from openbb_core.app.router import Router
router = Router(prefix="/cftc")
@router.command(model="COTSearch")
@router.command(
model="COTSearch",
exclude_auto_examples=True,
examples=[
'obb.regulators.cftc.cot_search(query="gold")',
],
)
async def cot_search(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -28,12 +34,22 @@ async def cot_search(
return await OBBject.from_query(Query(**locals()))
@router.command(model="COT")
@router.command(
model="COT",
exclude_auto_examples=True,
examples=[
'obb.regulators.cftc.cot(series_id="GC=F").to_df()',
"#### Enter the report ID by the Nasdaq Data Link Code. ####",
'obb.regulators.cftc.cot(series_id="088691").to_df()',
"### Get the report for futures only. ####",
'obb.regulators.cftc.cot(series_id="088691", data_type="F").to_df()',
],
)
async def cot(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Commitment of Traders Reports. Lookup Commitment of Traders Reports by series ID."""
"""Commitment of Traders Reports."""
return await OBBject.from_query(Query(**locals()))

View File

@@ -14,51 +14,94 @@ from openbb_core.app.router import Router
router = Router(prefix="/sec")
@router.command(model="CikMap")
@router.command(
model="CikMap",
exclude_auto_examples=True,
examples=[
'obb.regulators.sec.cik_map(symbol="MSFT").results.cik',
" 0000789019",
],
)
async def cik_map(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get the CIK number corresponding to a ticker symbol."""
"""Map a ticker symbol to a CIK number."""
return await OBBject.from_query(Query(**locals()))
@router.command(model="InstitutionsSearch")
@router.command(
model="InstitutionsSearch",
exclude_auto_examples=True,
examples=[
'obb.regulators.sec.institutions_search(query="blackstone real estate").to_df()'
],
)
async def institutions_search(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Look up institutions regulated by the SEC."""
"""Search SEC-regulated institutions by name and return a list of results with CIK numbers."""
return await OBBject.from_query(Query(**locals()))
@router.command(model="SchemaFiles")
@router.command(
model="SchemaFiles",
exclude_auto_examples=True,
examples=[
"data = obb.regulators.sec.schema_files()",
"data.files[0]",
" https://xbrl.fasb.org/us-gaap/",
"#### The directory structure can be navigated by constructing a URL from the 'results' list. ####",
"url = data.files[0]+data.files[-1]",
"#### The URL base will always be the 0 position in the list, feed the URL back in as a parameter. ####",
"obb.regulators.sec.schema_files(url=url).results.files",
" ['https://xbrl.fasb.org/us-gaap/2024/'",
" 'USGAAP2024FileList.xml'",
" 'dis/'",
" 'dqcrules/'",
" 'ebp/'",
" 'elts/'",
" 'entire/'",
" 'meta/'",
" 'stm/'",
" 'us-gaap-2024.zip']",
],
)
async def schema_files(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get lists of SEC XML schema files by year."""
"""A tool for navigating the directory of SEC XML schema files by year."""
return await OBBject.from_query(Query(**locals()))
@router.command(model="SymbolMap")
@router.command(
model="SymbolMap",
exclude_auto_examples=True,
examples=['obb.regulators.sec.symbol_map("0000789019").results.symbol', " MSFT"],
)
async def symbol_map(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get the ticker symbol corresponding to a company's CIK."""
"""Map a CIK number to a ticker symbol, leading 0s can be omitted or included."""
return await OBBject.from_query(Query(**locals()))
@router.command(model="RssLitigation")
@router.command(
model="RssLitigation",
exclude_auto_examples=True,
examples=['obb.regulators.sec.rss_litigation().to_dict("records")[0]'],
)
async def rss_litigation(
cc: CommandContext,
provider_choices: ProviderChoices,
@@ -69,12 +112,18 @@ async def rss_litigation(
return await OBBject.from_query(Query(**locals()))
@router.command(model="SicSearch")
@router.command(
model="SicSearch",
exclude_auto_examples=True,
examples=[
'obb.regulators.sec.sic_search("real estate investment trusts").results',
],
)
async def sic_search(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Search for Industry Titles, Reporting Office, and SIC Codes."""
"""Search for Industry Titles, Reporting Office, and SIC Codes. An empty query string returns all results."""
return await OBBject.from_query(Query(**locals()))

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(

View File

@@ -32,7 +32,7 @@ class ROUTER_regulators_sec(Container):
provider: Optional[Literal["sec"]] = None,
**kwargs
) -> OBBject:
"""Get the CIK number corresponding to a ticker symbol.
"""Map a ticker symbol to a CIK number.
Parameters
----------
@@ -65,7 +65,8 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.cik_map(symbol="AAPL")
>>> obb.regulators.sec.cik_map(symbol="MSFT").results.cik
>>> 0000789019
""" # noqa: E501
return self._run(
@@ -94,7 +95,7 @@ class ROUTER_regulators_sec(Container):
provider: Optional[Literal["sec"]] = None,
**kwargs
) -> OBBject:
"""Look up institutions regulated by the SEC.
"""Search SEC-regulated institutions by name and return a list of results with CIK numbers.
Parameters
----------
@@ -131,7 +132,7 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.institutions_search(query="AAPL", use_cache=True)
>>> obb.regulators.sec.institutions_search(query="blackstone real estate").to_df()
""" # noqa: E501
return self._run(
@@ -191,7 +192,7 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.rss_litigation()
>>> obb.regulators.sec.rss_litigation().to_dict("records")[0]
""" # noqa: E501
return self._run(
@@ -218,7 +219,7 @@ class ROUTER_regulators_sec(Container):
provider: Optional[Literal["sec"]] = None,
**kwargs
) -> OBBject:
"""Get lists of SEC XML schema files by year.
"""A tool for navigating the directory of SEC XML schema files by year.
Parameters
----------
@@ -255,7 +256,23 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.schema_files(query="AAPL", use_cache=True)
>>> data = obb.regulators.sec.schema_files()
>>> data.files[0]
>>> https://xbrl.fasb.org/us-gaap/
>>> #### The directory structure can be navigated by constructing a URL from the 'results' list. ####
>>> url = data.files[0]+data.files[-1]
>>> #### The URL base will always be the 0 position in the list, feed the URL back in as a parameter. ####
>>> obb.regulators.sec.schema_files(url=url).results.files
>>> ['https://xbrl.fasb.org/us-gaap/2024/',
>>> 'USGAAP2024FileList.xml'
>>> 'dis/'
>>> 'dqcrules/'
>>> 'ebp/'
>>> 'elts/'
>>> 'entire/'
>>> 'meta/'
>>> 'stm/'
>>> 'us-gaap-2024.zip']
""" # noqa: E501
return self._run(
@@ -285,7 +302,7 @@ class ROUTER_regulators_sec(Container):
provider: Optional[Literal["sec"]] = None,
**kwargs
) -> OBBject:
"""Search for Industry Titles, Reporting Office, and SIC Codes.
"""Search for Industry Titles, Reporting Office, and SIC Codes. An empty query string returns all results.
Parameters
----------
@@ -324,7 +341,7 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.sic_search(query="AAPL", use_cache=True)
>>> obb.regulators.sec.sic_search("real estate investment trusts").results
""" # noqa: E501
return self._run(
@@ -354,7 +371,7 @@ class ROUTER_regulators_sec(Container):
provider: Optional[Literal["sec"]] = None,
**kwargs
) -> OBBject:
"""Get the ticker symbol corresponding to a company's CIK.
"""Map a CIK number to a ticker symbol, leading 0s can be omitted or included.
Parameters
----------
@@ -389,7 +406,8 @@ class ROUTER_regulators_sec(Container):
Example
-------
>>> from openbb import obb
>>> obb.regulators.sec.symbol_map(query="AAPL", use_cache=True)
>>> obb.regulators.sec.symbol_map("0000789019").results.symbol
>>> MSFT
""" # noqa: E501
return self._run(

View File

@@ -1,5 +1,7 @@
"""Benzinga World News Model."""
# pylint: disable=unused-argument
import math
from datetime import (
date as dateType,
@@ -97,21 +99,31 @@ class BenzingaWorldNewsData(WorldNewsData):
)
@field_validator("date", "updated", mode="before", check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
@classmethod
def date_validate(cls, v):
"""Return the date as a datetime object."""
return datetime.strptime(v, "%a, %d %b %Y %H:%M:%S %z")
@field_validator("stocks", "channels", "tags", mode="before", check_fields=False)
def list_validate(cls, v): # pylint: disable=E0213
@classmethod
def list_validate(cls, v):
"""Return the list as a string."""
return ",".join(
[item.get("name", None) for item in v if item.get("name", None)]
)
v = ",".join([item.get("name", None) for item in v if item.get("name", None)])
return v if v != "" else None
@field_validator("id", mode="before", check_fields=False)
def id_validate(cls, v): # pylint: disable=E0213
"""Return the id as a string."""
return str(v)
@field_validator(
"id", "text", "teaser", "title", "author", mode="before", check_fields=False
)
@classmethod
def id_validate(cls, v):
"""Return the a string if the field is not empty."""
return str(v) if v else None
@field_validator("images", mode="before", check_fields=False)
@classmethod
def empty_list(cls, v):
"""Return None instead of []"""
return None if v == [] else v
class BenzingaWorldNewsFetcher(
@@ -132,7 +144,7 @@ class BenzingaWorldNewsFetcher(
query: BenzingaWorldNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[dict]:
) -> List[Dict]:
"""Extract the data."""
token = credentials.get("benzinga_api_key") if credentials else ""
base_url = "https://api.benzinga.com/api/v2/news"
@@ -151,11 +163,10 @@ class BenzingaWorldNewsFetcher(
return data[: query.limit]
# pylint: disable=unused-argument
@staticmethod
def transform_data(
query: BenzingaWorldNewsQueryParams,
data: List[dict],
data: List[Dict],
**kwargs: Any,
) -> List[BenzingaWorldNewsData]:
"""Transform the data."""

View File

@@ -21,7 +21,7 @@ def vcr_config():
@pytest.mark.record_http
def test_benzinga_world_news_fetcher(credentials=test_credentials):
params = {}
params = {"limit": 20}
fetcher = BenzingaWorldNewsFetcher()
result = fetcher.test(params, credentials)

View File

@@ -1,5 +1,6 @@
"""Biztoc World News Model."""
import warnings
from datetime import datetime, timedelta
from typing import Any, Dict, List, Literal, Optional
@@ -9,10 +10,11 @@ from openbb_core.provider.standard_models.world_news import (
WorldNewsData,
WorldNewsQueryParams,
)
from openbb_core.provider.utils.helpers import filter_by_dates
from pandas import to_datetime
from pydantic import Field, field_validator
_warn = warnings.warn
class BiztocWorldNewsQueryParams(WorldNewsQueryParams):
"""Biztoc World News Query."""
@@ -37,7 +39,12 @@ class BiztocWorldNewsQueryParams(WorldNewsQueryParams):
class BiztocWorldNewsData(WorldNewsData):
"""Biztoc World News Data."""
__alias_dict__ = {"date": "created", "text": "body", "site": "domain"}
__alias_dict__ = {
"date": "created",
"text": "body",
"site": "domain",
"images": "img",
}
images: Optional[Dict[str, str]] = Field(
description="Images for the article.", alias="images", default=None
@@ -69,6 +76,8 @@ class BiztocWorldNewsFetcher(
@staticmethod
def transform_query(params: Dict[str, Any]) -> BiztocWorldNewsQueryParams:
"""Transform the query."""
if params.get("start_date") or params.get("end_date"):
_warn("start_date and end_date are not supported for this endpoint.")
return BiztocWorldNewsQueryParams(**params)
@staticmethod
@@ -96,7 +105,7 @@ class BiztocWorldNewsFetcher(
hours=times[item["created"]]
)
return data
return sorted(data, key=lambda x: x["created"], reverse=True)
# pylint: disable=unused-argument
@staticmethod
@@ -104,5 +113,4 @@ class BiztocWorldNewsFetcher(
query: BiztocWorldNewsQueryParams, data: List[Dict], **kwargs: Any
) -> List[BiztocWorldNewsData]:
"""Transform the data to the standard format."""
modeled_data = [BiztocWorldNewsData.model_validate(d) for d in data]
return filter_by_dates(modeled_data, query.start_date, query.end_date)
return [BiztocWorldNewsData.model_validate(d) for d in data[: query.limit]]

View File

@@ -1,6 +1,7 @@
"""FMP World News Model."""
import math
import warnings
from datetime import datetime
from typing import Any, Dict, List, Optional
@@ -9,9 +10,11 @@ from openbb_core.provider.standard_models.world_news import (
WorldNewsData,
WorldNewsQueryParams,
)
from openbb_core.provider.utils.helpers import amake_requests, filter_by_dates
from openbb_core.provider.utils.helpers import amake_requests
from pydantic import Field, field_validator
_warn = warnings.warn
class FMPWorldNewsQueryParams(WorldNewsQueryParams):
"""FMP World News Query.
@@ -32,6 +35,13 @@ class FMPWorldNewsData(WorldNewsData):
"""Return the date as a datetime object."""
return datetime.strptime(v, "%Y-%m-%dT%H:%M:%S.%fZ")
@field_validator("images", mode="before", check_fields=False)
def images_validate(cls, v): # pylint: disable=E0213
"""Conform the response to a list."""
if isinstance(v, str):
return [{"o": v}]
return v if isinstance(v, List[Dict]) else None
class FMPWorldNewsFetcher(
Fetcher[
@@ -44,6 +54,8 @@ class FMPWorldNewsFetcher(
@staticmethod
def transform_query(params: Dict[str, Any]) -> FMPWorldNewsQueryParams:
"""Transform the query params."""
if params.get("start_date") or params.get("end_date"):
_warn("start_date and end_date are not supported for this endpoint.")
return FMPWorldNewsQueryParams(**params)
@staticmethod
@@ -62,7 +74,6 @@ class FMPWorldNewsFetcher(
f"{base_url}/general_news?page={page}&apikey={api_key}"
for page in range(pages)
]
response = await amake_requests(urls, **kwargs)
data = sorted(response, key=lambda x: x["publishedDate"], reverse=True)
@@ -74,9 +85,4 @@ class FMPWorldNewsFetcher(
query: FMPWorldNewsQueryParams, data: List[Dict], **kwargs: Any
) -> List[FMPWorldNewsData]:
"""Return the transformed data."""
for d in data:
if isinstance(d["image"], str):
d["image"] = [{"url": d["image"]}]
modeled_data = [FMPWorldNewsData.model_validate(d) for d in data]
return filter_by_dates(modeled_data, query.start_date, query.end_date)
return [FMPWorldNewsData.model_validate(d) for d in data]

View File

@@ -1,5 +1,6 @@
"""Intrinio World News Model."""
import warnings
from datetime import datetime
from typing import Any, Dict, List, Optional
@@ -8,10 +9,11 @@ from openbb_core.provider.standard_models.world_news import (
WorldNewsData,
WorldNewsQueryParams,
)
from openbb_core.provider.utils.helpers import filter_by_dates
from openbb_intrinio.utils.helpers import get_data_many
from pydantic import Field, field_validator
_warn = warnings.warn
class IntrinioWorldNewsQueryParams(WorldNewsQueryParams):
"""Intrinio World News Query.
@@ -47,6 +49,8 @@ class IntrinioWorldNewsFetcher(
@staticmethod
def transform_query(params: Dict[str, Any]) -> IntrinioWorldNewsQueryParams:
"""Transform the query params."""
if params.get("start_date") or params.get("end_date"):
_warn("start_date and end_date are not supported for this endpoint.")
return IntrinioWorldNewsQueryParams(**params)
@staticmethod
@@ -69,5 +73,4 @@ class IntrinioWorldNewsFetcher(
query: IntrinioWorldNewsQueryParams, data: List[Dict], **kwargs: Any
) -> List[IntrinioWorldNewsData]:
"""Return the transformed data."""
modeled_data = [IntrinioWorldNewsData.model_validate(d) for d in data]
return filter_by_dates(modeled_data, query.start_date, query.end_date)
return [IntrinioWorldNewsData.model_validate(d) for d in data]

View File

@@ -9,7 +9,7 @@ interactions:
Connection:
- keep-alive
method: GET
uri: https://api-v2.intrinio.com/companies/news?api_key=MOCK_API_KEY&page_size=20
uri: https://api-v2.intrinio.com/companies/news?page_size=2500&api_key=MOCK_API_KEY
response:
body:
string: !!binary |

View File

@@ -9,11 +9,10 @@ from openbb_core.provider.standard_models.world_news import (
WorldNewsData,
WorldNewsQueryParams,
)
from openbb_core.provider.utils.helpers import filter_by_dates, get_querystring
from openbb_core.provider.utils.helpers import get_querystring
from openbb_tiingo.utils.helpers import get_data_many
from pydantic import Field, field_validator
from ..utils.helpers import get_data_many
class TiingoWorldNewsQueryParams(WorldNewsQueryParams):
"""Tiingo World News Query.
@@ -21,6 +20,13 @@ class TiingoWorldNewsQueryParams(WorldNewsQueryParams):
Source: https://www.tiingo.com/documentation/news
"""
__alias_dict__ = {
"start_date": "startDate",
"end_date": "endDate",
}
offset: Optional[int] = Field(
default=0, description="Page offset, used in conjunction with limit."
)
source: Optional[str] = Field(
default=None, description="A comma-separated list of the domains requested."
)
@@ -95,5 +101,4 @@ class TiingoWorldNewsFetcher(
query: TiingoWorldNewsQueryParams, data: List[Dict], **kwargs: Any
) -> List[TiingoWorldNewsData]:
"""Return the transformed data."""
modeled_data = [TiingoWorldNewsData.model_validate(d) for d in data]
return filter_by_dates(modeled_data, query.start_date, query.end_date)
return [TiingoWorldNewsData.model_validate(d) for d in data]

View File

@@ -9,7 +9,7 @@ interactions:
Connection:
- keep-alive
method: GET
uri: https://api.tiingo.com/tiingo/news?limit=20&token=MOCK_TOKEN
uri: https://api.tiingo.com/tiingo/news?limit=20&offset=0&token=MOCK_TOKEN
response:
body:
string: "[{\"id\":59591461,\"publishedDate\":\"2023-11-16T08:38:56Z\",\"title\":\"How

View File

@@ -48,7 +48,7 @@ def test_tiingo_company_news_fetcher(credentials=test_credentials):
@pytest.mark.record_http
def test_tiingo_world_news_fetcher(credentials=test_credentials):
params = {}
params = {"limit": 20}
fetcher = TiingoWorldNewsFetcher()
result = fetcher.test(params, credentials)