Skip to content
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

[Feature] Add Primary Dealer Positioning To Economy #6566

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Primray Dealer Positioning Standard Model."""

from datetime import (
date as dateType,
)
from typing import Optional

from pydantic import Field

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,
)


class PrimaryDealerPositioningQueryParams(QueryParams):
"""Primary Dealer Positioning Query."""

start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date", "")
)
end_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("end_date", "")
)


class PrimaryDealerPositioningData(Data):
"""Primary Dealer Positioning Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
25 changes: 25 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,28 @@ def test_economy_survey_manufacturing_outlook_texas(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"provider": "federal_reserve",
"start_date": "2024-01-01",
"end_date": "2024-04-01",
"category": "cmbs",
}
),
],
)
@pytest.mark.integration
def test_economy_primary_dealer_positioning(params, headers):
"""Test the economy primary dealer positioning endpoint"""
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/economy/primary_dealer_positioning?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,27 @@ def test_economy_survey_manufacturing_outlook_texas(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"provider": "federal_reserve",
"start_date": "2024-01-01",
"end_date": "2024-04-01",
"category": "cmbs",
}
),
],
)
@pytest.mark.integration
def test_economy_primary_dealer_positioning(params, obb):
"""Test the economy primary dealer positioning endpoint"""
params = {p: v for p, v in params.items() if v}

result = obb.economy.primary_dealer_positioning(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,25 @@ async def retail_prices(
) -> OBBject:
"""Get retail prices for common items."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="PrimaryDealerPositioning",
examples=[
APIEx(parameters={"provider": "federal_reserve"}),
APIEx(
parameters={
"category": "abs",
"provider": "federal_reserve",
},
),
],
)
async def primary_dealer_positioning(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get Primary dealer positioning statistics."""
return await OBBject.from_query(Query(**locals()))
135 changes: 135 additions & 0 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -7596,6 +7596,141 @@
},
"model": "RetailPrices"
},
"/economy/primary_dealer_positioning": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get Primary dealer positioning statistics.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.primary_dealer_positioning(provider='federal_reserve')\nobb.economy.primary_dealer_positioning(category=abs, provider='federal_reserve')\n```\n\n",
"parameters": {
"standard": [
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "end_date",
"type": "Union[date, str]",
"description": "End date of the data, in YYYY-MM-DD format.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "provider",
"type": "Literal['federal_reserve']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: federal_reserve.",
"default": null,
"optional": true
}
],
"federal_reserve": [
{
"name": "category",
"type": "Literal['treasuries', 'bills', 'coupons', 'notes', 'tips', 'mbs', 'cmbs', 'municipal', 'corporate', 'commercial_paper', 'corporate_ig', 'corporate_junk', 'abs']",
"description": "The category of asset to return, defaults to 'treasuries'.",
"default": "treasuries",
"optional": true,
"choices": [
"treasuries",
"bills",
"coupons",
"notes",
"tips",
"mbs",
"cmbs",
"municipal",
"corporate",
"commercial_paper",
"corporate_ig",
"corporate_junk",
"abs"
]
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[PrimaryDealerPositioning]",
"description": "Serializable results."
},
{
"name": "provider",
"type": "Optional[Literal['federal_reserve']]",
"description": "Provider name."
},
{
"name": "warnings",
"type": "Optional[List[Warning_]]",
"description": "List of warnings."
},
{
"name": "chart",
"type": "Optional[Chart]",
"description": "Chart object."
},
{
"name": "extra",
"type": "Dict[str, Any]",
"description": "Extra info."
}
]
},
"data": {
"standard": [
{
"name": "date",
"type": "date",
"description": "The date of the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "symbol",
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": "",
"optional": false,
"choices": null
}
],
"federal_reserve": [
{
"name": "value",
"type": "int",
"description": "The reported value of the net position (long - short), in millions of $USD.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "name",
"type": "str",
"description": "Short name for the series.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "title",
"type": "str",
"description": "Title of the series.",
"default": "",
"optional": false,
"choices": null
}
]
},
"model": "PrimaryDealerPositioning"
},
"/equity/calendar/ipo": {
"deprecated": {
"flag": null,
Expand Down
86 changes: 86 additions & 0 deletions openbb_platform/openbb/package/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ROUTER_economy(Container):
indicators
long_term_interest_rate
money_measures
primary_dealer_positioning
retail_prices
risk_premium
share_price_index
Expand Down Expand Up @@ -1759,6 +1760,91 @@ def money_measures(
)
)

@exception_handler
@validate
def primary_dealer_positioning(
self,
start_date: Annotated[
Union[datetime.date, None, str],
OpenBBField(description="Start date of the data, in YYYY-MM-DD format."),
] = None,
end_date: Annotated[
Union[datetime.date, None, str],
OpenBBField(description="End date of the data, in YYYY-MM-DD format."),
] = None,
provider: Annotated[
Optional[Literal["federal_reserve"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: federal_reserve."
),
] = None,
**kwargs
) -> OBBject:
"""Get Primary dealer positioning statistics.

Parameters
----------
start_date : Union[datetime.date, None, str]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None, str]
End date of the data, in YYYY-MM-DD format.
provider : Optional[Literal['federal_reserve']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: federal_reserve.
category : Literal['treasuries', 'bills', 'coupons', 'notes', 'tips', 'mbs', 'cmbs', 'municipal', 'corporate', 'commercial_paper', 'corporate_ig', 'corporate_junk', 'abs']
The category of asset to return, defaults to 'treasuries'. (provider: federal_reserve)

Returns
-------
OBBject
results : List[PrimaryDealerPositioning]
Serializable results.
provider : Optional[Literal['federal_reserve']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.

PrimaryDealerPositioning
------------------------
date : date
The date of the data.
symbol : str
Symbol representing the entity requested in the data.
value : Optional[int]
The reported value of the net position (long - short), in millions of $USD. (provider: federal_reserve)
name : Optional[str]
Short name for the series. (provider: federal_reserve)
title : Optional[str]
Title of the series. (provider: federal_reserve)

Examples
--------
>>> from openbb import obb
>>> obb.economy.primary_dealer_positioning(provider='federal_reserve')
>>> obb.economy.primary_dealer_positioning(category='abs', provider='federal_reserve')
""" # noqa: E501

return self._run(
"/economy/primary_dealer_positioning",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"economy.primary_dealer_positioning",
("federal_reserve",),
)
},
standard_params={
"start_date": start_date,
"end_date": end_date,
},
extra_params=kwargs,
)
)

@exception_handler
@validate
def retail_prices(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from openbb_federal_reserve.models.overnight_bank_funding_rate import (
FederalReserveOvernightBankFundingRateFetcher,
)
from openbb_federal_reserve.models.primary_dealer_positioning import (
FederalReservePrimaryDealerPositioningFetcher,
)
from openbb_federal_reserve.models.sofr import FederalReserveSOFRFetcher
from openbb_federal_reserve.models.treasury_rates import (
FederalReserveTreasuryRatesFetcher,
Expand All @@ -25,11 +28,12 @@
description="""Access data provided by the Federal Reserve System, the Central Bank of the United States.""",
fetcher_dict={
"CentralBankHoldings": FederalReserveCentralBankHoldingsFetcher,
"TreasuryRates": FederalReserveTreasuryRatesFetcher,
"FederalFundsRate": FederalReserveFederalFundsRateFetcher,
"MoneyMeasures": FederalReserveMoneyMeasuresFetcher,
"OvernightBankFundingRate": FederalReserveOvernightBankFundingRateFetcher,
"FederalFundsRate": FederalReserveFederalFundsRateFetcher,
"PrimaryDealerPositioning": FederalReservePrimaryDealerPositioningFetcher,
"SOFR": FederalReserveSOFRFetcher,
"TreasuryRates": FederalReserveTreasuryRatesFetcher,
"YieldCurve": FederalReserveYieldCurveFetcher,
},
repr_name="Federal Reserve (FED)",
Expand Down
Loading
Loading