DEV Community

Archit Mittal
Archit Mittal

Posted on

I Had My First Automated Trade Running in 47 Minutes — Here's the Exact Setup

A friend called me last week with a familiar problem.

He had been comparing broker API documentation for three days straight. Zerodha versus Fyers versus Upstox versus Angel One. Spreadsheets of feature comparisons. Reddit threads. YouTube reviews. Three days of research, zero lines of code written.

I told him to stop comparing and start building.

By that evening, he had his first automated trade running. A simple bot that auto-squares-off all open positions at 3:15 PM so he never forgets to close before market end. Nothing fancy. But it worked. And it replaced a task that had cost him real money twice in the previous month when he forgot to exit positions manually.

This article is the guide I wish existed when I started automating trades two years ago. No theory. No affiliate links. Just the practical breakdown of how to go from zero to a working trading bot using Python and a broker API.

Why Most People Never Get Past the Research Phase

Here is the pattern I see repeatedly. Someone decides they want to automate their trading. They spend a week reading documentation. They get overwhelmed by the differences between brokers. They bookmark fifteen tutorials. They never write a single line of code.

The problem is not complexity. The problem is that most guides start with the wrong question. They ask "which broker has the best API?" when they should ask "which broker will let me run my first bot today?"

Those are very different questions.

The best API on paper means nothing if the authentication flow takes you a week to figure out. The most feature-rich documentation is useless if the sandbox environment does not match production. I have seen developers with years of experience get stuck for days on OAuth token refresh flows that should take twenty minutes.

The Setup I Actually Use (And Why)

I run four trading bots simultaneously on Fyers API. Here is why I chose it, with specific technical details rather than marketing language.

Authentication that does not fight you. Fyers uses a straightforward OAuth2 flow. You get an app_id and secret_key from their developer portal. The access token generation takes one API call. Compare this to brokers where you need to handle TOTP-based two-factor authentication programmatically — that alone can eat an entire afternoon.

One API for everything you need. Historical data, real-time websocket streaming, order placement, and position management — all through a single REST API with consistent response formats. Some brokers split these across different endpoints with different authentication methods. That means maintaining multiple connection handlers in your code. With a unified API, your codebase stays clean.

Rate limits that make sense for retail. Ten requests per second. If you are a retail algo trader running a few strategies, that is more than enough. I run four bots simultaneously and have never hit the ceiling. For context, even a high-frequency scalping strategy at the retail level rarely needs more than two to three requests per second.

Zero cost for API access. You pay standard brokerage on executed trades. The API itself costs nothing. No monthly subscription. No per-call charges. No premium tier you need to unlock to access historical data. This matters more than people realise — I have seen traders pay $50 to $100 per month for API access on international platforms before they have even validated whether their strategy works.

From Zero to First Bot: The 47-Minute Breakdown

Here is exactly how the timeline broke down when I set up my friend that evening.

Minutes 0 to 8: Developer portal setup. Created an app on Fyers API developer portal. Got the app_id and secret_key. This is a one-time setup — you reuse these credentials for every bot.

Minutes 8 to 15: Authentication script. Wrote a Python script to generate the access token. The Fyers Python SDK (fyers-apiv3) handles most of the heavy lifting. Install it, pass your credentials, get a token. Seven minutes including pip install time.

Minutes 15 to 30: The bot logic. His requirement was simple — check all open positions at 3:15 PM and square them off. That is a position fetch call followed by conditional sell orders. The logic itself was about 30 lines of Python. We wrapped it in a scheduled function using Python's schedule library.

Minutes 30 to 40: Testing with paper trades. Fyers allows you to validate order parameters without actually executing. We tested the flow end to end — fetch positions, generate square-off orders, validate them. Fixed two bugs: one where we were not handling the case of zero open positions, and another where the order type parameter was wrong for market orders.

Minutes 40 to 47: Live deployment. Switched from validation mode to live execution. Ran the bot. Watched it sit idle until 3:15 PM on the next trading day, then cleanly close all three open positions.

Total code: under 60 lines of Python. No frameworks. No Docker containers. No cloud deployment. Just a Python script running on his laptop with a cron job.

The Bots I Run Daily (And What They Actually Do)

Over two years, I have built up to four bots running simultaneously. None of them are complex. The power is in consistency, not sophistication.

Bot 1: The Position Closer. Squares off all positions at 3:15 PM. This was the first bot I ever wrote. It has saved me from forgetting to exit positions at least a dozen times. At an average of $200 to $500 per forgotten exit (in slippage and overnight risk), this single bot has probably saved me $3,000 or more.

Bot 2: The Morning Screener. Runs at 9:16 AM (one minute after market open). Scans a predefined watchlist for stocks that gapped up or down more than two percent from previous close. Sends results to my phone via WhatsApp using a simple webhook. I review the list over my morning coffee instead of staring at a screen for twenty minutes.

Bot 3: The SIP Optimizer. This one runs weekly. Instead of fixed-date SIP investments, it checks the Nifty P/E ratio. If the market is trading below historical average P/E, it invests more. If above average, it invests less. A basic value-averaging approach that anyone with a mutual fund account thinks about but nobody does manually because it is tedious. The total difference over eighteen months has been a 2.3% higher return compared to my fixed-date SIP — which translates to roughly $400 extra on a moderate portfolio.

Bot 4: The Trade Journal. Every executed trade gets logged automatically into a Google Sheet with entry price, exit price, P&L, holding duration, and the strategy tag. At the end of the week, a summary lands in my WhatsApp. I used to maintain this journal manually and abandoned it after two weeks every time. The automated version has been running for fourteen months without a single missed entry.

The Mistakes That Cost Me Real Money

I would be dishonest if I presented this as a smooth journey. Here are the expensive lessons.

Mistake 1: Not handling token expiry. Fyers access tokens expire daily. My first bot worked perfectly for one day and then silently failed the next morning because the token had expired. I only noticed when I checked my positions at 3:30 PM and found them still open. Cost: about $180 in overnight slippage. The fix took ten minutes — a token refresh function that runs at 8:30 AM before market open.

Mistake 2: No circuit breaker. My screener bot once sent me forty-seven WhatsApp messages in three minutes during a market-wide gap event. The fix: a simple counter that caps alerts at five per run and aggregates the rest into a single summary message.

Mistake 3: Trusting backtests blindly. I built a momentum strategy that looked incredible in backtesting — 34% annual returns over five years of historical data. In live trading, it lost 8% in the first month. The backtest did not account for slippage, partial fills, or the fact that the stocks it picked were often illiquid. I shut it down, went back to simple automation, and have not tried to build a "strategy" bot since. My bots automate actions, not decisions. That distinction matters.

When You Should NOT Automate Your Trading

This might be the most important section of this article.

Do not automate your trading strategy if you have not traded it manually for at least three months. Automation amplifies whatever you feed it. If your manual strategy loses money, your automated strategy will lose money faster and more consistently.

Do not automate if you cannot explain every line of your bot's code. I have seen people copy trading bots from GitHub, run them with real money, and then panic when something unexpected happens. If you did not write it, you do not understand it. If you do not understand it, you should not trust it with your money.

Do not start with strategy automation. Start with task automation — the boring stuff like position closing, journaling, and screening. These have near-zero financial risk and teach you the entire API workflow. Once you are comfortable with the plumbing, then consider automating decisions. Most people do this backwards.

Getting Started Today

If you have basic Python knowledge and a trading account, you can have your first bot running this evening. Here is the minimal path.

First, pick one repetitive task you do every trading day. Not a strategy. A task. Closing positions, checking prices, logging trades — something mechanical.

Second, set up API access with your broker. If you are in India, Fyers is my recommendation. If you are international, Interactive Brokers or Alpaca both have solid Python SDKs.

Third, write the smallest possible script that does that one task. Do not add features. Do not handle edge cases yet. Get the core loop working.

Fourth, run it in paper or validation mode for one full week. Watch it. Log what it does. Fix what breaks.

Fifth, go live with small positions. Scale up only after you trust it.

The entire process should take one weekend if you focus. Not three days of comparison shopping. One weekend of building.

The Real Value Is Not the Trades

After two years of running trading bots, here is what I have learned: the money saved from automation is real but it is not the main value. The real value is in the discipline it enforces.

My trade journal has fourteen months of unbroken data because a bot fills it in. My SIP adjustments happen consistently because a script makes them. My positions close on time because code does not forget.

Automation does not make you a better trader. It makes you a more consistent one. And in markets, consistency compounds.


Archit Mittal is the founder of Automate Algos. He helps businesses automate chaos using AI agents and custom workflows. Connect with him on LinkedIn @automate-archit.

Top comments (0)