mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
refactored StocksOwnership for stocks.fa.own
This commit is contained in:
@@ -16,20 +16,48 @@ class FMPStockOwnershipQueryParams(StockOwnershipQueryParams):
|
||||
"""FMP Stock Ownership query.
|
||||
|
||||
Source: https://site.financialmodelingprep.com/developer/docs/#Stock-Ownership-by-Holders
|
||||
|
||||
Parameter
|
||||
---------
|
||||
symbol : string
|
||||
The symbol of the company.
|
||||
page : int
|
||||
The page number to get
|
||||
date : date
|
||||
The CIK of the company owner.
|
||||
"""
|
||||
|
||||
|
||||
class FMPStockOwnershipData(StockOwnershipData):
|
||||
"""FMP Stock Ownership data."""
|
||||
"""FMP Stock Ownership Data."""
|
||||
|
||||
class Config:
|
||||
fields = {
|
||||
"filing_date": "filingDate",
|
||||
"investor_name": "investorName",
|
||||
"security_name": "securityName",
|
||||
"type_of_security": "typeOfSecurity",
|
||||
"security_cusip": "securityCusip",
|
||||
"shares_type": "sharesType",
|
||||
"put_call_share": "putCallShare",
|
||||
"investment_discretion": "investmentDiscretion",
|
||||
"industry_title": "industryTitle",
|
||||
"last_weight": "lastWeight",
|
||||
"change_in_weight": "changeInWeight",
|
||||
"change_in_weight_percentage": "changeInWeightPercentage",
|
||||
"market_value": "marketValue",
|
||||
"last_market_value": "lastMarketValue",
|
||||
"change_in_market_value": "changeInMarketValue",
|
||||
"change_in_market_value_percentage": "changeInMarketValuePercentage",
|
||||
"shares_number": "sharesNumber",
|
||||
"last_shares_number": "lastSharesNumber",
|
||||
"change_in_shares_number": "changeInSharesNumber",
|
||||
"change_in_shares_number_percentage": "changeInSharesNumberPercentage",
|
||||
"quarter_end_price": "quarterEndPrice",
|
||||
"avg_price_paid": "avgPricePaid",
|
||||
"is_new": "isNew",
|
||||
"is_sold_out": "isSoldOut",
|
||||
"last_ownership": "lastOwnership",
|
||||
"change_in_ownership": "changeInOwnership",
|
||||
"change_in_ownership_percentage": "changeInOwnershipPercentage",
|
||||
"holding_period": "holdingPeriod",
|
||||
"first_added": "firstAdded",
|
||||
"performance_percentage": "performancePercentage",
|
||||
"last_performance": "lastPerformance",
|
||||
"change_in_performance": "changeInPerformance",
|
||||
"is_counted_for_performance": "isCountedForPerformance",
|
||||
}
|
||||
|
||||
|
||||
class FMPStockOwnershipFetcher(
|
||||
@@ -56,6 +84,7 @@ class FMPStockOwnershipFetcher(
|
||||
api_key,
|
||||
query,
|
||||
)
|
||||
|
||||
return get_data_many(url, FMPStockOwnershipData)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
"""Stock owner data model."""
|
||||
|
||||
|
||||
from datetime import (
|
||||
date as dateType,
|
||||
datetime,
|
||||
)
|
||||
|
||||
from pydantic import validator
|
||||
from datetime import date as dateType, datetime
|
||||
from typing import 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, DATA_DESCRIPTIONS
|
||||
|
||||
from pydantic import Field, validator
|
||||
|
||||
|
||||
def most_recent_quarter(base: dateType = dateType.today()) -> dateType:
|
||||
@@ -42,149 +41,172 @@ def most_recent_quarter(base: dateType = dateType.today()) -> dateType:
|
||||
|
||||
|
||||
class StockOwnershipQueryParams(QueryParams, BaseSymbol):
|
||||
"""Stock ownership query.
|
||||
"""Stock ownership Query."""
|
||||
|
||||
|
||||
Parameter
|
||||
---------
|
||||
symbol : string
|
||||
The symbol of the company.
|
||||
page : int
|
||||
The page number to get
|
||||
date : date
|
||||
The CIK of the company owner.
|
||||
"""
|
||||
|
||||
page: int = 0
|
||||
date: dateType = most_recent_quarter()
|
||||
date: dateType = Field(description=QUERY_DESCRIPTIONS.get("date", ""))
|
||||
page: Optional[int] = Field(
|
||||
default=0, description="The page number of the data to fetch."
|
||||
)
|
||||
|
||||
@validator("date", pre=True)
|
||||
def time_validate(cls, v: str): # pylint: disable=E0213
|
||||
base = datetime.strptime(v, "%Y-%m-%d").date()
|
||||
return most_recent_quarter(base)
|
||||
def date_validate(cls, v: str): # pylint: disable=E0213
|
||||
# base = datetime.strptime(v, "%Y-%m-%d").date()
|
||||
return most_recent_quarter(v)
|
||||
|
||||
|
||||
class StockOwnershipData(Data):
|
||||
"""Stock ownership data.
|
||||
"""Stock Ownership Data."""
|
||||
|
||||
Returns
|
||||
-------
|
||||
date : date
|
||||
The date of the stock ownership.
|
||||
cik : int
|
||||
The cik of the stock ownership.
|
||||
filingDate : date
|
||||
The filing date of the stock ownership.
|
||||
investorName : str
|
||||
The investor name of the stock ownership.
|
||||
symbol : str
|
||||
The symbol of the stock ownership.
|
||||
securityName : str
|
||||
The security name of the stock ownership.
|
||||
typeOfSecurity : str
|
||||
The type of security of the stock ownership.
|
||||
securityCusip : str
|
||||
The security cusip of the stock ownership.
|
||||
sharesType : str
|
||||
The shares type of the stock ownership.
|
||||
putCallShare : str
|
||||
The put call share of the stock ownership.
|
||||
investmentDiscretion : str
|
||||
The investment discretion of the stock ownership.
|
||||
industryTitle : str
|
||||
The industry title of the stock ownership.
|
||||
weight : float
|
||||
The weight of the stock ownership.
|
||||
lastWeight : float
|
||||
The last weight of the stock ownership.
|
||||
changeInWeight : float
|
||||
The change in weight of the stock ownership.
|
||||
changeInWeightPercentage : float
|
||||
The change in weight percentage of the stock ownership.
|
||||
marketValue : int
|
||||
The market value of the stock ownership.
|
||||
lastMarketValue : int
|
||||
The last market value of the stock ownership.
|
||||
changeInMarketValue : int
|
||||
The change in market value of the stock ownership.
|
||||
changeInMarketValuePercentage : float
|
||||
The change in market value percentage of the stock ownership.
|
||||
sharesNumber : int
|
||||
The shares number of the stock ownership.
|
||||
lastSharesNumber : int
|
||||
The last shares number of the stock ownership.
|
||||
changeInSharesNumber : float
|
||||
The change in shares number of the stock ownership.
|
||||
changeInSharesNumberPercentage : float
|
||||
The change in shares number percentage of the stock ownership.
|
||||
quarterEndPrice : float
|
||||
The quarter end price of the stock ownership.
|
||||
avgPricePaid : float
|
||||
The average price paid of the stock ownership.
|
||||
isNew : bool
|
||||
Is the stock ownership new.
|
||||
isSoldOut : bool
|
||||
Is the stock ownership sold out.
|
||||
ownership : float
|
||||
How much is the ownership.
|
||||
lastOwnership : float
|
||||
The last ownership amount.
|
||||
changeInOwnership : float
|
||||
The change in ownership amount.
|
||||
changeInOwnershipPercentage : float
|
||||
The change in ownership percentage.
|
||||
holdingPeriod : int
|
||||
The holding period of the stock ownership.
|
||||
firstAdded : date
|
||||
The first added date of the stock ownership.
|
||||
performance : float
|
||||
The performance of the stock ownership.
|
||||
performancePercentage : float
|
||||
The performance percentage of the stock ownership.
|
||||
lastPerformance : float
|
||||
The last performance of the stock ownership.
|
||||
changeInPerformance : float
|
||||
The change in performance of the stock ownership.
|
||||
isCountedForPerformance : bool
|
||||
Is the stock ownership counted for performance.
|
||||
"""
|
||||
|
||||
date: dateType
|
||||
cik: int
|
||||
filingDate: dateType
|
||||
investorName: str
|
||||
symbol: str
|
||||
securityName: str
|
||||
typeOfSecurity: str
|
||||
securityCusip: str
|
||||
sharesType: str
|
||||
putCallShare: str
|
||||
investmentDiscretion: str
|
||||
industryTitle: str
|
||||
weight: float
|
||||
lastWeight: float
|
||||
changeInWeight: float
|
||||
changeInWeightPercentage: float
|
||||
marketValue: int
|
||||
lastMarketValue: int
|
||||
changeInMarketValue: int
|
||||
changeInMarketValuePercentage: float
|
||||
sharesNumber: int
|
||||
lastSharesNumber: int
|
||||
changeInSharesNumber: float
|
||||
changeInSharesNumberPercentage: float
|
||||
quarterEndPrice: float
|
||||
avgPricePaid: float
|
||||
isNew: bool
|
||||
isSoldOut: bool
|
||||
ownership: float
|
||||
lastOwnership: float
|
||||
changeInOwnership: float
|
||||
changeInOwnershipPercentage: float
|
||||
holdingPeriod: int
|
||||
firstAdded: dateType
|
||||
performance: float
|
||||
performancePercentage: float
|
||||
lastPerformance: float
|
||||
changeInPerformance: float
|
||||
isCountedForPerformance: bool
|
||||
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
|
||||
cik: int = Field(description="The cik of the stock ownership.")
|
||||
filing_date: dateType = Field(
|
||||
alias="filingDate", description="The filing date of the stock ownership."
|
||||
)
|
||||
investor_name: str = Field(
|
||||
...,
|
||||
alias="investorName",
|
||||
description="The investor name of the stock ownership.",
|
||||
)
|
||||
symbol: str = Field(description="The symbol of the stock ownership.")
|
||||
security_name: str = Field(
|
||||
...,
|
||||
alias="securityName",
|
||||
description="The security name of the stock ownership.",
|
||||
)
|
||||
type_of_security: str = Field(
|
||||
...,
|
||||
alias="typeOfSecurity",
|
||||
description="The type of security of the stock ownership.",
|
||||
)
|
||||
security_cusip: str = Field(
|
||||
...,
|
||||
alias="securityCusip",
|
||||
description="The security cusip of the stock ownership.",
|
||||
)
|
||||
shares_type: str = Field(
|
||||
alias="sharesType", description="The shares type of the stock ownership."
|
||||
)
|
||||
put_call_share: str = Field(
|
||||
...,
|
||||
alias="putCallShare",
|
||||
description="The put call share of the stock ownership.",
|
||||
)
|
||||
investment_discretion: str = Field(
|
||||
...,
|
||||
alias="investmentDiscretion",
|
||||
description="The investment discretion of the stock ownership.",
|
||||
)
|
||||
industry_title: str = Field(
|
||||
...,
|
||||
alias="industryTitle",
|
||||
description="The industry title of the stock ownership.",
|
||||
)
|
||||
weight: float = Field(description="The weight of the stock ownership.")
|
||||
last_weight: float = Field(
|
||||
alias="lastWeight", description="The last weight of the stock ownership."
|
||||
)
|
||||
change_in_weight: float = Field(
|
||||
...,
|
||||
alias="changeInWeight",
|
||||
description="The change in weight of the stock ownership.",
|
||||
)
|
||||
change_in_weight_percentage: float = Field(
|
||||
...,
|
||||
alias="changeInWeightPercentage",
|
||||
description="The change in weight percentage of the stock ownership.",
|
||||
)
|
||||
market_value: int = Field(
|
||||
alias="marketValue", description="The market value of the stock ownership."
|
||||
)
|
||||
last_market_value: int = Field(
|
||||
...,
|
||||
alias="lastMarketValue",
|
||||
description="The last market value of the stock ownership.",
|
||||
)
|
||||
change_in_market_value: int = Field(
|
||||
...,
|
||||
alias="changeInMarketValue",
|
||||
description="The change in market value of the stock ownership.",
|
||||
)
|
||||
change_in_market_value_percentage: float = Field(
|
||||
...,
|
||||
alias="changeInMarketValuePercentage",
|
||||
description="The change in market value percentage of the stock ownership.",
|
||||
)
|
||||
shares_number: int = Field(
|
||||
...,
|
||||
alias="sharesNumber",
|
||||
description="The shares number of the stock ownership.",
|
||||
)
|
||||
last_shares_number: int = Field(
|
||||
...,
|
||||
alias="lastSharesNumber",
|
||||
description="The last shares number of the stock ownership.",
|
||||
)
|
||||
change_in_shares_number: float = Field(
|
||||
...,
|
||||
alias="changeInSharesNumber",
|
||||
description="The change in shares number of the stock ownership.",
|
||||
)
|
||||
change_in_shares_number_percentage: float = Field(
|
||||
...,
|
||||
alias="changeInSharesNumberPercentage",
|
||||
description="The change in shares number percentage of the stock ownership.",
|
||||
)
|
||||
quarter_end_price: float = Field(
|
||||
...,
|
||||
alias="quarterEndPrice",
|
||||
description="The quarter end price of the stock ownership.",
|
||||
)
|
||||
avg_price_paid: float = Field(
|
||||
...,
|
||||
alias="avgPricePaid",
|
||||
description="The average price paid of the stock ownership.",
|
||||
)
|
||||
is_new: bool = Field(alias="isNew", description="Is the stock ownership new.")
|
||||
is_sold_out: bool = Field(
|
||||
alias="isSoldOut", description="Is the stock ownership sold out."
|
||||
)
|
||||
ownership: float = Field(description="How much is the ownership.")
|
||||
last_ownership: float = Field(
|
||||
alias="lastOwnership", description="The last ownership amount."
|
||||
)
|
||||
change_in_ownership: float = Field(
|
||||
alias="changeInOwnership", description="The change in ownership amount."
|
||||
)
|
||||
change_in_ownership_percentage: float = Field(
|
||||
...,
|
||||
alias="changeInOwnershipPercentage",
|
||||
description="The change in ownership percentage.",
|
||||
)
|
||||
holding_period: int = Field(
|
||||
...,
|
||||
alias="holdingPeriod",
|
||||
description="The holding period of the stock ownership.",
|
||||
)
|
||||
first_added: dateType = Field(
|
||||
...,
|
||||
alias="firstAdded",
|
||||
description="The first added date of the stock ownership.",
|
||||
)
|
||||
performance: float = Field(description="The performance of the stock ownership.")
|
||||
performance_percentage: float = Field(
|
||||
...,
|
||||
alias="performancePercentage",
|
||||
description="The performance percentage of the stock ownership.",
|
||||
)
|
||||
last_performance: float = Field(
|
||||
...,
|
||||
alias="lastPerformance",
|
||||
description="The last performance of the stock ownership.",
|
||||
)
|
||||
change_in_performance: float = Field(
|
||||
...,
|
||||
alias="changeInPerformance",
|
||||
description="The change in performance of the stock ownership.",
|
||||
)
|
||||
is_counted_for_performance: bool = Field(
|
||||
...,
|
||||
alias="isCountedForPerformance",
|
||||
description="Is the stock ownership counted for performance.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user