<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kiteconnect Python on WebNotes</title><link>https://v2.webnotes.in/tags/kiteconnect-python/</link><description>Recent content in Kiteconnect Python on WebNotes</description><generator>Hugo</generator><language>en-IN</language><lastBuildDate>Tue, 12 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://v2.webnotes.in/tags/kiteconnect-python/index.xml" rel="self" type="application/rss+xml"/><item><title>How to authenticate Kite Connect with TOTP automation</title><link>https://v2.webnotes.in/how-to-kite-connect-totp-automation/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-kite-connect-totp-automation/</guid><description>&lt;p&gt;Algo trading scripts need a fresh &lt;code&gt;access_token&lt;/code&gt; every morning before market open. The standard &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-tokens/"&gt;Kite Connect authentication flow&lt;/a&gt;
 requires opening a browser, completing the Zerodha login, and pasting the &lt;code&gt;request_token&lt;/code&gt;. For unattended or server-based strategies, that manual step is a bottleneck. This guide shows how to automate the entire login using &lt;code&gt;pyotp&lt;/code&gt; to generate the TOTP code, eliminating the need for any browser interaction.&lt;/p&gt;
&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Prerequisites&lt;/strong&gt;
 &lt;div class="callout__body"&gt;&lt;ul&gt;
&lt;li&gt;An active Kite Connect subscription (Rs 2,000/month plus GST). See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-api-key/"&gt;How to generate a Kite Connect API key&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;Your &lt;code&gt;api_key&lt;/code&gt;, &lt;code&gt;api_secret&lt;/code&gt;, Zerodha client ID (user ID), and Zerodha account password.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;TOTP secret key&lt;/strong&gt; (the base-32 string shown when you first set up TOTP on your Zerodha account). This is not the six-digit OTP; it is the underlying secret used to generate OTPs.&lt;/li&gt;
&lt;li&gt;Python 3.8 or later and a virtual environment with &lt;code&gt;kiteconnect&lt;/code&gt;, &lt;code&gt;pyotp&lt;/code&gt;, and &lt;code&gt;requests&lt;/code&gt; installed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Important: TOTP secret vs OTP code&lt;/strong&gt;
 &lt;div class="callout__body"&gt;The TOTP &lt;strong&gt;secret&lt;/strong&gt; is the static base-32 key (typically 32 characters, shown once when you enable 2FA on Zerodha&amp;rsquo;s profile page). The &lt;strong&gt;OTP&lt;/strong&gt; is the six-digit code generated from that secret every 30 seconds. You need to store the secret, not a specific OTP.&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--info" role="note"&gt;
 &lt;strong class="callout__label"&gt;Conflict-of-interest disclosure&lt;/strong&gt;
 &lt;div class="callout__body"&gt;WebNotes is an independent knowledge base. This guide is not sponsored by Zerodha or any third party.&lt;/div&gt;
&lt;/aside&gt;

&lt;h2 id="how-totp-automation-works"&gt;How TOTP automation works&lt;/h2&gt;
&lt;p&gt;The standard Kite Connect login involves three steps at Zerodha&amp;rsquo;s end: submit client ID and password, then submit a TOTP OTP, after which Zerodha redirects to your registered URL with a &lt;code&gt;request_token&lt;/code&gt;. A browser performs these steps interactively. Automation replaces the browser with a &lt;code&gt;requests.Session&lt;/code&gt; that sends the same HTTP POST calls, and replaces the TOTP app with &lt;code&gt;pyotp.TOTP(secret).now()&lt;/code&gt; to generate the current OTP.&lt;/p&gt;</description></item><item><title>How to generate the request_token and access_token on Kite Connect</title><link>https://v2.webnotes.in/how-to-generate-kite-connect-tokens/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-generate-kite-connect-tokens/</guid><description>&lt;p&gt;Every &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 session requires a fresh &lt;code&gt;access_token&lt;/code&gt; that is valid for the current trading day. Generating an &lt;code&gt;access_token&lt;/code&gt; involves a two-step OAuth-style flow: the user logs in through Zerodha&amp;rsquo;s browser-based consent screen to obtain a &lt;code&gt;request_token&lt;/code&gt;, and the server then exchanges that &lt;code&gt;request_token&lt;/code&gt;, along with a cryptographic checksum, for an &lt;code&gt;access_token&lt;/code&gt;. This guide explains both steps using the official &lt;a href="https://v2.webnotes.in/how-to-basic-python-kiteconnect-script/"&gt;kiteconnect Python SDK&lt;/a&gt;
.&lt;/p&gt;
&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Prerequisites&lt;/strong&gt;
 &lt;div class="callout__body"&gt;&lt;ul&gt;
&lt;li&gt;An active Kite Connect subscription and a valid &lt;code&gt;api_key&lt;/code&gt; and &lt;code&gt;api_secret&lt;/code&gt;. See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-api-key/"&gt;How to generate a Kite Connect API key&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;Python 3.8 or later installed.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;kiteconnect&lt;/code&gt; package installed: &lt;code&gt;pip install kiteconnect&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The redirect URL registered in your app configured on the developer console.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--info" role="note"&gt;
 &lt;strong class="callout__label"&gt;Conflict-of-interest disclosure&lt;/strong&gt;
 &lt;div class="callout__body"&gt;WebNotes is an independent knowledge base. This guide is not sponsored by Zerodha or any third party.&lt;/div&gt;
&lt;/aside&gt;

&lt;h2 id="how-the-token-flow-works"&gt;How the token flow works&lt;/h2&gt;
&lt;p&gt;Kite Connect&amp;rsquo;s authentication is modelled on OAuth 2.0 with a custom checksum step. The flow has three actors: your application, the user&amp;rsquo;s browser, and Zerodha&amp;rsquo;s API server.&lt;/p&gt;</description></item><item><title>How to migrate from Pi bridge to Kite Connect</title><link>https://v2.webnotes.in/how-to-migrate-pi-bridge-to-kite-connect/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-migrate-pi-bridge-to-kite-connect/</guid><description>&lt;p&gt;&lt;a href="https://v2.webnotes.in/zerodha-pi-discontinuation/"&gt;Zerodha Pi&lt;/a&gt;
 was Zerodha&amp;rsquo;s desktop trading terminal that included a bridge allowing algorithmic strategies written in AFL (AmiBroker Formula Language) or Excel macros to place orders programmatically via a COM/DDE interface. Zerodha discontinued Pi and the Pi bridge, directing users to the &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 as the supported replacement. This guide walks through every step of migrating a Pi bridge-based strategy to Kite Connect, with direct function-level equivalents and rewritten code examples.&lt;/p&gt;</description></item><item><title>How to place an order via the Kite Connect REST API</title><link>https://v2.webnotes.in/how-to-place-order-kite-connect-rest/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-place-order-kite-connect-rest/</guid><description>&lt;p&gt;The &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 exposes a clean REST interface for order management that supports all major Indian exchanges and order types. Once you have a valid &lt;code&gt;access_token&lt;/code&gt; (see &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-tokens/"&gt;How to generate the request_token and access_token&lt;/a&gt;
), you can place, modify, and cancel orders programmatically using the &lt;a href="https://github.com/zerodha/pykiteconnect"&gt;kiteconnect Python SDK&lt;/a&gt;
. This guide covers the full order-placement workflow, parameter reference, and production-grade error handling.&lt;/p&gt;
&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Prerequisites&lt;/strong&gt;
 &lt;div class="callout__body"&gt;&lt;ul&gt;
&lt;li&gt;An active Kite Connect subscription (Rs 2,000/month plus GST). See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-api-key/"&gt;How to generate a Kite Connect API key&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;A valid &lt;code&gt;access_token&lt;/code&gt; for the current trading day. See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-tokens/"&gt;How to generate the request_token and access_token&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;kiteconnect&lt;/code&gt; package installed: &lt;code&gt;pip install kiteconnect&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Python 3.8 or later.&lt;/li&gt;
&lt;li&gt;A funded and active Zerodha trading account with sufficient margin for the intended order.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--info" role="note"&gt;
 &lt;strong class="callout__label"&gt;Conflict-of-interest disclosure&lt;/strong&gt;
 &lt;div class="callout__body"&gt;WebNotes is an independent knowledge base. This guide is not sponsored by Zerodha or any third party. Links to kite.trade and zerodha.com are informational only.&lt;/div&gt;
&lt;/aside&gt;

&lt;h2 id="order-model-in-kite-connect"&gt;Order model in Kite Connect&lt;/h2&gt;
&lt;p&gt;Kite Connect organises every order placement call around four orthogonal dimensions.&lt;/p&gt;</description></item><item><title>How to stream live ticks via Kite WebSocket</title><link>https://v2.webnotes.in/how-to-stream-kite-websocket-ticks/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-stream-kite-websocket-ticks/</guid><description>&lt;p&gt;The &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 provides a binary WebSocket feed for real-time market data through a class called &lt;code&gt;KiteTicker&lt;/code&gt; in the &lt;a href="https://github.com/zerodha/pykiteconnect"&gt;kiteconnect Python SDK&lt;/a&gt;
. Unlike the REST endpoints, which are request-response, &lt;code&gt;KiteTicker&lt;/code&gt; maintains a persistent connection and pushes price updates as they occur. This guide explains how to establish that connection, subscribe to instruments, decode ticks, and handle network interruptions reliably.&lt;/p&gt;
&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Prerequisites&lt;/strong&gt;
 &lt;div class="callout__body"&gt;&lt;ul&gt;
&lt;li&gt;An active Kite Connect subscription (Rs 2,000/month plus GST). See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-api-key/"&gt;How to generate a Kite Connect API key&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;A valid &lt;code&gt;access_token&lt;/code&gt; for the current trading day. See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-tokens/"&gt;How to generate the request_token and access_token&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;kiteconnect&lt;/code&gt; package installed: &lt;code&gt;pip install kiteconnect&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Python 3.8 or later.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--info" role="note"&gt;
 &lt;strong class="callout__label"&gt;Conflict-of-interest disclosure&lt;/strong&gt;
 &lt;div class="callout__body"&gt;WebNotes is an independent knowledge base. This guide is not sponsored by Zerodha or any third party.&lt;/div&gt;
&lt;/aside&gt;

&lt;h2 id="how-the-kiteticker-websocket-works"&gt;How the KiteTicker WebSocket works&lt;/h2&gt;
&lt;p&gt;Kite Connect&amp;rsquo;s WebSocket endpoint at &lt;code&gt;wss://ws.kite.trade&lt;/code&gt; streams binary-encoded tick packets. Each packet contains price, volume, and depth data for one or more instruments. The &lt;code&gt;KiteTicker&lt;/code&gt; class handles the binary decoding, connection lifecycle, and reconnection internally, so your application receives clean Python dictionaries.&lt;/p&gt;</description></item><item><title>How to use postback URLs on Kite Connect</title><link>https://v2.webnotes.in/how-to-use-postback-urls-kite-connect/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-use-postback-urls-kite-connect/</guid><description>&lt;p&gt;The &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 includes a postback (webhook) mechanism that pushes order update notifications to your server the moment an order changes state. Instead of polling &lt;code&gt;GET /orders&lt;/code&gt; repeatedly, your server receives an HTTP POST at the registered postback URL each time an order moves from &lt;code&gt;OPEN&lt;/code&gt; to &lt;code&gt;COMPLETE&lt;/code&gt;, &lt;code&gt;REJECTED&lt;/code&gt;, &lt;code&gt;CANCELLED&lt;/code&gt;, or any intermediate state. This guide covers registration, checksum verification, a Python server implementation, and production hardening.&lt;/p&gt;
&lt;aside class="callout callout--key" role="note"&gt;
 &lt;strong class="callout__label"&gt;Prerequisites&lt;/strong&gt;
 &lt;div class="callout__body"&gt;&lt;ul&gt;
&lt;li&gt;An active Kite Connect subscription (Rs 2,000/month plus GST). See &lt;a href="https://v2.webnotes.in/how-to-generate-kite-connect-api-key/"&gt;How to generate a Kite Connect API key&lt;/a&gt;
.&lt;/li&gt;
&lt;li&gt;A valid &lt;code&gt;api_key&lt;/code&gt; and &lt;code&gt;api_secret&lt;/code&gt;. Postback integrity verification requires the &lt;code&gt;api_secret&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A publicly accessible HTTPS server where Zerodha can deliver POST requests. Zerodha requires HTTPS; plain HTTP postback URLs are not accepted in production.&lt;/li&gt;
&lt;li&gt;Basic familiarity with HTTP servers in Python (Flask or similar).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/aside&gt;

&lt;aside class="callout callout--info" role="note"&gt;
 &lt;strong class="callout__label"&gt;Conflict-of-interest disclosure&lt;/strong&gt;
 &lt;div class="callout__body"&gt;WebNotes is an independent knowledge base. This guide is not sponsored by Zerodha or any third party.&lt;/div&gt;
&lt;/aside&gt;

&lt;h2 id="what-is-a-postback-url"&gt;What is a postback URL?&lt;/h2&gt;
&lt;p&gt;A postback URL is an HTTP POST endpoint you register in the Kite Connect developer console. Whenever an order placed through your app changes state at Zerodha&amp;rsquo;s OMS (Order Management System), Zerodha sends an HTTP POST request to your postback URL with the updated order details in the request body.&lt;/p&gt;</description></item><item><title>How to write a basic Python script using kiteconnect</title><link>https://v2.webnotes.in/how-to-basic-python-kiteconnect-script/</link><pubDate>Tue, 12 May 2026 00:00:00 +0000</pubDate><guid>https://v2.webnotes.in/how-to-basic-python-kiteconnect-script/</guid><description>&lt;p&gt;The &lt;a href="https://github.com/zerodha/pykiteconnect"&gt;kiteconnect Python SDK&lt;/a&gt;
 is the official client library for the &lt;a href="https://v2.webnotes.in/kite-connect-api/"&gt;Kite Connect API&lt;/a&gt;
 from &lt;a href="https://v2.webnotes.in/zerodha/"&gt;Zerodha&lt;/a&gt;
. It wraps every REST endpoint and the WebSocket tick stream into a clean, Pythonic interface. This guide takes you from a blank directory to a working script that authenticates with Kite Connect, fetches your portfolio, queries live market prices, and places a paper-trade-style order. By the end you will have a reusable project structure suitable as the foundation for any algo trading strategy.&lt;/p&gt;</description></item></channel></rss>