refactored SECFilings for stocks.dd.sec

This commit is contained in:
Pratyush Shukla
2023-08-02 02:20:51 +05:30
parent 4bbb18ebf1
commit da08d83943
2 changed files with 142 additions and 74 deletions

View File

@@ -1,50 +1,37 @@
"""SEC Filings fetcher."""
from datetime import (
date as dateType,
datetime,
)
from datetime import datetime
from typing import Any, Dict, List, Optional
from openbb_provider.abstract.data import Data
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.models.sec_filings import SECFilingsData, SECFilingsQueryParams
from pydantic import validator
from openbb_fmp.utils.helpers import create_url, get_data_many
from pydantic import validator
class FMPSECFilingsQueryParams(SECFilingsQueryParams):
"""FMP SEC Filings QueryParams.
"""FMP SEC Filings Query.
Source: https://site.financialmodelingprep.com/developer/docs/sec-filings-api/
Parameter
---------
symbol : str
The symbol of the company.
type : str
The type of the SEC filing form. (full list: https://www.sec.gov/forms)
page : int
The page of the results.
limit : int
The limit of the results.
"""
class FMPSECFilingsData(Data):
symbol: str
fillingDate: dateType
acceptedDate: dateType
cik: str
type: str
link: str
finalLink: str
class FMPSECFilingsData(SECFilingsData):
"""FMP SEC Filings Data."""
@validator("fillingDate", "acceptedDate", pre=True)
class Config:
fields = {
"filling_date": "fillingDate",
"accepted_date": "acceptedDate",
"final_link": "finalLink",
}
@validator("fillingDate", "acceptedDate", pre=True, check_fields=False)
def convert_date(cls, v): # pylint: disable=no-self-argument
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S").date()
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
class FMPSECFilingsFetcher(
@@ -68,6 +55,7 @@ class FMPSECFilingsFetcher(
url = create_url(
3, f"sec_filings/{query.symbol}", api_key, query, exclude=["symbol"]
)
return get_data_many(url, FMPSECFilingsData)
@staticmethod

View File

@@ -1,59 +1,139 @@
"""SEC filings data model."""
"""SEC Filings data model."""
from datetime import date as dateType
from typing import Optional
from datetime import datetime
from typing import Literal, Optional
from openbb_provider.abstract.data import Data
from openbb_provider.abstract.query_params import QueryParams
from openbb_provider.models.base import BaseSymbol
from openbb_provider.descriptions import QUERY_DESCRIPTIONS
from pydantic import Field
FORM_TYPES = Literal[
"1",
"1-A",
"1-E",
"1-K",
"1-N",
"1-SA",
"1-U",
"1-Z",
"10",
"10-D",
"10-K",
"10-M",
"10-Q",
"11-K",
"12b-25",
"13F",
"13H",
"144",
"15",
"15F",
"17-H",
"18",
"18-K",
"19b-4",
"19b-4(e)",
"19b-7",
"2-E",
"20-F",
"24F-2",
"25",
"3",
"4",
"40-F",
"5",
"6-K",
"7-M",
"8-A",
"8-K",
"8-M",
"9-M",
"ABS-15G",
"ABS-EE",
"ABS DD-15E",
"ADV",
"ADV-E",
"ADV-H",
"ADV-NR",
"ADV-W",
"ATS",
"ATS-N",
"ATS-R",
"BD",
"BD-N",
"BDW",
"C",
"CA-1",
"CB",
"CFPORTAL",
"CRS",
"CUSTODY",
"D",
"F-1",
"F-10",
"F-3",
"F-4",
"F-6",
"F-7",
"F-8",
"F-80",
"F-N",
"F-X",
"ID",
"MA",
"MA-I",
"MA-NR",
"MA-W",
"MSD",
"MSDW",
"N-14",
"N-17D-1",
"N-17f-1",
"N-17f-2",
"N-18f-1",
"N-1A",
"N-2",
"N-23c-3",
"N-27D-1",
"N-3",
"N-4",
"N-5",
"N-54A",
"N-54C",
"N-6",
"N-6EI-1",
"N-6F",
"N-8A",
"N-8B-2",
"N-8B-4",
"N-8F",
"N-CEN",
]
class SECFilingsQueryParams(QueryParams, BaseSymbol):
"""SEC Filings query model.
Parameter
---------
symbol : str
The symbol of the company.
type : str
The type of the SEC filing form. (full list: https://www.sec.gov/forms)
page : int
The page of the results.
limit : int
The limit of the results.
"""
"""SEC Filings Query."""
symbol: str
type: Optional[str] = None
page: Optional[int] = 0
limit: Optional[int] = None
type: FORM_TYPES = Field(
default="10-K", description="The type of the SEC filing form."
)
page: Optional[int] = Field(default=0, description="Page number of the results.")
limit: Optional[int] = Field(
default=100, description=QUERY_DESCRIPTIONS.get("limit", "")
)
class SECFilingsData(Data):
"""SEC filings data.
class SECFilingsData(Data, BaseSymbol):
"""SEC Filings Data."""
Returns
-------
symbol : str
The symbol of the stock.
filling_date : date
The filling date of the SEC filing.
accepted_date : date
The accepted date of the SEC filing.
cik : str
The CIK of the SEC filing.
type : str
The type of the SEC filing.
link : str
The link of the SEC filing.
final_link : str
The final link of the SEC filing.
"""
symbol: str
filling_date: dateType
accepted_date: dateType
cik: Optional[str]
type: str
link: str
final_link: str
filling_date: datetime = Field(description="The filling date of the SEC filing.")
accepted_date: datetime = Field(description="The accepted date of the SEC filing.")
cik: str = Field(description="The CIK of the SEC filing.")
type: str = Field(description="The type of the SEC filing.")
link: str = Field(description="The link of the SEC filing.")
final_link: str = Field(description="The final link of the SEC filing.")