Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ssl-context
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone authored Dec 11, 2024
2 parents 4f9c026 + d704de5 commit 5a65612
Show file tree
Hide file tree
Showing 12 changed files with 871 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Government Trades Standard Model."""

from datetime import date as dateType
from typing import Literal, Optional

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, NonNegativeInt, field_validator


class GovernmentTradesQueryParams(QueryParams):
"""Government Trades Query."""

symbol: Optional[str] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("symbol", "")
)
chamber: Literal["house", "senate", "all"] = Field(
default="all", description="Government Chamber."
)
limit: Optional[NonNegativeInt] = Field(
default=100, description=QUERY_DESCRIPTIONS.get("limit", "")
)

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: str):
"""Convert field to uppercase."""
return v.upper() if v else None


class GovernmentTradesData(Data):
"""Government Trades data."""

symbol: Optional[str] = Field(
default=None, description=DATA_DESCRIPTIONS.get("symbol", "")
)
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
transaction_date: Optional[dateType] = Field(
default=None, description="Date of Transaction."
)
representative: Optional[str] = Field(
default=None, description="Name of Representative."
)
33 changes: 33 additions & 0 deletions openbb_platform/extensions/equity/integration/test_equity_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2156,3 +2156,36 @@ def test_equity_discovery_latest_financial_reports(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"chamber": "all",
"symbol": "AAPL",
"provider": "fmp",
"limit": None,
}
),
(
{
"symbol": None,
"chamber": "all",
"limit": 300,
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_equity_ownership_government_trades(params, headers):
"""Test the equity ownership government trades 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/equity/ownership/government_trades?{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 @@ -2017,3 +2017,35 @@ def test_equity_discovery_latest_financial_reports(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"chamber": "all",
"symbol": "AAPL",
"provider": "fmp",
"limit": None,
}
),
(
{
"symbol": None,
"chamber": "all",
"limit": 300,
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_equity_ownership_government_trades(params, obb):
"""Test the equity ownership government trades endpoint."""
params = {p: v for p, v in params.items() if v}

result = obb.equity.ownership.government_trades(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,22 @@ async def form_13f(
their investment strategy from competitors and the public.
"""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="GovernmentTrades",
examples=[
APIEx(parameters={"symbol": "AAPL", "chamber": "all", "provider": "fmp"}),
APIEx(parameters={"limit": 500, "chamber": "all", "provider": "fmp"}),
],
)
async def government_trades(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Obtain government transaction data, including data from the Senate
and the House of Representatives.
"""
return await OBBject.from_query(Query(**locals()))
173 changes: 172 additions & 1 deletion openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "OpenBB Platform (Python)",
"description": "Investment research for everyone, anywhere.",
"core": "1.3.6",
"core": "1.3.7",
"extensions": {
"openbb_core_extension": [
"[email protected]",
Expand Down Expand Up @@ -10271,6 +10271,7 @@
"dominica",
"dominican_republic",
"east_germany",
"eastern_caribbean_currency_union",
"ecuador",
"egypt",
"el_salvador",
Expand Down Expand Up @@ -10526,6 +10527,7 @@
"dominica",
"dominican_republic",
"east_germany",
"eastern_caribbean_currency_union",
"ecuador",
"egypt",
"el_salvador",
Expand Down Expand Up @@ -28322,6 +28324,175 @@
},
"model": "Form13FHR"
},
"/equity/ownership/government_trades": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Obtain government transaction data, including data from the Senate\nand the House of Representatives.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.equity.ownership.government_trades(symbol='AAPL', chamber='all', provider='fmp')\nobb.equity.ownership.government_trades(limit=500, chamber='all', provider='fmp')\n```\n\n",
"parameters": {
"standard": [
{
"name": "symbol",
"type": "Union[str, List[str]]",
"description": "Symbol to get data for. Multiple items allowed for provider(s): fmp.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "chamber",
"type": "Literal['house', 'senate', 'all']",
"description": "Government Chamber.",
"default": "all",
"optional": true,
"choices": null
},
{
"name": "limit",
"type": "Annotated[int, Ge(ge=0)]",
"description": "The number of data entries to return.",
"default": 100,
"optional": true,
"choices": null
}
],
"fmp": []
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[GovernmentTrades]",
"description": "Serializable results."
},
{
"name": "provider",
"type": "Optional[Literal['fmp']]",
"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": "symbol",
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "date",
"type": "Union[date, str]",
"description": "The date of the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "transaction_date",
"type": "date",
"description": "Date of Transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "representative",
"type": "str",
"description": "Name of Representative.",
"default": null,
"optional": true,
"choices": null
}
],
"fmp": [
{
"name": "chamber",
"type": "Literal['house', 'senate']",
"description": "Government Chamber - House or Senate.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "owner",
"type": "str",
"description": "Ownership status (e.g., Spouse, Joint).",
"default": null,
"optional": true,
"choices": null
},
{
"name": "asset_type",
"type": "str",
"description": "Type of asset involved in the transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "asset_description",
"type": "str",
"description": "Description of the asset.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "transaction_type",
"type": "str",
"description": "Type of transaction (e.g., Sale, Purchase).",
"default": null,
"optional": true,
"choices": null
},
{
"name": "amount",
"type": "str",
"description": "Transaction amount range.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "comment",
"type": "str",
"description": "Additional comments on the transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "url",
"type": "str",
"description": "Link to the transaction document.",
"default": null,
"optional": true,
"choices": null
}
]
},
"model": "GovernmentTrades"
},
"/equity/price/quote": {
"deprecated": {
"flag": null,
Expand Down
2 changes: 2 additions & 0 deletions openbb_platform/openbb/package/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ def direction_of_trade(
"dominica",
"dominican_republic",
"east_germany",
"eastern_caribbean_currency_union",
"ecuador",
"egypt",
"el_salvador",
Expand Down Expand Up @@ -1682,6 +1683,7 @@ def direction_of_trade(
"dominica",
"dominican_republic",
"east_germany",
"eastern_caribbean_currency_union",
"ecuador",
"egypt",
"el_salvador",
Expand Down
Loading

0 comments on commit 5a65612

Please sign in to comment.