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 Python algo on Zerodha Kite Connect from a VPS in India: 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.
What you need before you start
- A Zerodha account and a Kite Connect developer app. Check Zerodha’s current pricing, limits and terms on their developer site, because they change.
- Your API key and API secret from that app.
- A Linux VPS. Ubuntu 24.04 works well. One script runs fine on Cloud Nano or Cloud XS, and several scripts or heavier data work suit Cloud VPS S. See how much RAM and CPU a VPS needs.
- Basic Python knowledge.
Why use a VPS for an algo
- Always on: your script does not depend on your home power or Wi-Fi.
- A stable IP: every GigaNodes VPS includes a dedicated IPv4 address. Brokers increasingly ask for a registered static IP for API orders, so check your broker’s current rules and register the address if required.
- Control: you choose the Python version, scheduling and monitoring.
- Location: choose the data centre closest to the services you use and measure it yourself. See VPS in Mumbai and Noida.
For a broader comparison of hosting choices for traders, read our algo trading VPS guide and best VPS for algo trading in India. If you trade forex through MetaTrader instead, see the forex VPS page.
Step 1: prepare the server
Log in over SSH, create a normal user, and secure the server first. Follow our Linux VPS hardening checklist, then set the timezone to match the market:
sudo apt update && sudo apt upgrade -y
sudo timedatectl set-timezone Asia/Kolkata
sudo apt install -y python3-venv python3-pip
sudo adduser algo
If you are new to the commands, keep our Linux commands cheat sheet open.
Step 2: create a virtual environment
Switch to the new user and install the official Kite Connect library in an isolated environment.
sudo -iu algo
mkdir -p ~/bot && cd ~/bot
python3 -m venv venv
source venv/bin/activate
pip install kiteconnect python-dotenv
Step 3: store secrets safely
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.
cat > ~/bot/.env <<'EOF'
KITE_API_KEY=your_api_key_here
KITE_API_SECRET=your_api_secret_here
DRY_RUN=1
EOF
chmod 600 ~/bot/.env
Step 4: the access token
Kite access tokens are short-lived, and generating one requires you to log in through Zerodha’s official login flow. Do not store your Zerodha password in a script, and check Zerodha’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.
touch ~/.kite_token && chmod 600 ~/.kite_token
Step 5: a minimal script that connects and reads a price
This script only reads data. Run it first to confirm everything works, before you add any order logic.
# ~/bot/check.py
import os
from dotenv import load_dotenv
from kiteconnect import KiteConnect
load_dotenv()
kite = KiteConnect(api_key=os.environ["KITE_API_KEY"])
kite.set_access_token(open(os.path.expanduser("~/.kite_token")).read().strip())
print("Logged in as:", kite.profile()["user_name"])
print(kite.ltp(["NSE:INFY"]))
cd ~/bot && source venv/bin/activate && python check.py
Step 6: build safety rails before any order
Most algo losses come from bugs, not strategy. Put these limits in code before you place a single live order:
- A dry-run switch. With
DRY_RUN=1the bot logs what it would do and sends nothing. - Hard limits. Maximum quantity per order, maximum orders per day and a maximum daily loss, after which the bot stops.
- A kill switch. A file or command that stops the bot immediately.
- Market hours and holidays. Run only in the trading window and skip exchange holidays.
- Idempotency. Never place the same order twice because of a retry.
# order helper with a dry-run guard
def place(kite, symbol, qty, side):
if os.environ.get("DRY_RUN", "1") == "1":
print("DRY RUN:", side, qty, symbol)
return None
return kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NSE,
tradingsymbol=symbol,
transaction_type=(kite.TRANSACTION_TYPE_BUY if side == "BUY"
else kite.TRANSACTION_TYPE_SELL),
quantity=qty,
product=kite.PRODUCT_MIS,
order_type=kite.ORDER_TYPE_MARKET,
)
Test with dry-run on for several days and, if your broker allows, with the smallest possible quantity before scaling anything.
Step 7: run it as a service
A systemd service restarts your bot if it crashes and starts it when the server reboots. Create /etc/systemd/system/algo.service as root:
[Unit]
Description=Python algo bot
After=network-online.target
[Service]
User=algo
WorkingDirectory=/home/algo/bot
ExecStart=/home/algo/bot/venv/bin/python /home/algo/bot/main.py
Restart=on-failure
RestartSec=10
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now algo
sudo journalctl -u algo -f # watch the logs
To start and stop around market hours instead, use cron: 15 9 * * 1-5 systemctl start algo and 35 15 * * 1-5 systemctl stop algo, adjusting for your strategy.
Step 8: logging and alerts
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 bot hosting guide shows how to keep one online.
Latency: measure, do not assume
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.
curl -o /dev/null -s -w "%{time_total}s\n" https://api.kite.trade
If your strategy depends on consistent speed, a plan with reserved CPU may help. See the virtual dedicated server page and dedicated servers for algo and forex trading.
Common mistakes
- Putting API keys in code or in a public repository.
- Skipping dry-run and testing with real money on day one.
- No maximum order size, so a bug sends a huge order.
- Ignoring that the access token expires daily.
- No alerts, so a crashed bot goes unnoticed for hours.
- Running as root instead of a limited user.
Which VPS plan should you pick?
- One script: Cloud Nano or Cloud XS. See what you can run on a ₹600 VPS.
- Several scripts or data work: Cloud VPS S or higher.
- Consistent CPU: a VDS with reserved cores.
Compare plans on the VPS India page. New VPS customers get a 48-hour money-back guarantee as account credit, so you can test your setup before committing.
Frequently asked questions
Can I run a Kite Connect algo on a VPS?
Yes, a VPS is a common place to run one. Follow Zerodha’s current terms for the API, and check whether your broker requires a registered static IP for API orders.
Do I need a static IP?
Brokers and exchanges have been tightening API rules for retail algo trading. Check your broker’s current requirements. Every GigaNodes VPS includes a dedicated IPv4 address you can register if needed.
How big a VPS do I need for one trading script?
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 sizing guide.
How do I handle the daily access token?
Complete Zerodha’s official login each trading day and save the token to a protected file your bot reads. Do not store your password in code.
Is this financial advice?
No. It is a technical guide. You are responsible for your strategy, risk limits and compliance with your broker’s and the exchange’s rules.
Next steps
Choose a server on the VPS India page and harden it with our security checklist. For more on running code on a VPS, see Node.js and Python apps on a VPS. For the wider picture, start with our VPS buyer’s guide.



