<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Shashank</title>
    <description>The latest articles on Forem by Shashank (@shankjbs571).</description>
    <link>https://forem.com/shankjbs571</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1473345%2F64eca346-90a8-49f3-aaa4-ff4d33bc3156.png</url>
      <title>Forem: Shashank</title>
      <link>https://forem.com/shankjbs571</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shankjbs571"/>
    <language>en</language>
    <item>
      <title>I Built a Multi-Broker Trading Platform — Here’s What Actually Broke (and How I Fixed It)</title>
      <dc:creator>Shashank</dc:creator>
      <pubDate>Sat, 25 Apr 2026 03:27:14 +0000</pubDate>
      <link>https://forem.com/shankjbs571/i-built-a-multi-broker-trading-platform-heres-what-actually-broke-and-how-i-fixed-it-5bi2</link>
      <guid>https://forem.com/shankjbs571/i-built-a-multi-broker-trading-platform-heres-what-actually-broke-and-how-i-fixed-it-5bi2</guid>
      <description>&lt;p&gt;Most trading tools lock you into a single broker.&lt;/p&gt;

&lt;p&gt;I didn’t like that.&lt;/p&gt;

&lt;p&gt;So I started building a platform where you can connect multiple brokers and manage your trades from one place—positions, orders, execution logic, everything.&lt;/p&gt;

&lt;p&gt;Sounds straightforward… until it isn’t.&lt;/p&gt;

&lt;p&gt;This is not a &lt;strong&gt;“how to build a trading app”&lt;/strong&gt; guide.&lt;/p&gt;

&lt;p&gt;This is what actually went wrong while building one—and how I dealt with it.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 The Idea
&lt;/h2&gt;

&lt;p&gt;The goal was simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connect multiple brokers (like IBKR, FYERS, ZERODHA etc.)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Provide a unified interface for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Positions&lt;/li&gt;
&lt;li&gt;Orderbook&lt;/li&gt;
&lt;li&gt;Order placement / cancellation / modification&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Add automation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto-sell based on target/stop-loss&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Handle real-time data using WebSockets&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Basically: &lt;strong&gt;one platform to control everything without juggling multiple apps.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture (High-Level)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI&lt;/li&gt;
&lt;li&gt;WebSockets for real-time updates&lt;/li&gt;
&lt;li&gt;Broker-specific modules (client, orders, portfolio)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Frontend:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Core idea:&lt;/strong&gt;&lt;br&gt;
Each broker has its own implementation, but the platform exposes a &lt;strong&gt;common interface&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So internally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Different logic&lt;/li&gt;
&lt;li&gt;Externally: same API&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Challenge 1: Every Broker is… Different
&lt;/h2&gt;

&lt;p&gt;This was the first reality check.&lt;/p&gt;

&lt;p&gt;Even though brokers provide similar features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication flows differ&lt;/li&gt;
&lt;li&gt;Order formats differ&lt;/li&gt;
&lt;li&gt;Response structures differ&lt;/li&gt;
&lt;li&gt;WebSocket behavior differs&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What I did
&lt;/h3&gt;

&lt;p&gt;Created a &lt;strong&gt;broker abstraction layer&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;client.py&lt;/code&gt; → authentication&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;orders.py&lt;/code&gt; → order placement, cancel, modify&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;portfolio.py&lt;/code&gt; → positions, holdings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each broker implements the same structure.&lt;/p&gt;

&lt;p&gt;So instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;broker&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xyz&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I just do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;broker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;place_order&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clean. Scalable. Less headache later.&lt;/p&gt;




&lt;h2&gt;
  
  
  Challenge 2: Real-Time Execution Isn’t “Real-Time”
&lt;/h2&gt;

&lt;p&gt;For features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop-loss&lt;/li&gt;
&lt;li&gt;Target-based selling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You need &lt;strong&gt;live price updates&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Initially, I used WebSockets directly within the main application.&lt;/p&gt;

&lt;h3&gt;
  
  
  What broke?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Random disconnects&lt;/li&gt;
&lt;li&gt;Delayed ticks&lt;/li&gt;
&lt;li&gt;Missed execution windows&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And in trading, delay = money lost.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I changed
&lt;/h3&gt;

&lt;p&gt;I shifted this responsibility to an &lt;strong&gt;independent service&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of handling execution inside the main app, I built a separate service that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continuously monitors live prices&lt;/li&gt;
&lt;li&gt;Runs independently of the main backend&lt;/li&gt;
&lt;li&gt;Triggers sell execution when conditions are met&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why this worked better
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Isolation: Failures in price monitoring don’t affect the main system&lt;/li&gt;
&lt;li&gt;Reliability: Dedicated process for handling real-time logic&lt;/li&gt;
&lt;li&gt;Scalability: Easier to optimize and scale independently&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also learned:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t blindly trust WebSocket streams. Always have a fallback.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Challenge 3: Order State Lies (Sometimes)
&lt;/h2&gt;

&lt;p&gt;You place an order.&lt;/p&gt;

&lt;p&gt;Broker says: “Placed.”&lt;/p&gt;

&lt;p&gt;But actual state?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pending&lt;/li&gt;
&lt;li&gt;Partially filled&lt;/li&gt;
&lt;li&gt;Rejected later&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Problem
&lt;/h3&gt;

&lt;p&gt;Your system thinks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Done.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reality:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Not even close.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Continuously sync order status&lt;/li&gt;
&lt;li&gt;Treat broker as &lt;strong&gt;source of truth&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Build logic for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;partial fills&lt;/li&gt;
&lt;li&gt;retries&lt;/li&gt;
&lt;li&gt;cancellations&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Challenge 4: Automation is Harder Than It Sounds
&lt;/h2&gt;

&lt;p&gt;“Auto-sell when target hits” sounds easy.&lt;/p&gt;

&lt;p&gt;It’s not.&lt;/p&gt;

&lt;h3&gt;
  
  
  Issues faced:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Price spikes triggering false execution&lt;/li&gt;
&lt;li&gt;Multiple triggers firing at once&lt;/li&gt;
&lt;li&gt;Race conditions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fixes:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Locking execution per position&lt;/li&gt;
&lt;li&gt;Adding thresholds (buffer zones)&lt;/li&gt;
&lt;li&gt;Validating before placing sell orders&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What’s Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Add more brokers&lt;/li&gt;
&lt;li&gt;Improve execution latency&lt;/li&gt;
&lt;li&gt;Build better analytics around trades&lt;/li&gt;
&lt;li&gt;Scale infrastructure&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Building this wasn’t just about coding.&lt;/p&gt;

&lt;p&gt;It was about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;handling uncertainty&lt;/li&gt;
&lt;li&gt;designing for failure&lt;/li&gt;
&lt;li&gt;and thinking beyond “happy paths”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're building anything involving real-time systems or external APIs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expect things to break. Design anyway.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;If you’ve worked on something similar or are building in this space, I’d love to hear your experience.&lt;/p&gt;

</description>
      <category>fastapi</category>
      <category>python</category>
      <category>react</category>
      <category>data</category>
    </item>
  </channel>
</rss>
