Package: shoonyapy
Shoonya Trading APIsUnofficial Python Trading APIs for Finvasia Shoonya Platform.To support this project consider opening account withfinvasia.comwiththis referral link.Finvasiaoffers Zero Brokerage trading and is doing good recently with it's new Shoonya platform.Please checkshoonyaweb platform.Support this work by opening account withFinvasiaWORK IS STILL IN PROGRESSUSE AT YOUR OWN RISK, DO NOT EXPECT 100% PERFECT DATAUSE ONLY DURING LIVE MARKETTHIS API DOES NOT WORK ON SATURDAY SUNDAYDataApi MAY WORK ON WEEKENDS WITH FEW EXCEPTIONSDocumentation is incomplete expect bugs and send pull requestsInstallationPython version>3.9is needed for this module to workGit is required for below command to workpip install git+https://gitlab.com/algo2t/shoonyapy.gitAlternate way to installPython version>3.9is needed for this module to workDownload the wheel fromreleasespython -m pip install shoonyapy-0.1.0-py3-none-any.whlHow to setup a good environmentInstall latest Python version 3.9.x, download it fromhereLinux comes with python upgrade it to latest version 3.9.xUsescoop.shfor Windows as package manager.Use your favorite editor likeVSCodiumorVSCodedownload it fromhereVScode is available for Windows, Linux and MacPython extension for vscode ishereMagicPython is also good extensionWonderful documentation for working with python and vscode ishereUse virtualenv to create a virtual python env so that your system is not affectedSteps for virtualenv creation -python -m pip install virtualenvand then virtualenv venvActivate thevenv=>.\venv\Scripts\activate(this is an example for Windows OS)Install and upgrade modules(venv) PS D:\trading\algo2trade\shoonya> python -m pip install -U pip wheel setuptools pylint rope autopep8UsageCreating aconfig.pyexampleusername='FA12345'password='FinvAsia@P123'# Date of Birth format is dd-MM-yyyy e.g 29-06-1984pan_or_dob='ABCDE1234Z'Login or Using DataApi and ShoonyaApifromshoonyapyimportShoonyaApi,DataApiimportloggingimportconfigfromdatetimeimportdatetimeasdtfromtimeimportsleepimportpandasaspdlogging.basicConfig(level=logging.DEBUG)begin=dt.now()print(begin)data=DataApi()shoonya=ShoonyaApi(config.username,config.password,config.pan_or_dob,debug=True)sbin=data.get_instrument_by_exchange_symbol('NSE','SBIN')order_no=shoonya.place_order(sbin,1,order_type=shoonya.ORDER_TYPE_LIMIT,price=472,product=shoonya.PRODUCT_INTRADAY,txn_type=shoonya.TRANSACTION_TYPE_SELL,is_amo=False)df=shoonya.orders()df=df.loc[df['status'].str.contains('Pending'),['order_no','status','segment','product']]print(df)end=dt.now()duration=end-beginprint(end)print(f"milliseconds taken ::{duration.microseconds/1000}")API Short DocumentationModify Orders API is still underdevelopment so do not use it.List Orders or Order Bookshoonya.orders()Order History or Order Detailsshoonya.order_history(order_no, segment)List Trades or Trade Bookshoonya.trades()Trade History or Trade Detailsshoonya.trade_history()Holdingsshoonya.holdings()Net Position or Positionsshoonya.positions()Fund Limit or Funds - NOT WORKINGshoonya.funds()Order Management APIsPlace Bracket Orderinst=data.get_instrument_by_exchange_symbol('MCX','GOLDPETAL21AUGFUT')print(data.ltp(inst).ltp)order_no=shoonya.place_bracket_order(inst,shoonya.TRANSACTION_TYPE_BUY,\shoonya.ORDER_TYPE_MARKET,1,0,0,2,1)inst=data.get_instrument_by_exchange_symbol('NSE','SBIN')order_no=shoonya.place_bracket_order(inst,shoonya.TRANSACTION_TYPE_BUY,\shoonya.ORDER_TYPE_LIMIT,quantity=1,price=450,profit=2,stoploss=10)print(order_no)Exit Bracket Orderbo_exit=shoonya.exit_bracket_order(order_no,shoonya.SEGMENT_COMMODITY)print(bo_exit)Square Off All Positionsshoonya.square_off_all()Square Off Symbol Positionsinst=data.get_instrument_by_exchange_symbol('NSE','SBIN')shoonya.square_off_symbol(instrument.symbol)Exit Pending Ordersshoonya.exit_pending_orders()Place Orderdata=DataApi()inst=data.get_instrument_by_exchange_symbol(exchange,symbol)print(inst)order_no=shoonya.place_order(inst,quantity,price,is_amo=True)print(order_no)Cancel Ordershoonya.cancel_order(order_no, shoonya.SEGMENT_COMMODITY)Market Statusshoonya=ShoonyaApi(config.username,config.password,config.pan_or_dob,debug=True)shoonya.market_status(exchange='MCX')shoonya.market_status(mkt_type=shoonya.MARKET_TYPE_OL)shoonya.market_status(mkt_type='')shoonya.market_status(exchange=shoonya.EXCHANGE_NSE,segment=shoonya.SEGMENT_DERIVATIVE,mkt_type=shoonya.MARKET_TYPE_NL)DataApi example for Indices Nifty Bank and Nifty 50 no login is requiredfromshoonyapyimportDataApifromdatetimeimportdatetimeasdtfromdatetimeimporttimedeltaastdfromcollectionsimportnamedtupledata=DataApi()Instrument=namedtuple('Instrument',['exchange','segment','token','symbol','name','expiry','lot_size'])inst=Instrument('NSE_INDICES','E','26009','Nifty Bank','Nifty Bank','0001-01-01T00:00:00',0)df=data.history(inst,start_time=dt.today()-td(days=5))print(df)inst=Instrument('NSE_INDICES','E','26000','Nifty 50','Nifty Bank','0001-01-01T00:00:00',0)# Default end_time is todaydf=data.history(inst,start_time=dt.today()-td(days=5))print(df)df=data.history(inst,start_time=dt.today()-td(days=5),end_time=dt.today()-td(days=3),interval=15)print(df)Types of Exchangesshoonya.EXCHANGE_NSEshoonya.EXCHANGE_BSEshoonya.EXCHANGE_MCXTypes of Segmentsshoonya.SEGMENT_EQUITYshoonya.SEGMENT_DERIVATIVEshoonya.SEGMENT_CURRENCYshoonya.SEGMENT_COMMODITYTypes of Transactionsshoonya.TRANSACTION_TYPE_BUYshoonya.TRANSACTION_TYPE_SELLTypes of Productsshoonya.PRODUCT_NORMALshoonya.PRODUCT_INTRADAYshoonya.PRODUCT_MARGINshoonya.PRODUCT_BOshoonya.PRODUCT_COshoonya.PRODUCT_CNCshoonya.PRODUCT_MTFTypes of Marketsshoonya.MARKET_TYPE_NLshoonya.MARKET_TYPE_OLshoonya.MARKET_TYPE_AUshoonya.MARKET_TYPE_SPshoonya.MARKET_TYPE_A1shoonya.MARKET_TYPE_A2ContributingYou can contribute to the project by submitting issues, merge requests, etc.
Documentation updates or WiKi Updates can be suggested by users.DonationsFor any donations, please connect with the author.Authors and acknowledgmentThanks to people who motivated to create this project.Thanks Finvasia / Shoonya Team for providing API DocumentationDependenciesPythonrequestsPythonpandasPythongetmacLicenseThis project is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
Free distribution is allowed.Project statusThis project is a hobby project and must not be considered as legally bonded with Finvasia.
In case, you want to support this project consider opening account withfinvasia.comwiththis referral link.