forked from OpenBB-finance/OpenBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ETF info and sector exposure from FMP (OpenBB-finance#5620)
* Add ETF info from FMP * Add integration tests * Add unit tests * Add etf sectors endpoint * Add etf sectors fmp endpoint * Omit nested sector list from fmp info data * Update tests and test data * Update test data * Specify provider explicitly in integration tests * Update tests * Skip yfinance etf historical test * Fix linter errors after the merge * Fix more linter errors * Fix failing and add missing tests * Fix integration tests * Fix calendar ipo tests
- Loading branch information
Showing
22 changed files
with
4,482 additions
and
4,162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""FMP Data Integration.""" |
79 changes: 79 additions & 0 deletions
79
openbb_platform/providers/fmp/openbb_fmp/models/etf_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""FMP ETF Info fetcher.""" | ||
|
||
from typing import Any, Dict, List, Optional | ||
|
||
from openbb_fmp.utils.helpers import create_url, get_data_many | ||
from openbb_provider.abstract.fetcher import Fetcher | ||
from openbb_provider.standard_models.etf_info import EtfInfoData, EtfInfoQueryParams | ||
from pydantic import Field | ||
|
||
|
||
class FMPEtfInfoQueryParams(EtfInfoQueryParams): | ||
"""FMP ETF Info Query Params.""" | ||
|
||
|
||
class FMPEtfInfoData(EtfInfoData): | ||
"""FMP ETF Info Data.""" | ||
|
||
asset_class: Optional[str] = Field( | ||
alias="assetClass", description="Asset class of the ETF." | ||
) | ||
aum: Optional[float] = Field(description="Assets under management.") | ||
avg_volume: Optional[float] = Field( | ||
alias="avgVolume", description="Average trading volume of the ETF." | ||
) | ||
cusip: Optional[str] = Field(description="CUSIP of the ETF.") | ||
description: Optional[str] = Field(description="Description of the ETF.") | ||
domicile: Optional[str] = Field(description="Domicile of the ETF.") | ||
etf_company: Optional[str] = Field( | ||
alias="etfCompany", description="Company of the ETF." | ||
) | ||
expense_ratio: Optional[float] = Field( | ||
alias="expenseRatio", description="Expense ratio of the ETF." | ||
) | ||
isin: Optional[str] = Field(description="ISIN of the ETF.") | ||
nav: Optional[float] = Field(description="Net asset value of the ETF.") | ||
nav_currency: Optional[str] = Field( | ||
alias="navCurrency", description="Currency of the ETF's net asset value." | ||
) | ||
website: Optional[str] = Field(description="Website link of the ETF.") | ||
holdings_count: Optional[int] = Field( | ||
alias="holdingsCount", description="Number of holdings in the ETF." | ||
) | ||
|
||
|
||
class FMPEtfInfoFetcher( | ||
Fetcher[ | ||
FMPEtfInfoQueryParams, | ||
List[FMPEtfInfoData], | ||
] | ||
): | ||
"""Transform the query, extract and transform the data from the FMP endpoints.""" | ||
|
||
@staticmethod | ||
def transform_query(params: Dict[str, Any]) -> FMPEtfInfoQueryParams: | ||
"""Transform the query.""" | ||
return FMPEtfInfoQueryParams(**params) | ||
|
||
@staticmethod | ||
def extract_data( | ||
query: FMPEtfInfoQueryParams, | ||
credentials: Optional[Dict[str, str]], | ||
**kwargs: Any, | ||
) -> List[Dict]: | ||
"""Return the raw data from the FMP endpoint.""" | ||
api_key = credentials.get("fmp_api_key") if credentials else "" | ||
|
||
url = create_url(version=4, endpoint="etf-info", api_key=api_key, query=query) | ||
|
||
return get_data_many(url, **kwargs) | ||
|
||
@staticmethod | ||
def transform_data( | ||
query: FMPEtfInfoQueryParams, data: List[Dict], **kwargs: Any | ||
) -> List[FMPEtfInfoData]: | ||
"""Return the transformed data.""" | ||
# remove "sectorList" key from data. it's handled by the sectors | ||
for d in data: | ||
d.pop("sectorList", None) | ||
return [FMPEtfInfoData.model_validate(d) for d in data] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.