So you’ve dipped your toes into Python. Now let’s look at how the whole algo trading system works when you’re coding it yourself.
Imagine this as a machine with four parts:
Let’s go through these step by step — desi trader style.
To run any strategy, you need market data. This includes:
How do you get this data in Python?
You use APIs — which are like data delivery boys. They bring fresh candles to your code every few seconds or minutes.
There are public APIs (for learning and testing) and broker APIs (for live trading).
Example code:
import yfinance as yf data = yf.download("RELIANCE.NS", period="1d", interval="5m")
This gives you Reliance’s intraday data in 5-min candles — simple!
Now that you have candles, it’s time to check your conditions. Let’s say:
You’ll use Python libraries like ta to calculate RSI and EMA, and then use if-else to write the logic.
if rsi < 30 and price > ema_20: place_order("BUY")
Boom. Your brain → logic → code.
Once your logic says “Buy”, your code has to send an order to your broker.
This is done via broker APIs.
A broker API is a set of tools provided by your broker that allows your program to interact with their trading platform. Through it, you can place trades, fetch live market data, check positions, and manage your portfolio—all directly from your code.
Here’s how it works in practice:
broker.place_order("RELIANCE", "BUY", qty=10)
Don’t worry — each broker provides documentation and sample code.
Once your algo is live, you have to:
You can even get Telegram alerts when your algo trades. Neat, right?
DATA ➝ STRATEGY ➝ ORDER ➝ MONITORING
That’s the loop your algo runs every minute or second — non-stop.
In the next chapter, we’ll show you an actual sample strategy in code — from data to execution — that you can study and modify for your own use.
Excited? Let’s dive into real code!
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. It is not produced by the desk of the Kotak Securities Research Team, nor is it a report published by the Kotak Securities Research Team. The information presented is compiled from several secondary sources available on the internet and may change over time. Investors should conduct their own research and consult with financial professionals before making any investment decisions. Read the full disclaimer here.
Investments in securities market are subject to market risks, read all the related documents carefully before investing. Brokerage will not exceed SEBI prescribed limit. The securities are quoted as an example and not as a recommendation. SEBI Registration No-INZ000200137 Member Id NSE-08081; BSE-673; MSE-1024, MCX-56285, NCDEX-1262.
Explore our comprehensive video library that blends expert market insights with Kotak's innovative financial solutions to support your goals.