mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 05:52:23 +00:00
* Cleanse PO from Yahoo Finance * I removed equal but then moved it back in * Update tests * Get rid of sust command * Get rid of quote since broken * Added in export capability for quote * Remove pir and summary, fix news and change source for weights * Update stuff * Add sources * Update portfolio to not be dependend on Yahoo Finance * Update all tests * Update SDK * Details * Fix integration scripts * I think I had to rewrite these * Update more tests * oopsie * Fix 1 * Fix Sort * and fix test --------- Co-authored-by: james <jmaslek11@gmail.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""FinancialModelingPrep model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import json
|
|
import logging
|
|
from typing import Dict
|
|
from urllib.error import HTTPError
|
|
from urllib.request import urlopen
|
|
|
|
from openbb_terminal import config_terminal as cfg
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.rich_config import console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# pylint: disable=consider-using-with
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_etf_sector_weightings(name: str) -> Dict:
|
|
"""Return sector weightings allocation of ETF. [Source: FinancialModelingPrep]
|
|
|
|
Parameters
|
|
----------
|
|
name: str
|
|
ETF name
|
|
|
|
Returns
|
|
-------
|
|
Dict[str, Any]
|
|
Dictionary with sector weightings allocation
|
|
"""
|
|
try:
|
|
response = urlopen(
|
|
f"https://financialmodelingprep.com/api/v3/etf-sector-weightings/{name}?apikey={cfg.API_KEY_FINANCIALMODELINGPREP}"
|
|
)
|
|
data = json.loads(response.read().decode("utf-8"))
|
|
except HTTPError:
|
|
console.print(
|
|
"This endpoint is only for premium members. Please visit the subscription page to upgrade the "
|
|
"plan (Starter or higher) at https://financialmodelingprep.com/developer/docs/pricing"
|
|
)
|
|
return dict()
|
|
|
|
if "Error Message" in data:
|
|
raise ValueError(data["Error Message"])
|
|
|
|
return data
|