mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-29 20:53:54 +00:00
refactored StockInsiderTrading for stocks.fa.ins
This commit is contained in:
@@ -1,61 +1,52 @@
|
||||
"""FMP Stock Insider Trading fetcher."""
|
||||
|
||||
|
||||
from datetime import date, 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.stock_insider_trading import (
|
||||
StockInsiderTradingData,
|
||||
StockInsiderTradingQueryParams,
|
||||
)
|
||||
from pydantic import Field
|
||||
from pydantic import validator
|
||||
|
||||
from openbb_fmp.utils.helpers import create_url, get_data_many
|
||||
|
||||
|
||||
class FMPStockInsiderTradingQueryParams(StockInsiderTradingQueryParams):
|
||||
"""FMP Stock Insider Trading query.
|
||||
"""FMP Stock Insider Trading Query.
|
||||
|
||||
Source: https://site.financialmodelingprep.com/developer/docs/#Stock-Insider-Trading
|
||||
|
||||
Parameter
|
||||
---------
|
||||
transactionType : List[TransactionTypes]
|
||||
The type of the transaction. Possible values are:
|
||||
A-Award, C-Conversion, D-Return, E-ExpireShort, F-InKind, G-Gift, H-ExpireLong
|
||||
I-Discretionary, J-Other, L-Small, M-Exempt, O-OutOfTheMoneym P-Purchase
|
||||
S-Sale, U-Tender, W-Will, X-InTheMoney, Z-Trust
|
||||
symbol : str]
|
||||
The symbol of the company.
|
||||
reportingCik : str]
|
||||
The CIK of the reporting owner.
|
||||
companyCik: str]
|
||||
The CIK of the company owner.
|
||||
page: int
|
||||
The page number to get
|
||||
"""
|
||||
|
||||
|
||||
class FMPStockInsiderTradingData(Data):
|
||||
"""FMP Stock Insider Trading data."""
|
||||
class FMPStockInsiderTradingData(StockInsiderTradingData):
|
||||
"""FMP Stock Insider Trading Data."""
|
||||
|
||||
symbol: str
|
||||
filingDate: datetime = Field(alias="filing_date")
|
||||
transactionDate: date = Field(alias="transaction_date")
|
||||
reportingCik: int = Field(alias="reporting_cik")
|
||||
transactionType: str = Field(alias="transaction_type")
|
||||
securitiesOwned: int = Field(alias="securities_owned")
|
||||
companyCik: int = Field(alias="company_cik")
|
||||
reportingName: str = Field(alias="reporting_name")
|
||||
typeOfOwner: str = Field(alias="type_of_owner")
|
||||
acquistionOrDisposition: str = Field(alias="acquistion_or_disposition")
|
||||
formType: str = Field(alias="form_type")
|
||||
securitiesTransacted: float = Field(alias="securities_transacted")
|
||||
price: float
|
||||
securityName: str = Field(alias="security_name")
|
||||
link: str
|
||||
class Config:
|
||||
fields = {
|
||||
"filing_date": "filingDate",
|
||||
"transaction_date": "transactionDate",
|
||||
"reporting_cik": "reportingCik",
|
||||
"transaction_type": "transactionType",
|
||||
"securities_owned": "securitiesOwned",
|
||||
"company_cik": "companyCik",
|
||||
"reporting_name": "reportingName",
|
||||
"type_of_owner": "typeOfOwner",
|
||||
"acquistion_or_disposition": "acquistionOrDisposition",
|
||||
"form_type": "formType",
|
||||
"securities_transacted": "securitiesTransacted",
|
||||
"security_name": "securityName",
|
||||
}
|
||||
|
||||
@validator("filingDate", pre=True, check_fields=False)
|
||||
def filing_date_validate(cls, v): # pylint: disable=E0213
|
||||
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
|
||||
|
||||
@validator("transactionDate", pre=True, check_fields=False)
|
||||
def transaction_date_validate(cls, v): # pylint: disable=E0213
|
||||
return datetime.strptime(v, "%Y-%m-%d").date()
|
||||
|
||||
|
||||
class FMPStockInsiderTradingFetcher(
|
||||
@@ -79,6 +70,7 @@ class FMPStockInsiderTradingFetcher(
|
||||
# This changes the actual type of a pydantic class, but its a quick and clean way to format properly
|
||||
query.transactionType = ",".join(query.transactionType) # type: ignore
|
||||
url = create_url(4, "insider-trading", api_key, query)
|
||||
|
||||
return get_data_many(url, FMPStockInsiderTradingData)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -2,111 +2,86 @@
|
||||
|
||||
|
||||
from datetime import date, datetime
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
from typing import List, 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 pydantic import Field
|
||||
|
||||
|
||||
class TransactionTypes(str, Enum):
|
||||
Award = "A-Award"
|
||||
Conversion = "C-Conversion"
|
||||
Return = "D-Return"
|
||||
ExpireShort = "E-ExpireShort"
|
||||
InKind = "F-InKind"
|
||||
Gift = "G-Gift"
|
||||
ExpireLong = "H-ExpireLong"
|
||||
Discretionary = "I-Discretionary"
|
||||
Other = "J-Other"
|
||||
Small = "L-Small"
|
||||
Exempt = "M-Exempt"
|
||||
OutOfTheMoney = "O-OutOfTheMoney"
|
||||
Purchase = "P-Purchase"
|
||||
Sale = "S-Sale"
|
||||
Tender = "U-Tender"
|
||||
Will = "W-Will"
|
||||
InTheMoney = "X-InTheMoney"
|
||||
Trust = "Z-Trust"
|
||||
TRANSACTION_TYPES = Literal[
|
||||
"A-Award",
|
||||
"C-Conversion",
|
||||
"D-Return",
|
||||
"E-ExpireShort",
|
||||
"F-InKind",
|
||||
"G-Gift",
|
||||
"H-ExpireLong",
|
||||
"I-Discretionary",
|
||||
"J-Other",
|
||||
"L-Small",
|
||||
"M-Exempt",
|
||||
"O-OutOfTheMoney",
|
||||
"P-Purchase",
|
||||
"S-Sale",
|
||||
"U-Tender",
|
||||
"W-Will",
|
||||
"X-InTheMoney",
|
||||
"Z-Trust",
|
||||
]
|
||||
|
||||
|
||||
class StockInsiderTradingQueryParams(QueryParams):
|
||||
"""Stock Insider Trading query.
|
||||
class StockInsiderTradingQueryParams(QueryParams, BaseSymbol):
|
||||
"""Stock Insider Trading Query."""
|
||||
|
||||
transactionType: Optional[List[TRANSACTION_TYPES]] = Field(
|
||||
default=["P-Purchase"], description="The type of the transaction."
|
||||
)
|
||||
reportingCik: Optional[int] = Field(description="The CIK of the reporting owner.")
|
||||
companyCik: Optional[int] = Field(description="The CIK of the company owner.")
|
||||
page: Optional[int] = Field(
|
||||
default=0, description="The page number of the data to fetch."
|
||||
)
|
||||
|
||||
|
||||
Parameter
|
||||
---------
|
||||
transactionType : List[TransactionTypes]
|
||||
The type of the transaction. Possible values are:
|
||||
A-Award, C-Conversion, D-Return, E-ExpireShort, F-InKind, G-Gift, H-ExpireLong
|
||||
I-Discretionary, J-Other, L-Small, M-Exempt, O-OutOfTheMoneym P-Purchase
|
||||
S-Sale, U-Tender, W-Will, X-InTheMoney, Z-Trust
|
||||
symbol : str]
|
||||
The symbol of the company.
|
||||
reportingCik : int]
|
||||
The CIK of the reporting owner.
|
||||
companyCik : int]
|
||||
The CIK of the company owner.
|
||||
page: int
|
||||
The page number to get
|
||||
"""
|
||||
class StockInsiderTradingData(Data, BaseSymbol):
|
||||
"""Stock Insider Trading Data."""
|
||||
|
||||
transactionType: List[TransactionTypes] = []
|
||||
symbol: Optional[str]
|
||||
reportingCik: Optional[int]
|
||||
companyCik: Optional[int]
|
||||
page: int = 0
|
||||
|
||||
|
||||
class StockInsiderTradingData(Data):
|
||||
"""Stock insider trading data.
|
||||
|
||||
Returns
|
||||
-------
|
||||
symbol : str
|
||||
The symbol of the asset.
|
||||
filingDate : datetime
|
||||
The filing date of the stock insider trading.
|
||||
transactionDate : date
|
||||
The transaction date of the stock insider trading.
|
||||
reportingCik : int
|
||||
The reporting CIK of the stock insider trading.
|
||||
transactionType : str
|
||||
The transaction type of the stock insider trading.
|
||||
securitiesOwned : int
|
||||
The securities owned of the stock insider trading.
|
||||
companyCik : int
|
||||
The company CIK of the stock insider trading.
|
||||
reportingName : str
|
||||
The reporting name of the stock insider trading.
|
||||
typeOfOwner : str
|
||||
The type of owner of the stock insider trading.
|
||||
acquistionOrDisposition : str
|
||||
The acquistion or disposition of the stock insider trading.
|
||||
formType : str
|
||||
The form type of the stock insider trading.
|
||||
securitiesTransacted : float
|
||||
The securities transacted of the stock insider trading.
|
||||
price : float
|
||||
The price of the stock insider trading.
|
||||
securityName : str
|
||||
The security name of the stock insider trading.
|
||||
link : str
|
||||
The link of the stock insider trading.
|
||||
"""
|
||||
|
||||
symbol: str
|
||||
filing_date: datetime
|
||||
transaction_date: date
|
||||
reporting_cik: int
|
||||
transaction_type: str
|
||||
securities_owned: int
|
||||
company_cik: int
|
||||
reporting_name: str
|
||||
type_of_owner: str
|
||||
acquistion_or_disposition: str
|
||||
form_type: str
|
||||
securities_transacted: float
|
||||
price: float
|
||||
security_name: str
|
||||
link: str
|
||||
filing_date: datetime = Field(
|
||||
description="The filing date of the stock insider trading."
|
||||
)
|
||||
transaction_date: date = Field(
|
||||
description="The transaction date of the stock insider trading."
|
||||
)
|
||||
reporting_cik: int = Field(
|
||||
description="The reporting CIK of the stock insider trading."
|
||||
)
|
||||
transaction_type: str = Field(
|
||||
description="The transaction type of the stock insider trading."
|
||||
)
|
||||
securities_owned: int = Field(
|
||||
description="The securities owned of the stock insider trading."
|
||||
)
|
||||
company_cik: int = Field(
|
||||
description="The company CIK of the stock insider trading."
|
||||
)
|
||||
reporting_name: str = Field(
|
||||
description="The reporting name of the stock insider trading."
|
||||
)
|
||||
type_of_owner: str = Field(
|
||||
description="The type of owner of the stock insider trading."
|
||||
)
|
||||
acquistion_or_disposition: str = Field(
|
||||
description="The acquistion or disposition of the stock insider trading."
|
||||
)
|
||||
form_type: str = Field(description="The form type of the stock insider trading.")
|
||||
securities_transacted: float = Field(
|
||||
description="The securities transacted of the stock insider trading."
|
||||
)
|
||||
price: float = Field(description="The price of the stock insider trading.")
|
||||
security_name: str = Field(
|
||||
description="The security name of the stock insider trading."
|
||||
)
|
||||
link: str = Field(description="The link of the stock insider trading.")
|
||||
|
||||
Reference in New Issue
Block a user