Skip to content

Instantly share code, notes, and snippets.

@vvksh
Last active June 24, 2023 02:42
Show Gist options
  • Save vvksh/920828be6173c50133ab79d6fe7994af to your computer and use it in GitHub Desktop.
Save vvksh/920828be6173c50133ab79d6fe7994af to your computer and use it in GitHub Desktop.
get ticker company name and market cap from yfinance in python
# 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