Package: kiteconnect
The Kite Connect API Python client - v4The official Python client for communicating with theKite Connect API.Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection.Zerodha Technology(c) 2021. Licensed under the MIT License.DocumentationPython client documentationKite Connect HTTP API documentationv4 - Breaking changesRenamed ticker fields as perkite connect docRenamedbsecdstobcdinticker.EXCHANGE_MAPv5 - Breaking changesDrop Support for Python 2.7: Starting from version v5, support for Python 2.7 has been discontinued. This decision was made due to theannouncementbysetup-python, which stopped supporting Python 2.x since May 2023.For Python 2.x Users: If you are using Python 2.x, you can continue using thekiteconnectlibrary, but please stick to the <= 4.x.x versions of the library. You can find the previous releases on thePyKiteConnect GitHub Releasespage.Installing the clientYou can install the pre release via pippip install --upgrade kiteconnectIts recommended to updatesetuptoolsto latest if you are facing any issue while installingpip install -U pip setuptoolsSince some of the dependencies uses C extensions it has to compiled before installing the package.Linux, BSD and macOSOn Linux, and BSDs, you will need a C compiler (such as GCC).Debian/Ubuntuapt-get install libffi-dev python-dev python3-devCentos/RHEL/Fedorayum install libffi-devel python3-devel python-develmacOS/OSxxcode-select --installMicrosoft WindowsEach Python version uses a specific compiler version (e.g. CPython 2.7 uses Visual C++ 9.0, CPython 3.3 uses Visual C++ 10.0, etc). So, you need to install the compiler version that corresponds to your Python versionPython 2.6, 2.7, 3.0, 3.1, 3.2 -Microsoft Visual C++ 9.0Python 3.3, 3.4 -Microsoft Visual C++ 10.0Python 3.5, 3.6 -Microsoft Visual C++ 14.0For more details checkofficial Python documentation.API usageimportloggingfromkiteconnectimportKiteConnectlogging.basicConfig(level=logging.DEBUG)kite=KiteConnect(api_key="your_api_key")# Redirect the user to the login url obtained# from kite.login_url(), and receive the request_token# from the registered redirect url after the login flow.# Once you have the request_token, obtain the access_token# as follows.data=kite.generate_session("request_token_here",api_secret="your_secret")kite.set_access_token(data["access_token"])# Place an ordertry:order_id=kite.place_order(tradingsymbol="INFY",exchange=kite.EXCHANGE_NSE,transaction_type=kite.TRANSACTION_TYPE_BUY,quantity=1,variety=kite.VARIETY_AMO,order_type=kite.ORDER_TYPE_MARKET,product=kite.PRODUCT_CNC,validity=kite.VALIDITY_DAY)logging.info("Order placed. ID is:{}".format(order_id))exceptExceptionase:logging.info("Order placement failed:{}".format(e.message))# Fetch all orderskite.orders()# Get instrumentskite.instruments()# Place an mutual fund orderkite.place_mf_order(tradingsymbol="INF090I01239",transaction_type=kite.TRANSACTION_TYPE_BUY,amount=5000,tag="mytag")# Cancel a mutual fund orderkite.cancel_mf_order(order_id="order_id")# Get mutual fund instrumentskite.mf_instruments()Refer to thePython client documentationfor the complete list of supported methods.WebSocket usageimportloggingfromkiteconnectimportKiteTickerlogging.basicConfig(level=logging.DEBUG)# Initialisekws=KiteTicker("your_api_key","your_access_token")defon_ticks(ws,ticks):# Callback to receive ticks.logging.debug("Ticks:{}".format(ticks))defon_connect(ws,response):# Callback on successful connect.# Subscribe to a list of instrument_tokens (RELIANCE and ACC here).ws.subscribe([738561,5633])# Set RELIANCE to tick in `full` mode.ws.set_mode(ws.MODE_FULL,[738561])defon_close(ws,code,reason):# On connection close stop the main loop# Reconnection will not happen after executing `ws.stop()`ws.stop()# Assign the callbacks.kws.on_ticks=on_tickskws.on_connect=on_connectkws.on_close=on_close# Infinite loop on the main thread. Nothing after this will run.# You have to use the pre-defined callbacks to manage subscriptions.kws.connect()Run unit testspythonsetup.pytestorpytest-stests/unit--cov-reporthtml:cov_html--cov=./Run integration testspytest-stests/integration/--cov-reporthtml:cov_html--cov=./--api-keyapi_key--access-tokenaccess_tokenGenerate documentationpipinstallpdoc

pdoc--html--html-dirdocskiteconnectChangelogCheck release notes