Skip to content

Commit

Permalink
[Feature] Add SEC As Provider To equity.ownership.insider_trading (#…
Browse files Browse the repository at this point in the history
…6947)

* add sec to equity.ownership.insider_trading

* integration test params

* lint

* forgot that file in the commit

* grammar police

* alias map

* more lint

* more alias mapping

* pylint

---------

Co-authored-by: Igor Radovanovic <[email protected]>
  • Loading branch information
deeleeramone and IgorWounds authored Nov 25, 2024
1 parent 7d8202f commit bde8aba
Show file tree
Hide file tree
Showing 11 changed files with 12,345 additions and 20 deletions.
10 changes: 10 additions & 0 deletions openbb_platform/extensions/equity/integration/test_equity_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ def test_equity_fundamental_income_growth(params, headers):
"sort_by": "updated_on",
}
),
(
{
"provider": "sec",
"symbol": "AAPL",
"limit": 10,
"start_date": "2024-06-30",
"end_date": "2024-09-30",
"use_cache": True,
}
),
],
)
@pytest.mark.integration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ def test_equity_fundamental_income_growth(params, obb):
"sort_by": "updated_on",
}
),
(
{
"provider": "sec",
"symbol": "AAPL",
"limit": 10,
"start_date": "2024-06-30",
"end_date": "2024-09-30",
"use_cache": True,
}
),
],
)
@pytest.mark.integration
Expand Down
190 changes: 189 additions & 1 deletion openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -27405,6 +27405,32 @@
"optional": true,
"choices": null
}
],
"sec": [
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format. Wide date ranges can result in long download times. Recommended to use a smaller date range, default is 120 days ago.",
"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 is today.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "use_cache",
"type": "bool",
"description": "Persist the data locally for future use. Default is True. Each form submission is an individual download and the SEC limits the number of concurrent downloads. This prevents the same file from being downloaded multiple times.",
"default": true,
"optional": true,
"choices": null
}
]
},
"returns": {
Expand All @@ -27416,7 +27442,7 @@
},
{
"name": "provider",
"type": "Optional[Literal['fmp', 'intrinio']]",
"type": "Optional[Literal['fmp', 'intrinio', 'sec']]",
"description": "Provider name."
},
{
Expand Down Expand Up @@ -27682,6 +27708,168 @@
"optional": true,
"choices": null
}
],
"sec": [
{
"name": "company_name",
"type": "str",
"description": "Name of the company.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "form",
"type": "Union[int, str]",
"description": "Form type.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "director",
"type": "bool",
"description": "Whether the owner is a director.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "officer",
"type": "bool",
"description": "Whether the owner is an officer.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "ten_percent_owner",
"type": "bool",
"description": "Whether the owner is a 10% owner.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "other",
"type": "bool",
"description": "Whether the owner is classified as other.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "other_text",
"type": "str",
"description": "Text for other classification.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "transaction_timeliness",
"type": "str",
"description": "Timeliness of the transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "ownership_type",
"type": "str",
"description": "Type of ownership, direct or indirect.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "nature_of_ownership",
"type": "str",
"description": "Nature of the ownership.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "exercise_date",
"type": "date",
"description": "Date of exercise.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "expiration_date",
"type": "date",
"description": "Date of expiration for the derivative.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "deemed_execution_date",
"type": "date",
"description": "Deemed execution date.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "underlying_security_title",
"type": "str",
"description": "Title of the underlying security.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "underlying_security_shares",
"type": "float",
"description": "Number of underlying shares associated with the derivative.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "underlying_security_value",
"type": "float",
"description": "Value of the underlying security.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "conversion_exercise_price",
"type": "float",
"description": "Price of conversion or exercise of the securities.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "transaction_value",
"type": "float",
"description": "Total value of the transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "value_owned",
"type": "float",
"description": "Value of the securities owned after the transaction.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "footnote",
"type": "str",
"description": "Footnote for the transaction.",
"default": null,
"optional": true,
"choices": null
}
]
},
"model": "InsiderTrading"
Expand Down
65 changes: 47 additions & 18 deletions openbb_platform/openbb/package/equity_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def insider_trading(
int, OpenBBField(description="The number of data entries to return.")
] = 500,
provider: Annotated[
Optional[Literal["fmp", "intrinio"]],
Optional[Literal["fmp", "intrinio", "sec"]],
OpenBBField(
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio."
description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, sec."
),
] = None,
**kwargs
Expand All @@ -170,25 +170,28 @@ def insider_trading(
Symbol to get data for.
limit : int
The number of data entries to return.
provider : Optional[Literal['fmp', 'intrinio']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio.
provider : Optional[Literal['fmp', 'intrinio', 'sec']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fmp, intrinio, sec.
transaction_type : Optional[Literal['award', 'conversion', 'return', 'expire_short', 'in_kind', 'gift', 'expire_long', 'discretionary', 'other', 'small', 'exempt', 'otm', 'purchase', 'sale', 'tender', 'will', 'itm', 'trust']]
Type of the transaction. (provider: fmp)
start_date : Optional[datetime.date]
Start date of the data, in YYYY-MM-DD format. (provider: intrinio)
Start date of the data, in YYYY-MM-DD format. (provider: intrinio);
Start date of the data, in YYYY-MM-DD format. Wide date ranges can result in long download times. Recommended to use a smaller date range, default is 120 days ago. (provider: sec)
end_date : Optional[datetime.date]
End date of the data, in YYYY-MM-DD format. (provider: intrinio)
End date of the data, in YYYY-MM-DD format. (provider: intrinio, sec)
ownership_type : Optional[Literal['D', 'I']]
Type of ownership. (provider: intrinio)
sort_by : Optional[Literal['filing_date', 'updated_on']]
Field to sort by. (provider: intrinio)
use_cache : bool
Persist the data locally for future use. Default is True. Each form submission is an individual download and the SEC limits the number of concurrent downloads. This prevents the same file from being downloaded multiple times. (provider: sec)
Returns
-------
OBBject
results : List[InsiderTrading]
Serializable results.
provider : Optional[Literal['fmp', 'intrinio']]
provider : Optional[Literal['fmp', 'intrinio', 'sec']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
Expand Down Expand Up @@ -230,33 +233,59 @@ def insider_trading(
form_type : Optional[str]
Form type of the insider trading. (provider: fmp)
company_name : Optional[str]
Name of the company. (provider: intrinio)
Name of the company. (provider: intrinio, sec)
conversion_exercise_price : Optional[float]
Conversion/Exercise price of the shares. (provider: intrinio)
Conversion/Exercise price of the shares. (provider: intrinio);
Price of conversion or exercise of the securities. (provider: sec)
deemed_execution_date : Optional[date]
Deemed execution date of the trade. (provider: intrinio)
Deemed execution date of the trade. (provider: intrinio);
Deemed execution date. (provider: sec)
exercise_date : Optional[date]
Exercise date of the trade. (provider: intrinio)
Exercise date of the trade. (provider: intrinio);
Date of exercise. (provider: sec)
expiration_date : Optional[date]
Expiration date of the derivative. (provider: intrinio)
Expiration date of the derivative. (provider: intrinio);
Date of expiration for the derivative. (provider: sec)
underlying_security_title : Optional[str]
Name of the underlying non-derivative security related to this derivative transaction. (provider: intrinio)
Name of the underlying non-derivative security related to this derivative transaction. (provider: intrinio);
Title of the underlying security. (provider: sec)
underlying_shares : Optional[Union[int, float]]
Number of underlying shares related to this derivative transaction. (provider: intrinio)
nature_of_ownership : Optional[str]
Nature of ownership of the insider trading. (provider: intrinio)
Nature of ownership of the insider trading. (provider: intrinio);
Nature of the ownership. (provider: sec)
director : Optional[bool]
Whether the owner is a director. (provider: intrinio)
Whether the owner is a director. (provider: intrinio, sec)
officer : Optional[bool]
Whether the owner is an officer. (provider: intrinio)
Whether the owner is an officer. (provider: intrinio, sec)
ten_percent_owner : Optional[bool]
Whether the owner is a 10% owner. (provider: intrinio)
Whether the owner is a 10% owner. (provider: intrinio, sec)
other_relation : Optional[bool]
Whether the owner is having another relation. (provider: intrinio)
derivative_transaction : Optional[bool]
Whether the owner is having a derivative transaction. (provider: intrinio)
report_line_number : Optional[int]
Report line number of the insider trading. (provider: intrinio)
form : Optional[Union[int, str]]
Form type. (provider: sec)
other : Optional[bool]
Whether the owner is classified as other. (provider: sec)
other_text : Optional[str]
Text for other classification. (provider: sec)
transaction_timeliness : Optional[str]
Timeliness of the transaction. (provider: sec)
ownership_type : Optional[str]
Type of ownership, direct or indirect. (provider: sec)
underlying_security_shares : Optional[float]
Number of underlying shares associated with the derivative. (provider: sec)
underlying_security_value : Optional[float]
Value of the underlying security. (provider: sec)
transaction_value : Optional[float]
Total value of the transaction. (provider: sec)
value_owned : Optional[float]
Value of the securities owned after the transaction. (provider: sec)
footnote : Optional[str]
Footnote for the transaction. (provider: sec)
Examples
--------
Expand All @@ -272,7 +301,7 @@ def insider_trading(
"provider": self._get_provider(
provider,
"equity.ownership.insider_trading",
("fmp", "intrinio"),
("fmp", "intrinio", "sec"),
)
},
standard_params={
Expand Down
2 changes: 2 additions & 0 deletions openbb_platform/providers/sec/openbb_sec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from openbb_sec.models.equity_search import SecEquitySearchFetcher
from openbb_sec.models.etf_holdings import SecEtfHoldingsFetcher
from openbb_sec.models.form_13FHR import SecForm13FHRFetcher
from openbb_sec.models.insider_trading import SecInsiderTradingFetcher
from openbb_sec.models.institutions_search import SecInstitutionsSearchFetcher
from openbb_sec.models.latest_financial_reports import SecLatestFinancialReportsFetcher
from openbb_sec.models.rss_litigation import SecRssLitigationFetcher
Expand All @@ -29,6 +30,7 @@
"EtfHoldings": SecEtfHoldingsFetcher,
"Filings": SecCompanyFilingsFetcher,
"Form13FHR": SecForm13FHRFetcher,
"InsiderTrading": SecInsiderTradingFetcher,
"InstitutionsSearch": SecInstitutionsSearchFetcher,
"LatestFinancialReports": SecLatestFinancialReportsFetcher,
"RssLitigation": SecRssLitigationFetcher,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def transform_data(
filings = filings[filings["reportDate"] >= query.start_date]
if query.end_date:
filings = filings[filings["reportDate"] <= query.end_date]
base_url = f"https://www.sec.gov/Archives/edgar/data/{query.cik}/"
base_url = f"https://www.sec.gov/Archives/edgar/data/{str(int(query.cik))}/" # type: ignore
filings["primaryDocumentUrl"] = (
base_url
+ filings["accessionNumber"].str.replace("-", "")
Expand Down
Loading

0 comments on commit bde8aba

Please sign in to comment.