Python Forum
Stock market (USA expandable for other countries) symbol or company lookup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stock market (USA expandable for other countries) symbol or company lookup
#1
This is another stock market symbol/company lookup class.

clone: git clone www.github.com/Larz60p/PySymbol
Github: www.github.com/Larz60p/PySymbol
pip: pip install PySymbol

Yet another Stock Market Symbol class

The following class can be used to get company name from symbol and vice/versa

before running first time, make sure you are connected to the internet, after that, it's only requires if an update is requested.

when first run it will create the data directory structure tree will then look like

├── data
│ ├── csv
│ │ ├── AMEX_symbols.csv
│ │ ├── NASDAQ_symbols.csv
│ │ └── NYSE_symbols.csv
│ ├── excel
│ └── json
│ ├── AMEX_symbols.json
│ ├── NASDAQ_symbols.json
│ └── NYSE_symbols.json
├── requirements.txt
└── src
├── __init__.py
├── CreateDict.py
├── __pycache__
│ ├── CreateDict.cpython-38.pyc
│ ├── PySymbol.cpython-38.pyc
│ ├── StkMktPaths.cpython-38.pyc
│ └── Symbols.cpython-38.pyc
├── PySymbol.py
├── StkMktPaths.py
└── TrySymbolFetch.py

Setup:

clone application: git clone https://github.com/Larz60p/PySymbol
cd to PySymbol
Create virtual environment: python -m venv venv
Activate virtual environment: . ./venv/bin/activate
With internet access update environment: pip install -r requirements.txt
From PySymbol directory, run application to get current symbol files: python src/PySymbol.py

To import class in an application: see example: src/TrySymbolFetch.py

To force updates, instantiate sym as: sym = PySymbol.PySymbol(force_update=True)

To run interactively:

>>> import PySymbol
>>> sym = PySymbol.PySymbol()
>>> lookup = sym.Lookup
>>> lookup('NYSE', company_name='Raytheon Company')
'RTN'
>>> lookup('NYSE', ticker='RTN')
'Raytheon Company'
>>>
This class can be expanded by adding market information links in module: StkMktPaths.py
there is a dictionary named self.symbols, each market entry looks like:
'NASDAQ': {
                'url': 'https://old.nasdaq.com/screening/companies-by-name.' \
                    'aspx?letter=0&exchange=nasdaq&render=download',
                'filename': self.csvpath / 'NASDAQ_symbols.csv',
                'json_filename': self.jsonpath / 'NASDAQ_symbols.json',
                'dictname': self.dicts['NASDAQ'],
                'companies': {},
                'symbols': {}

            },
attributes:
url -- download url for markets symbol list (looking for csv file)
filename -- a pathlib path to save csv download
json_filename -- a pathlib path to save generated json file
dictname -- Name to be assigned to this market's information dictionary
companies -- placeholder for generated company dictionary
symbols -- placeholder for generated symbol information

the json file contains a lot of other information that you may find useful.
What's here depends on the source of the downloaded file, but for those in the package, contains (one cell):
Output:
"2362": { "Symbol": "RMAX", "Name": "RE/MAX Holdings, Inc.", "LastSale": "37.7", "MarketCap": "$1.15B", "IPOyear": "2013", "Sector": "Finance", "industry": "Real Estate", "Summary Quote": "https://old.nasdaq.com/symbol/rmax", "": "" },
Reply
#2
There's a problem with the PyPi version. Git clone is OK, I'll post when corrected.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020