-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 97d06fa
Showing
12 changed files
with
15,474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
__pycache__/* | ||
tests/__pycache__/* | ||
dist/* | ||
src/pytickersymbols.egg-info/* | ||
src/tests/__pycache__/* | ||
src/pytickersymbols/__pycache__/* | ||
.coverage.* | ||
src/test/__pycache__/* | ||
report.xml | ||
coverage.xml | ||
nosetests.xml | ||
coverage/* | ||
.noseids | ||
report.xml | ||
.tox/* | ||
.venv/* | ||
.coverage | ||
build/* | ||
.pytest_cache/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: python | ||
python: | ||
- "3.6" | ||
cache: pip | ||
install: | ||
- pip install tox-travis coveralls | ||
script: | ||
- tox | ||
deploy: | ||
provider: pypi | ||
user: | ||
secure: "1WDqOWBY6tVEDRElNWLEws22r4GrHIn8pclYv2ivKJps4JzN3kREbuW/11oW6Cz8UOtMhUr8RwMtbupq73He9lP0y6AYrd4dr4EAW+G4woblMGo5k2L/m8Yt13RQ/jwP83+XNmdaGmZaP6TqN1/zYL9q2wAImoX0IqNu2csFsAMkVriqeuhy8IRra8YAChgHXHdCFFeZpJcWcZb45ej1sc9MbGgb+55+wVvA/gMzvkBLAEqC/P/Tm5FFvK5WW5vSHVrHMCeZvvh8m8v7vAo2Swx4ITzUvKyE5XdiKDfMrEAK0cW7iz1ghiP//2oKS/JaUNHOSYW/0sebn8EUBdyUSEqt/rN1l1+OietXxK6g3XK+vI/PKWF3ImcxpP0jM8laysLPfhrE6iQvAGJGgJObbpNeCXD7N0bsY5Rtpx8g1obARWLo2LwBEbmWKxtFi6goL2xHdLaGGp/og1bgSZv8h4S/raIOK62Ocu3D7Ju9ArrtCatXJ0sIhK5Nj7CFFEcjU8d+hMybPwspumi7LmULa97dPnRMzc2uJJhUAlINfKgSLXfrxtaThRJjQQKo0J0xcDEFroOIvcjoKQrUADwXyWGNwP6pT5SCDhnGGPnE8RjsSXAk1Qqj6Yl0GcdMwrCJiEp5qSEy9mvXic52jE2gOWdB8beDr2yOOBPdhQgrx1c=" | ||
password: | ||
secure: "bobH2YMEIwCwFo5+XK2Y4wtI48xBH4q6UGIbD5kyxZ8ttUoPnNvKXGVofFNwwP7kO1312q5RC3HHYj0S0E1BShyt7G+/W/fPrIkAhu7U6XMQhN33mQH3lDqfXfqoH8kd3t2BoVNTbwaooI0icUD/LElH+r8pYBug/qI4NNL5u3S9gwQKh77u3P1sUNEju14DdjmA+9cTcfTQJtSLukV9kiHLpkwkcpM8AHX5HYhU+7+cHShNwwOpX0IrZre9sN0NfcBL8U4qE+wisPLvBJ7wjvnRakxS3A1JdnF96ncxyd/A+60IFLfdpKpmAOJVsnC9Q/NWnRpI6JqtvwIZuKPVBMZqsSft6a/ZMz1wfvfW5NrDZSSs4cSX29zlGBK7BVqwF3uO73BxEj4m+5HYnJULEHv5kF34XZ/lg1dHAU09nbWqM3vmozj2ITbeXrxRBx7WNFG/sFiIJgvJJPAAX/lXoKrZFWbnWK5NoN0hLI7dZJrUHlj/xcIg8WOLAYYjrSXXwFqrpLTLnFIKEwS+9ngSodKb5Tcwb6hQmwXbSL8Qz8QCw5HlN0K5BhRHMhdnZG9GqGzJeSsk84NBQWKfaxlW2a+0Julz6tGCejQMFw+p3HC9EGUPPp1j/cAhZlKpUZBJ4NjimL/UvselFWWDjmUrAVwbXB0hJbvfjGOBnDP/XEY=" | ||
on: | ||
branch: master | ||
after_success: | ||
- coveralls --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2018-2019 Slash Gordon | ||
|
||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[![Build Status](https://travis-ci.org/portfolioplus/pytickersymbols.svg?branch=master)](https://travis-ci.org/portfolioplus/pytickersymbols) | ||
[![Coverage Status](https://coveralls.io/repos/github/portfolioplus/pytickersymbols/badge.svg?branch=master)](https://coveralls.io/github/portfolioplus/pytickersymbols?branch=master) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5ef7d89e40b7491db63ea9753e01851c)](https://www.codacy.com/app/cdieck88/pytickersymbols?utm_source=github.com&utm_medium=referral&utm_content=portfolioplus/pytickersymbols&utm_campaign=Badge_Grade) | ||
# pytickersymbols | ||
|
||
pytickersymbols provides access to google and yahoo ticker symbols for all stocks of the following indices: | ||
|
||
- [x] AEX | ||
- [x] BEL 20 | ||
- [x] CAC 40 | ||
- [x] DAX | ||
- [x] DOW JONES | ||
- [x] FTSE 100 | ||
- [x] IBEX 35 | ||
- [x] MDAX | ||
- [x] NASDAQ 100 | ||
- [x] OMX Helsinki 15 | ||
- [x] OMX Helsinki 25 | ||
- [x] OMX Stockholm 30 | ||
- [x] S&P 100 | ||
- [x] S&P 500 | ||
- [x] SDAX | ||
- [x] SMI | ||
- [x] TECDAX | ||
|
||
# quick start | ||
|
||
Get all countries, indices and industries as follow: | ||
```python | ||
from pytickersymbols import PyTickerSymbols | ||
|
||
stock_data = PyTickerSymbols() | ||
countries = stock_data.get_all_countries() | ||
indices = stock_data.get_all_indices() | ||
industries = stock_data.get_all_industries() | ||
``` | ||
|
||
You can select all stocks of an index as follow: | ||
```python | ||
from pytickersymbols import PyTickerSymbols | ||
|
||
stock_data = PyTickerSymbols() | ||
german_stocks = stock_data.get_stocks_by_index('DAX') | ||
uk_stocks = stock_data.get_stocks_by_index('FTSE 100') | ||
|
||
``` | ||
|
||
# issue tracker | ||
|
||
[https://github.com/portfolioplus/pytickersymbols/issuese](https://github.com/portfolioplus/pytickersymbols/issues") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wheel==0.33.4 | ||
pytest | ||
pytest-cov | ||
pandas_datareader==0.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyYAML==5.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" pytickersymbols | ||
Copyright 2019 Slash Gordon | ||
Use of this source code is governed by an MIT-style license that | ||
can be found in the LICENSE file. | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
|
||
EXCLUDE_FROM_PACKAGES = ['test', 'test.*', 'test*'] | ||
VERSION = '1.0.11' | ||
|
||
def get_requirements(requirements): | ||
with open(requirements) as requirement_file: | ||
content = requirement_file.readlines() | ||
content = [x.strip() for x in content] | ||
return content | ||
|
||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name="pytickersymbols", | ||
version=VERSION, | ||
author="Slash Gordon", | ||
author_email="slash.gordon.dev@gmail.com", | ||
py_modules=['pytickersymbols'], | ||
package_dir={'': 'src'}, | ||
description="The lib provides ticker symbols for yahoo and google finance.", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/portfolioplus/pytickersymbols", | ||
packages=find_packages('src', exclude=EXCLUDE_FROM_PACKAGES), | ||
package_data={'': ['data/*.yaml']}, | ||
classifiers=[ | ||
'Development Status :: 5 - Production/Stable', | ||
'Intended Audience :: Developers', | ||
'Natural Language :: English', | ||
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.6', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
'Topic :: Office/Business :: Financial :: Investment', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" pytickersymbols | ||
Copyright 2019 Slash Gordon | ||
Use of this source code is governed by an MIT-style license that | ||
can be found in the LICENSE file. | ||
""" | ||
import os | ||
import yaml | ||
|
||
|
||
class PyTickerSymbols: | ||
|
||
def __init__(self): | ||
self.__stocks = None | ||
yaml_path = os.path.join( | ||
os.path.dirname(os.path.realpath(__file__)), "data", "stocks.yaml" | ||
) | ||
with open(yaml_path) as stocks: | ||
self.__stocks = yaml.safe_load(stocks) | ||
|
||
def get_all_indices(self): | ||
""" | ||
Returns all available indices | ||
:return: list of index names | ||
""" | ||
return self.__get_sub_items("indices") | ||
|
||
def get_all_industries(self): | ||
""" | ||
Returns all available industries | ||
:return: list of industries | ||
""" | ||
return self.__get_sub_items("industries") | ||
|
||
def get_all_countries(self): | ||
""" | ||
Returns all available countries | ||
:return: list of country names | ||
""" | ||
items = [stock["country"] for stock in self.__stocks["companies"]] | ||
return list(set(items)) | ||
|
||
def get_stocks_by_index(self, index): | ||
""" | ||
Returns a list with stocks who belongs to given index. | ||
:param index: name of index | ||
:return: list of stocks | ||
""" | ||
return self.__get_items("indices", index) | ||
|
||
def get_yahoo_ticker_symbols_by_index(self, index): | ||
""" | ||
Returns a list with yahoo ticker symbols who belongs to given index. | ||
:param index: name of index | ||
:return: list of yahoo ticker symbols | ||
""" | ||
my_items = self.__get_items("indices", index) | ||
return self.__filter_data(my_items, False, True) | ||
|
||
def get_google_ticker_symbols_by_index(self, index): | ||
""" | ||
Returns a list with google ticker symbols who belongs to given index. | ||
:param index: name of index | ||
:return: list of google ticker symbols | ||
""" | ||
my_items = self.__get_items("indices", index) | ||
return self.__filter_data(my_items, True, False) | ||
|
||
def get_stocks_by_industry(self, industry): | ||
""" | ||
Returns a list with stocks who belongs to given index. | ||
:param industry: name of index | ||
:return: list of stocks | ||
""" | ||
return self.__get_items("industries", industry) | ||
|
||
def get_stocks_by_country(self, country): | ||
""" | ||
Returns a list with stocks who belongs to given country. | ||
:param country: name of country | ||
:return: list of stocks | ||
""" | ||
|
||
def __valid(cou, st_cou): | ||
return isinstance(cou, str) and st_cou.lower() == cou.lower() | ||
|
||
return [ | ||
stock | ||
for stock in self.__stocks["companies"] | ||
if __valid(country, stock["country"]) | ||
] | ||
|
||
def index_to_yahoo_symbol(self, index_name): | ||
""" | ||
Returns the yahoo symbol for index name. | ||
:param country: name of index | ||
:return: yahoo symbol | ||
""" | ||
yahoo_symbol = None | ||
for index_item in self.__stocks["indices"]: | ||
if index_item['name'] == index_name: | ||
yahoo_symbol = index_item['yahoo'] | ||
break | ||
return yahoo_symbol | ||
|
||
def __get_items(self, key, val): | ||
stocks = [ | ||
stock | ||
for stock in self.__stocks["companies"] | ||
for item in stock[key] | ||
if isinstance(val, str) and val.lower() == item.lower() | ||
] | ||
return stocks | ||
|
||
def __get_sub_items(self, key): | ||
sub_items = list( | ||
set( | ||
[ | ||
item | ||
for stock in self.__stocks["companies"] | ||
for item in stock[key] | ||
] | ||
) | ||
) | ||
return sub_items | ||
|
||
@staticmethod | ||
def __filter_data(stocks, google, yahoo): | ||
ticker_list = [] | ||
for stock in stocks: | ||
sub_list = [] | ||
for symbol in stock["symbols"]: | ||
if google and "google" in symbol and symbol["google"] != "-": | ||
sub_list.append(symbol["google"]) | ||
if yahoo and "yahoo" in symbol and symbol["yahoo"] != "-": | ||
sub_list.append(symbol["yahoo"]) | ||
ticker_list.append(sub_list) | ||
return ticker_list |
Oops, something went wrong.