Get the Ticker Symbol for US exchange listed stocks in Python

Introduction

If I wanted to get stock price data for the New York Stock Exchange (NYSE) and NASDAQ, I needed to know the Ticker Symbol of the stock, so I will explain how to do it. We have not confirmed that all listed stocks are listed, so please refer to it.

environment

Windows 10 home

Anaconda(Python 3.7.6)

Pandas 0.24.2

Get the Ticker Symbol

Get the list from NASDAQ ftp and mold it.

import pandas as pd

others_list = 'ftp://ftp.nasdaqtrader.com/symboldirectory/otherlisted.txt'
nasdaq_list = 'ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqlisted.txt'

def symbols_nyse():
    other = pd.read_csv(others_list, sep='|')
    #Get NYSE stuff
    company_nyse = other[other['Exchange']=='N'][['ACT Symbol', 'Security Name']]
    #ETFs include MYSE MKT, NYSE ARCA, and MATS.
    etf_other = other[other['ETF'] == 'Y'][['ACT Symbol', 'Security Name', 'Exchange']]   
    #index reset
    company_nyse = company_nyse.reset_index(drop=True)
    etf_other = etf_other.reset_index(drop=True)
    #ACT Symbol -> Symbol
    company_nyse = company_nyse.rename(columns={'ACT Symbol':'Symbol'})
    etf_other = eft_other.rename(columns={'ACT Symbol':'Symbol'})
    
    return company_nyse, etf_other

def symbols_nasdaq():
    nasdaq = pd.read_csv(nasdaq_list, sep='|')
    #Get only those with Normal Status
    nasdaq_normal = nasdaq[nasdaq['Financial Status']=='N']
    #Select one that is not a Test issue
    nasdaq_normal = nasdaq_normal[nasdaq_normal['Test Issue']=='N']
    #Determined by ETF
    company_nasdaq = nasdaq_normal[nasdaq_normal['ETF']=='N'][['Symbol', 'Security Name']]
    etf_nasdaq = nasdaq_normal[nasdaq_normal['ETF']=='Y'][['Symbol', 'Security Name']]
    #index reset
    company_nasdaq = company_nasdaq.reset_index(drop=True)
    etf_nasdaq = etf_nasdaq.reset_index(drop=True)

    return company_nasdaq, etf_nasdaq

def symbols_all():
    company_nyse, etf_other = symbols_nyse()
    company_nasdaq, etf_nasdaq = symbols_nasdaq()
    #Distinguish between NYSE and NASDAQ
    company_nyse['Market'] = 'NYSE'
    company_nasdaq['Market'] = 'NASDAQ'    
    #Also distinguish NASDAQ ETFs
    etf_nasdaq['Exchange'] = 'NASDAQ'#etf_Match to other colum name

    return (pd.concat([company_nyse, company_nasdaq], ignore_index=True, sort=False),
            pd.concat([etf_other, etf_nasdaq], ignore_index=True, sort=False))

Show Ticker Symbol

You can see the Ticker Symbol of a listed company by looking at the'Symbol'column.

company, etf = symbols_all()
company
symbols.png

reference

Recommended Posts

Get the Ticker Symbol for US exchange listed stocks in Python
Get the desktop path in Python
Get the script path in Python
Get the desktop path in Python
Get the host name in Python
Get exchange rates from open exchange rates in Python
MongoDB for the first time in Python
Get a token for conoha in python
Get the EDINET code list in Python
Get the key for the second layer migration of JSON data in python
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
Get the caller of a function in Python
Tips for hitting the ATND API in Python
Get the X Window System window title in Python
How to get the files in the [Python] folder
How to get the variable name itself in python
How to get the number of digits in Python
[Python] Get the numbers in the graph image with OCR
[python] Get the list of classes defined in the module
Get the result in dict format with Python psycopg2
Get the size (number of elements) of UnionFind in Python
Get the value selected in Selenium Python VBA pull-down
Get date in Python
[For beginners] Web scraping with Python "Access the URL in the page to get the contents"
Get the URL of the HTTP redirect destination in Python
Get your heart rate from the fitbit API in Python!
Check the operation of Python for .NET in each environment
Get the MIME type in Python and determine the file format
Get the number of specific elements in a python list
Search for variables in pandas.DataFrame and get the corresponding row.
[Understand in the shortest time] Python basics for data analysis
Get the value while specifying the default value from dict in Python
How to get the last (last) value in a list in Python
Automatically get the port where Arduino is stuck in Python
Get the current date and time in Python, considering the time difference
Get the number of occurrences for each element in the list
Google search for the last line of the file in Python
Get the index of each element of the confusion matrix in Python
Get YouTube Comments in Python
Get last month in python
Download the file in Python
Find the difference in Python
Search for strings in Python
Techniques for sorting in Python
Get Terminal size in Python
[Python] Get the previous month
Explicitly get EOF in python
Get Evernote notes in Python
About "for _ in range ():" in python
Get Japanese synonyms in Python
How is the progress? Let's get on with the boom ?? in Python
Wrap (part of) the AtCoder Library in Cython for use in Python
Automatically resize screenshots for the App Store for each screen in Python
python> Display 3 decimals in ".3f, .3f, .3f" format / Get 3 coordinate values in the range [-1: 1]
[Introduction to Python] How to use the in operator in a for statement?
Hit the New Relic API in Python to get the server status
[python] Get the rank of the values in List in ascending / descending order
Dockerfile with the necessary libraries for natural language processing in python
Review the basics in 1 minute! Python Priority queue for fast minimums