{"id":296,"date":"2026-10-29T17:02:58","date_gmt":"2026-10-29T17:02:58","guid":{"rendered":"https:\/\/giganodes.host\/blog\/python-algo-zerodha-kite-connect-vps-india"},"modified":"2026-10-29T17:02:58","modified_gmt":"2026-10-29T17:02:58","slug":"python-algo-zerodha-kite-connect-vps-india","status":"publish","type":"post","link":"https:\/\/giganodes.host\/blog\/python-algo-zerodha-kite-connect-vps-india","title":{"rendered":"Run a Python Algo on Zerodha Kite Connect from a VPS (India)"},"content":{"rendered":"<div class=\"qa\"><strong>Quick answer:<\/strong> put your Python trading script on an always-on Ubuntu VPS, store your Kite Connect API key in a locked-down environment file, keep the daily access token in a protected file, add a dry-run switch and hard order limits, and run it as a systemd service so it restarts after a crash or reboot. A small plan (1 to 2 vCores, 2 to 4 GB) is enough for one script. This is a technical guide, not investment advice. Check Zerodha&#8217;s current Kite Connect terms, pricing and API rules before you trade live.<\/div>\n<p>Running a trading script on your laptop means it stops when the laptop sleeps, the Wi-Fi drops or the power goes. A VPS keeps it running all day and gives it a stable IP address. This guide shows how to set up a <strong>Python algo on Zerodha Kite Connect from a VPS in India<\/strong>: server setup, secrets, a minimal working script, running it as a service, and the safety rails you should build before sending a real order. It is a general technical walkthrough, and nothing here is a trading strategy or financial advice.<\/p>\n<h2>What you need before you start<\/h2>\n<ul>\n<li>A Zerodha account and a Kite Connect developer app. Check Zerodha&#8217;s current pricing, limits and terms on their developer site, because they change.<\/li>\n<li>Your <strong>API key<\/strong> and <strong>API secret<\/strong> from that app.<\/li>\n<li>A Linux VPS. Ubuntu 24.04 works well. One script runs fine on <strong>Cloud Nano or Cloud XS<\/strong>, and several scripts or heavier data work suit Cloud VPS S. See <a href=\"https:\/\/giganodes.host\/blog\/how-much-ram-cpu-does-vps-need\">how much RAM and CPU a VPS needs<\/a>.<\/li>\n<li>Basic Python knowledge.<\/li>\n<\/ul>\n<h2>Why use a VPS for an algo<\/h2>\n<ul>\n<li><strong>Always on:<\/strong> your script does not depend on your home power or Wi-Fi.<\/li>\n<li><strong>A stable IP:<\/strong> every GigaNodes VPS includes a dedicated IPv4 address. Brokers increasingly ask for a registered static IP for API orders, so check your broker&#8217;s current rules and register the address if required.<\/li>\n<li><strong>Control:<\/strong> you choose the Python version, scheduling and monitoring.<\/li>\n<li><strong>Location:<\/strong> choose the data centre closest to the services you use and measure it yourself. See <a href=\"https:\/\/giganodes.host\/vps\/india\/mumbai\">VPS in Mumbai<\/a> and <a href=\"https:\/\/giganodes.host\/vps\/india\/noida\">Noida<\/a>.<\/li>\n<\/ul>\n<p>For a broader comparison of hosting choices for traders, read our <a href=\"https:\/\/giganodes.host\/blog\/algo-trading-vps-india\">algo trading VPS guide<\/a> and <a href=\"https:\/\/giganodes.host\/blog\/best-vps-for-algo-trading-india\">best VPS for algo trading in India<\/a>. If you trade forex through MetaTrader instead, see the <a href=\"https:\/\/giganodes.host\/vps\/india\/forex-vps\">forex VPS page<\/a>.<\/p>\n<h2>Step 1: prepare the server<\/h2>\n<p>Log in over SSH, create a normal user, and secure the server first. Follow our <a href=\"https:\/\/giganodes.host\/blog\/linux-vps-security-hardening-in-india\">Linux VPS hardening checklist<\/a>, then set the timezone to match the market:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y\nsudo timedatectl set-timezone Asia\/Kolkata\nsudo apt install -y python3-venv python3-pip\nsudo adduser algo<\/code><\/pre>\n<p>If you are new to the commands, keep our <a href=\"https:\/\/giganodes.host\/blog\/linux-vps-commands-cheat-sheet-india\">Linux commands cheat sheet<\/a> open.<\/p>\n<h2>Step 2: create a virtual environment<\/h2>\n<p>Switch to the new user and install the official Kite Connect library in an isolated environment.<\/p>\n<pre><code>sudo -iu algo\nmkdir -p ~\/bot &amp;&amp; cd ~\/bot\npython3 -m venv venv\nsource venv\/bin\/activate\npip install kiteconnect python-dotenv<\/code><\/pre>\n<h2>Step 3: store secrets safely<\/h2>\n<p>Never write your API key or secret directly in code, and never commit them to a repository. Put them in a file only your user can read.<\/p>\n<pre><code>cat &gt; ~\/bot\/.env &lt;&lt;'EOF'\nKITE_API_KEY=your_api_key_here\nKITE_API_SECRET=your_api_secret_here\nDRY_RUN=1\nEOF\nchmod 600 ~\/bot\/.env<\/code><\/pre>\n<h2>Step 4: the access token<\/h2>\n<p>Kite access tokens are short-lived, and generating one requires you to log in through Zerodha&#8217;s official login flow. Do not store your Zerodha password in a script, and check Zerodha&#8217;s current policy before you automate anything around login. A common, simple pattern is to complete the official login once each trading day, write the resulting access token to a protected file, and have your bot read it from there.<\/p>\n<pre><code>touch ~\/.kite_token &amp;&amp; chmod 600 ~\/.kite_token<\/code><\/pre>\n<h2>Step 5: a minimal script that connects and reads a price<\/h2>\n<p>This script only reads data. Run it first to confirm everything works, before you add any order logic.<\/p>\n<pre><code># ~\/bot\/check.py\nimport os\nfrom dotenv import load_dotenv\nfrom kiteconnect import KiteConnect\n\nload_dotenv()\nkite = KiteConnect(api_key=os.environ[\"KITE_API_KEY\"])\nkite.set_access_token(open(os.path.expanduser(\"~\/.kite_token\")).read().strip())\n\nprint(\"Logged in as:\", kite.profile()[\"user_name\"])\nprint(kite.ltp([\"NSE:INFY\"]))<\/code><\/pre>\n<pre><code>cd ~\/bot &amp;&amp; source venv\/bin\/activate &amp;&amp; python check.py<\/code><\/pre>\n<h2>Step 6: build safety rails before any order<\/h2>\n<p>Most algo losses come from bugs, not strategy. Put these limits in code before you place a single live order:<\/p>\n<ul>\n<li><strong>A dry-run switch.<\/strong> With <code>DRY_RUN=1<\/code> the bot logs what it would do and sends nothing.<\/li>\n<li><strong>Hard limits.<\/strong> Maximum quantity per order, maximum orders per day and a maximum daily loss, after which the bot stops.<\/li>\n<li><strong>A kill switch.<\/strong> A file or command that stops the bot immediately.<\/li>\n<li><strong>Market hours and holidays.<\/strong> Run only in the trading window and skip exchange holidays.<\/li>\n<li><strong>Idempotency.<\/strong> Never place the same order twice because of a retry.<\/li>\n<\/ul>\n<pre><code># order helper with a dry-run guard\ndef place(kite, symbol, qty, side):\n    if os.environ.get(\"DRY_RUN\", \"1\") == \"1\":\n        print(\"DRY RUN:\", side, qty, symbol)\n        return None\n    return kite.place_order(\n        variety=kite.VARIETY_REGULAR,\n        exchange=kite.EXCHANGE_NSE,\n        tradingsymbol=symbol,\n        transaction_type=(kite.TRANSACTION_TYPE_BUY if side == \"BUY\"\n                          else kite.TRANSACTION_TYPE_SELL),\n        quantity=qty,\n        product=kite.PRODUCT_MIS,\n        order_type=kite.ORDER_TYPE_MARKET,\n    )<\/code><\/pre>\n<p>Test with dry-run on for several days and, if your broker allows, with the smallest possible quantity before scaling anything.<\/p>\n<h2>Step 7: run it as a service<\/h2>\n<p>A systemd service restarts your bot if it crashes and starts it when the server reboots. Create <code>\/etc\/systemd\/system\/algo.service<\/code> as root:<\/p>\n<pre><code>[Unit]\nDescription=Python algo bot\nAfter=network-online.target\n\n[Service]\nUser=algo\nWorkingDirectory=\/home\/algo\/bot\nExecStart=\/home\/algo\/bot\/venv\/bin\/python \/home\/algo\/bot\/main.py\nRestart=on-failure\nRestartSec=10\nEnvironment=PYTHONUNBUFFERED=1\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<pre><code>sudo systemctl daemon-reload\nsudo systemctl enable --now algo\nsudo journalctl -u algo -f      # watch the logs<\/code><\/pre>\n<p>To start and stop around market hours instead, use cron: <code>15 9 * * 1-5 systemctl start algo<\/code> and <code>35 15 * * 1-5 systemctl stop algo<\/code>, adjusting for your strategy.<\/p>\n<h2>Step 8: logging and alerts<\/h2>\n<p>Log every decision and every order response. Send yourself an alert when something goes wrong, such as a rejected order or a crash. A Telegram bot is a simple option, and our <a href=\"https:\/\/giganodes.host\/blog\/discord-bot-vps-hosting-india\">bot hosting guide<\/a> shows how to keep one online.<\/p>\n<h2>Latency: measure, do not assume<\/h2>\n<p>Advertised numbers are not your numbers. Measure the round trip from your VPS to the API you use, at different times of day, and compare data centres if it matters to your strategy.<\/p>\n<pre><code>curl -o \/dev\/null -s -w \"%{time_total}s\\n\" https:\/\/api.kite.trade<\/code><\/pre>\n<p>If your strategy depends on consistent speed, a plan with reserved CPU may help. See the <a href=\"https:\/\/giganodes.host\/vps\/india\/virtual-dedicated-server\">virtual dedicated server page<\/a> and <a href=\"https:\/\/giganodes.host\/blog\/dedicated-server-forex-algo-trading-india\">dedicated servers for algo and forex trading<\/a>.<\/p>\n<h2>Common mistakes<\/h2>\n<ul>\n<li>Putting API keys in code or in a public repository.<\/li>\n<li>Skipping dry-run and testing with real money on day one.<\/li>\n<li>No maximum order size, so a bug sends a huge order.<\/li>\n<li>Ignoring that the access token expires daily.<\/li>\n<li>No alerts, so a crashed bot goes unnoticed for hours.<\/li>\n<li>Running as root instead of a limited user.<\/li>\n<\/ul>\n<h2>Which VPS plan should you pick?<\/h2>\n<ul>\n<li><strong>One script:<\/strong> Cloud Nano or Cloud XS. See <a href=\"https:\/\/giganodes.host\/blog\/what-can-you-run-on-a-600-rupee-vps\">what you can run on a \u20b9600 VPS<\/a>.<\/li>\n<li><strong>Several scripts or data work:<\/strong> Cloud VPS S or higher.<\/li>\n<li><strong>Consistent CPU:<\/strong> a VDS with reserved cores.<\/li>\n<\/ul>\n<p>Compare plans on the <a href=\"https:\/\/giganodes.host\/vps\/india\">VPS India page<\/a>. New VPS customers get a 48-hour money-back guarantee as account credit, so you can test your setup before committing.<\/p>\n<h2>Frequently asked questions<\/h2>\n<h3>Can I run a Kite Connect algo on a VPS?<\/h3>\n<p>Yes, a VPS is a common place to run one. Follow Zerodha&#8217;s current terms for the API, and check whether your broker requires a registered static IP for API orders.<\/p>\n<h3>Do I need a static IP?<\/h3>\n<p>Brokers and exchanges have been tightening API rules for retail algo trading. Check your broker&#8217;s current requirements. Every GigaNodes VPS includes a dedicated IPv4 address you can register if needed.<\/p>\n<h3>How big a VPS do I need for one trading script?<\/h3>\n<p>A small plan with 1 to 2 vCores and 2 to 4 GB of RAM is usually enough for a single script. Measure your own usage with the tips in our <a href=\"https:\/\/giganodes.host\/blog\/how-much-ram-cpu-does-vps-need\">sizing guide<\/a>.<\/p>\n<h3>How do I handle the daily access token?<\/h3>\n<p>Complete Zerodha&#8217;s official login each trading day and save the token to a protected file your bot reads. Do not store your password in code.<\/p>\n<h3>Is this financial advice?<\/h3>\n<p>No. It is a technical guide. You are responsible for your strategy, risk limits and compliance with your broker&#8217;s and the exchange&#8217;s rules.<\/p>\n<h2>Next steps<\/h2>\n<p>Choose a server on the <a href=\"https:\/\/giganodes.host\/vps\/india\">VPS India page<\/a> and harden it with our <a href=\"https:\/\/giganodes.host\/blog\/linux-vps-security-hardening-in-india\">security checklist<\/a>. For more on running code on a VPS, see <a href=\"https:\/\/giganodes.host\/blog\/vps-for-nodejs-and-python-apps-in-india\">Node.js and Python apps on a VPS<\/a>. For the wider picture, start with our <a href=\"https:\/\/giganodes.host\/blog\/best-vps-hosting-india\">VPS buyer&#8217;s guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Server setup, secrets, safety rails and a systemd service for a Python algo on Kite Connect.<\/p>\n","protected":false},"author":2,"featured_media":299,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,14],"tags":[289,291,176,290],"class_list":["post-296","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-vps-hosting","tag-algo-trading","tag-python","tag-vps-india","tag-zerodha"],"_links":{"self":[{"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":0,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/media\/299"}],"wp:attachment":[{"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giganodes.host\/blog\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}