Last active
June 24, 2023 02:42
-
-
Save vvksh/920828be6173c50133ab79d6fe7994af to your computer and use it in GitHub Desktop.
get ticker company name and market cap from yfinance in python
This file contains hidden or 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
# pip3 install yfinance | |
from typing import Dict | |
def get_ticker_metadata(ticker: str) -> Dict[str, str]: | |
""" | |
:param ticker: stock ticker | |
:return: Dictionary containing some metadata | |
""" | |
result = {"company_name": "not_found", | |
"market_cap": "not_found"} | |
import yfinance as yf | |
try: | |
info = yf.Ticker(ticker).info | |
if info: | |
if 'longName' in info: | |
result["company_name"] = info['longName'] | |
if "marketCap" in info: | |
result["market_cap"] = str(round((info['marketCap']/1000000000), 2)) + " blns$" | |
except Exception as e: | |
print(e) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment