Package: tehran-stocks
Tehran Stock Market بورس تهران در پایتونA python package that helps to access TSETMC stock price history, Using OOP InterfaceFeaturesDownload All stocks pricesDownload prices from a group (i.e ETFs or cars, etc.)Download Price history of one specific StockAfter first setup available offline.CommandLine InterfaceExport data to csv, excel or Stata(dta)Compatible withsqlalchemyCompatible withPANDASBased on lightsqliteTable of Contents1. Tehran Stock Market بورس تهران در پایتون1.1. Features1.2. Table of Contents2. Usage2.1. - Install2.2. - Initialization2.2.1. -1 Command line2.2.2. -2 Python2.3. - Download and Update prices2.3.1. -1 Command line2.3.2. -2 Python2.4. - Access Data2.4.1. -1 Search Stocks2.4.2. -2 Get Instant price and more details:2.5. - Custom Database2.6. Todo3. Support❤️Usage0 - Installpipinstalltehran_stocks1- InitializationFor first use you need initialize the database1-1 Command linets-getinit# Set up to sqlite database1-2 Pythonimporttehran_stocks# On first import package initialize itselfDuring initialization you will prompt for downloading all prices. if you answer yes it will download all prices, otherwise you can download data2- Download and Update prices2-1 Command linets-getupdate# update  all price , or download all if no price existts-getgroup34## 34 is the code for car's group.ts-getget_groups## get group name and group codes2-2 Pythonfromtehran_stocksimportget_all_price,Stocks,update_groupget_all_price()# download and(or) update all pricesupdate_group(34)#download and(or) update Stocks in groupCode = 34 (Cars)Stocks.get_group()# to see list of group codes3- Access DataTo access data you can useStockswhich is an customizedsqlalchemyobject, which helps you to find prices on an easy way.3-1 Search Stocksfromtehran_stocksimportStocks,db# You can use query to find stocksstock=Stocks.query.filter_by(name='كگل').first()#find by symbol(نماد)stock=Stocks.query.filter_by(code='35700344742885862').first()# find by code on tsetmc urlstock=Stocks.query.filter(Stocks.title.like('%گل گهر%')).first()# Search by titlestock_list=Stocks.query.filter_by(group_code=34).all()# find all Stocks in Khodrostock_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 sqldb.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 withpandasdataframes:# use data as a pandas dataframe>>>stock.df#idcodetickerdtyyyymmddfirsthighlowclosevaluevolopenintperopenlastdate02249135700344742885862Gol-E-Gohar.2004082912000.012021.012000.012000.01884160500015700002708D12000.012000.02004-08-29>>>stock.summary()Startdate:2004/08/29Enddate:2019/07/14Totaldays: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')3-2 Get Instant price and more details:>>>stock.get_instant_detail(){'time':'12:29:57','last_price':'12950','last_close':'13060','last_high':'13300','last_low':'13130','last_open':'13330','trade_count':'12760','trade_volume':'1140','trade_value':'4671236','market_cap':'60715047900','date_string':'20220404','time_string':'122957'}# get change in share count>>>stock.get_shares_history()datenew_sharesold_sharesgdate01400-12-0800:00:00200.000B100.000B2022-02-2711400-04-2000:00:00100.000B74.400B2021-07-11# get change in price ~ dividend, split, etc.>>stock.get_dividend()dateafterbeforedividendgdate01400-04-1600:00:00187702007013002021-07-0711399-04-1800:00:0016350172509002020-07-08)4- Custom DatabaseYou can change the default database by updating the config file on:~/.tse/config.yml#unix MacOS/LinuxC:\Users\User\{USERNAME}\.tse\config.yml#WindowsCustom Config for postgresql (you may need to installpyscopg2):database:database:stocksengine:postgresqlhost:localhostpassword:passwordport:5432user:postgresTodoCreate DatabaseDownload DataCommandLine SupportJalali SupportInstant DataCustom databaseSupport❤️If you like this package you can buy me a cup of coffee ☕️.IDPAYSubscribe and share my youtube channel