Tehran Stock Market
A python package that helps to access TCCIM stock price history, Using OOP Interface
Features
- Download All stocks prices
- Download prices from a group (i.e ETFs or cars, etc.)
- Download Price history of one specific Stock
- After first setup available offline.
- CommandLine Interface
- Export data to csv, excel or Stata(dta)
- Compatible with
sqlalchemy - Compatible with
PANDAS - Based on light
sqlite
0 - Install
pip install tehran_stocks_ng
1- Initialization
For first use you need initialize the database
1-1 Command line
ts-get init # Set up to sqlite database
1-2 Python
import tehran_stocks
# On first import package initialize itself
During initialization you will prompt for downloading all prices. if you answer yes it will download all prices, otherwise you can download data
2- Download and Update prices
2-1 Command line
ts-get update # update all price , or download all if no price exist
ts-get group 34 ## 34 is the code for car's group.
ts-get get_groups ## get group name and group codes
2-2 Python
from tehran_stocks import get_all_price, Stocks, update_group
get_all_price() # download and(or) update all prices
update_group(34) #download and(or) update Stocks in groupCode = 34 (Cars)
Stocks.get_group() # to see list of group codes
3- Access Data
To access data you can use Stocks which is an customized sqlalchemy object, which helps you to find prices on an easy way.
3-1 Search Stocks
from tehran_stocks import Stocks, db
# You can use query to find stocks
stock = Stocks.query.filter_by(name='كگل').first() #find by symbol(نماد)
stock = Stocks.query.filter_by(code='35700344742885862').first() # find by code on tsetmc url
stock = Stocks.query.filter(Stocks.title.like('%گل گهر%')).first() # Search by title
stock_list = Stocks.query.filter_by(group_code =34).all() # find all Stocks in Khodro
stock_list = Stocks.query.filter(Stocks.group_code.in_([13,34])).all() # all stocks in khodro and felezat
## (Advanced)or run sql query using orm or raw sql
db.session.query(Stocks.group_code, Stocks.group_name).group_by(Stocks.group_code).all()
db.session.execute('select group_code , group_name from stocks group by group_name').fetchall()
Now easily access stock price and do whatever you want with pandas dataframes:
# use data as a pandas dataframe
>>> stock.df #
id code ticker dtyyyymmdd first high low close value vol openint per open last date
0 22491 35700344742885862 Gol-E-Gohar. 20040829 12000.0 12021.0 12000.0 12000.0 18841605000 1570000 2708 D 12000.0 12000.0 2004-08-29
>>> stock.summary()
Start date: 20040829
End date: 20190714
Total days: 2987
>>> stock.update()
# update stock price history
# Export to your preferred format
>>> stock.df.to_csv('price.csv')
>>> stock.df.to_excel('price.xlsx')
>>> stock.df.to_stata('price.dta')
Todo
- Create Database
- Download Data
- CommandLine Support
- Jalali Support
Metadata
Release files for tehran-stocks-ng 0.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tehran-stocks-ng-0.6.4.tar.gz | 9.0 kB | Without provenance | Details for tehran-stocks-ng-0.6.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tehran_stocks_ng-0.6.4-py3-none-any.whl | Python 3 | none | any | Details for tehran_stocks_ng-0.6.4-py3-none-any.whl |
Total release size: 19.9 kB
Release files / tehran-stocks-ng-0.6.4.tar.gz
| Download URL | tehran-stocks-ng-0.6.4.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc9f91814b75cb8b0c5e13bc926ddd7dfab8d2fb494e2f21ac24d8f7876377cd
|
|
BLAKE2b-256 checksum How to use checksums |
72acd39ace2f25dc7759ddd7ef47ae3823dbd7a247a5118ca1b8a3159bf827be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
|
Release files / tehran_stocks_ng-0.6.4-py3-none-any.whl
| Download URL | tehran_stocks_ng-0.6.4-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
835a99940980cb4ce05b44d2333b7285bec2c3887b4cebcaec87e3c9baec1c71
|
|
BLAKE2b-256 checksum How to use checksums |
e5ecf8963bec8b0784c4e5e68abc49d008f5b47d5a9b83ffefc1f826456e3de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191203 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.4
|
Security for tehran-stocks-ng 0.6.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.