mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
* quick econ fix * black * keys and feature flags * terminal name 👀 * some more replacements * some more replacements * edit pyproject * gst -> openbb * add example portfolios back to git * Update api from gst * sorry. skipping some tests * another round of names * another round of test edits * Missed some .gst refs and update timezone * water mark stuff * Fixing Names in terminal.spec and name of GTFF_DEFAULTS to OBBFF_DEFAULTS * fix more GST to OpenBB Terminal * Logging : merge conflicts with main * Revert wrong files Co-authored-by: Andrew <andrew.kenreich@gmail.com> Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Chavithra PARANA <chavithra@gmail.com>
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
"Polygon Model"
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
from typing import List, Tuple
|
|
|
|
import requests
|
|
|
|
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__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_similar_companies(ticker: str, us_only: bool) -> Tuple[List[str], str]:
|
|
"""Get similar companies from Polygon
|
|
|
|
Parameters
|
|
----------
|
|
ticker : str
|
|
Ticker to get similar companies of
|
|
|
|
Returns
|
|
-------
|
|
List[str] :
|
|
List of similar tickers
|
|
str :
|
|
String indicating data source
|
|
"""
|
|
result = requests.get(
|
|
f"https://api.polygon.io/v1/meta/symbols/{ticker.upper()}/company?&apiKey={cfg.API_POLYGON_KEY}"
|
|
)
|
|
|
|
similar = []
|
|
source = "Error"
|
|
|
|
if result.status_code == 200:
|
|
similar = result.json()["similar"]
|
|
source = "Polygon"
|
|
if us_only:
|
|
us_similar = []
|
|
mkw_link = "https://www.marketwatch.com/investing/stock/"
|
|
for sym in similar:
|
|
prep_link = mkw_link + sym
|
|
sent_req = requests.get(prep_link)
|
|
if prep_link == sent_req.request.url:
|
|
us_similar.append(sym)
|
|
similar = us_similar
|
|
elif result.status_code == 401:
|
|
console.print("[red]Invalid API Key[/red]\n")
|
|
elif result.status_code == 403:
|
|
console.print("[red]API Key not authorized for Premium Feature[/red]\n")
|
|
else:
|
|
console.print(result.json()["error"])
|
|
|
|
return similar, source
|