Skip to main content

Data Downloader for Tehran stock market

Project description

Tehran Stock Market

made-with-python PyPI - Downloads PyPI version Code style: black

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

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

Donation❤️

If you like this package you can buy me a cup of coffee ☕️.

You can pay using آپ Application by scanning following qrcode in the application or entering code 95656781:

NeshanPardakht

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tehran-stocks-0.8.0.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

tehran_stocks-0.8.0.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file tehran-stocks-0.8.0.1.tar.gz.

File metadata

  • Download URL: tehran-stocks-0.8.0.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6

File hashes

Hashes for tehran-stocks-0.8.0.1.tar.gz
Algorithm Hash digest
SHA256 79f5adc33f126a5b2b6992a881f8de7c2fa24d49f4d8737f05a6343cd7107b08
MD5 40d4817f93f95978282a652dd866179c
BLAKE2b-256 f0b90f8fbe3e037d7d41c217edcf35d9c33ce037ba2657be6c45a628503e0730

See more details on using hashes here.

File details

Details for the file tehran_stocks-0.8.0.1-py3-none-any.whl.

File metadata

  • Download URL: tehran_stocks-0.8.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6

File hashes

Hashes for tehran_stocks-0.8.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 849b5b3c9e89267ac4369342bec4c7a89c4c1445cf2bde5288b23b69083017e4
MD5 0cad3ae99753a2692dbdbb6c7cb89f84
BLAKE2b-256 cb941e5a779d1a2e8e697eaea9f9a6521ce6898289e406a91d812bb53441adb2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page