shilewenuw / get_all_tickers

Get all publicly traded tickers with this library
MIT License
275 stars 124 forks source link

Get company name by ticker #9

Closed benbense closed 3 years ago

benbense commented 3 years ago

Is there a way to get the company name by the ticker symbol?

frank-ceballos commented 3 years ago

Hello @benbense,

I have been using this function to grab the company name based on ticker symbol.

import requests

def get_company_names(symbol):
    "Get company name based on symbol/ticker-label"
    url = "http://d.yimg.com/autoc.finance.yahoo.com/autoc?query="+symbol+"&region=1&lang=en"
    result = requests.get(url).json()
    return result["ResultSet"]["Result"][0]["name"] 

You can try it out.

The input is a string with the ticker label. For example:

symbol  = "AAPL"
company_name = get_company_names(symbol)

The original function can be found here.

shilewenuw commented 3 years ago

thanks @frank-ceballos for the solution