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]try to add fmp senate trading data api #6957

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
758e5ea
[Feature] Add Government Trades
joshuaBri Nov 20, 2024
3d0525c
Merge remote-tracking branch 'origin/develop' into feature/government…
joshuaBri Nov 22, 2024
a721fc7
[BugFix] Supplement the missing files
joshuaBri Nov 25, 2024
0525f76
Merge branch 'develop' into feature/government_trades
joshuaBri Nov 27, 2024
36c3f93
[Enhancement] Fix branch goverment_trades
joshuaBri Nov 29, 2024
fe4e02f
Merge branch 'develop' into feature/government_trades
deeleeramone Dec 1, 2024
1b5cf11
Merge remote-tracking branch 'origin/develop' into feature/government…
joshuaBri Dec 2, 2024
4ab4d89
Merge remote-tracking branch 'origin/feature/government_trades' into …
joshuaBri Dec 2, 2024
8344207
[Enhancement] Fix branch government_trades
joshuaBri Dec 2, 2024
060f1d0
Merge branch 'develop' into feature/government_trades
deeleeramone Dec 5, 2024
abd5f2a
Capture test cassettes.
deeleeramone Dec 6, 2024
cb91bee
[Enhancement] Fix branch government_trades
joshuaBri Dec 6, 2024
04b4f8f
Merge remote-tracking branch 'origin/develop' into feature/government…
joshuaBri Dec 6, 2024
5b5899e
Merge remote-tracking branch 'origin/feature/government_trades' into …
joshuaBri Dec 6, 2024
68e4231
Merge branch 'develop' into feature/government_trades
deeleeramone Dec 6, 2024
017e0e6
some style things and prevent page from exceeding 30
deeleeramone Dec 7, 2024
b306124
black
deeleeramone Dec 7, 2024
f8a9885
linter again
deeleeramone Dec 7, 2024
6235290
else None instead of Other
deeleeramone Dec 7, 2024
c7758dc
Merge branch 'develop' into feature/government_trades
deeleeramone Dec 10, 2024
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,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(
deeleeramone marked this conversation as resolved.
Show resolved Hide resolved
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
Loading