Stock market (USA expandable for other countries) symbol or company lookup - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: Stock market (USA expandable for other countries) symbol or company lookup (/thread-22481.html) |
Stock market (USA expandable for other countries) symbol or company lookup - Larz60+ - Nov-14-2019 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):
RE: Stock market (USA expandable for other countries) symbol or company lookup - Larz60+ - Nov-14-2019 There's a problem with the PyPi version. Git clone is OK, I'll post when corrected. |