<?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>DEV Community: J. Arendz</title>
    <description>The latest articles on DEV Community by J. Arendz (@j_arendz_0e3b9917160fb60).</description>
    <link>https://dev.to/j_arendz_0e3b9917160fb60</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4266564%2Fc410126c-0e75-4b38-b028-2bebf1974efb.png</url>
      <title>DEV Community: J. Arendz</title>
      <link>https://dev.to/j_arendz_0e3b9917160fb60</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/j_arendz_0e3b9917160fb60"/>
    <language>en</language>
    <item>
      <title>The Tradovate API ignored my accountId, and my trade copier blew up an account</title>
      <dc:creator>J. Arendz</dc:creator>
      <pubDate>Thu, 26 Nov 2026 10:19:47 +0000</pubDate>
      <link>https://dev.to/j_arendz_0e3b9917160fb60/the-tradovate-api-ignored-my-accountid-and-my-trade-copier-blew-up-an-account-na9</link>
      <guid>https://dev.to/j_arendz_0e3b9917160fb60/the-tradovate-api-ignored-my-accountid-and-my-trade-copier-blew-up-an-account-na9</guid>
      <description>&lt;p&gt;I trade futures on several prop firm accounts at Tradovate. Placing the same trade by hand on four accounts is slow and error-prone, so I built a trade copier: a desktop app that watches one "leader" account and mirrors its orders to "follower" accounts.&lt;/p&gt;

&lt;p&gt;In June it took one of my funded accounts from normal to blown in a few minutes. Not because of a market move, but because of one assumption about an API parameter.&lt;/p&gt;

&lt;p&gt;This post is about that assumption, how it turned into a runaway loop, and what I changed so it can't happen again.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;The copier polls Tradovate for new fills. When the leader gets filled, it places the same order, scaled, on each follower. There's also a catch-up pass: if the app missed a leader fill (a dropped connection, a sleeping laptop), it replays it so the followers don't drift.&lt;/p&gt;

&lt;p&gt;To get the leader's fills, I called the fill list endpoint with the leader's account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="na"&gt;GET /fill/list?accountId&lt;/span&gt;&lt;span class="o"&gt;=&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That looked right. It returned fills, they looked like the leader's fills, and for weeks everything worked.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was actually happening
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;accountId&lt;/code&gt; parameter is ignored.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/fill/list&lt;/code&gt; is scoped to the &lt;strong&gt;user&lt;/strong&gt; (the login), not the account. You get fills from every account under that login. And a fill row doesn't carry an account ID, so nothing in the response tells you which account it belongs to.&lt;/p&gt;

&lt;p&gt;With one leader and no followers on the same login, you'd never notice. With followers on the same login, the response quietly includes their fills too.&lt;/p&gt;

&lt;h2&gt;
  
  
  How that became a runaway
&lt;/h2&gt;

&lt;p&gt;Follow the catch-up pass with that in mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The leader buys 1 contract. The copier mirrors it: the follower buys 2 (a 2x scale).&lt;/li&gt;
&lt;li&gt;Next poll, the catch-up pass reads the fill list. It sees the follower's fill, doesn't recognise it as already copied, and treats it as a &lt;strong&gt;missed leader fill&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It "replays" it: the follower gets another order, scaled 2x.&lt;/li&gt;
&lt;li&gt;That order fills. Next poll, that fill is also in the list, also looks like a missed leader fill, also gets replayed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2, 4, 8, 16. Each round fed the next one. By the time I stopped it, the follower was far past its drawdown limit.&lt;/p&gt;

&lt;p&gt;Nothing errored. Every request succeeded. The logs showed a copier doing exactly what it was built to do, on data that meant something different from what I thought.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: attribute every fill through its order
&lt;/h2&gt;

&lt;p&gt;Fills don't carry an account, but orders do. Each fill has an &lt;code&gt;orderId&lt;/code&gt;, and the order list includes &lt;code&gt;accountId&lt;/code&gt; per order. So attribution goes through the order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// fills and orders both come back for ALL accounts under the login,&lt;/span&gt;
&lt;span class="c1"&gt;// whatever accountId you pass&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;account_of&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;HashMap&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AccountId&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fill&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_fills&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;account_of&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;leader_id&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;process_leader_fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;               &lt;span class="c1"&gt;// a follower's fill: never replay it&lt;/span&gt;
        &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;skip_and_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// can't attribute: don't guess&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important line is the last one. If a fill can't be tied to the leader, it is &lt;strong&gt;not&lt;/strong&gt; replayed. Before, "I don't know whose this is" defaulted to "act on it". Now it defaults to "do nothing and say so".&lt;/p&gt;

&lt;p&gt;I added two more guards on the same day:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A staleness cap.&lt;/strong&gt; A fill older than 120 seconds is recorded but never replayed as a new market order. Catching up on a stale fill is how a small gap turns into a large position. If the follower is out of sync, the app flags it and the trader decides.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One processing path.&lt;/strong&gt; Fills from the live stream only &lt;em&gt;wake up&lt;/em&gt; the poll; they are handled in one place. Two paths that each "handle" a fill is how you get a fill copied twice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  It wasn't only fills
&lt;/h2&gt;

&lt;p&gt;Once I knew to look, I found the same behaviour in three other places:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/fillFee/list&lt;/code&gt;: user-scoped. My fee sync was writing every fee under every account.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/order/list&lt;/code&gt;: user-scoped. Fine for attribution (orders carry &lt;code&gt;accountId&lt;/code&gt;), but any code that assumed "these are this account's orders" was wrong.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/position/list&lt;/code&gt;: also user-scoped. I found this one later, in November, in a test harness rather than in production: with the leader long 2 and a follower long 1, "flatten this account" sent sell orders for &lt;strong&gt;both&lt;/strong&gt; positions from one account. It would have flipped the leader short instead of flat.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule I follow now: &lt;strong&gt;on this API, a list endpoint returns everything under the login, and every caller filters by account itself.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building on a trading API
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Measure, don't assume.&lt;/strong&gt; I "knew" the parameter worked because the response looked plausible. One test with two accounts on one login, comparing the results with and without the parameter, would have shown it in a minute. Every expensive bug in this project so far came from something I assumed instead of measured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When you can't tell, do nothing.&lt;/strong&gt; In software that places orders, the safe default for ambiguous data is inaction plus a visible warning, not a best guess. A missed copy costs a little. A wrong copy can cost the account.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build a fake broker.&lt;/strong&gt; After June I wrote a simulated Tradovate that the copy engine runs against in tests: several accounts under one login, user-scoped lists, partial fills, delayed positions. The &lt;code&gt;/position/list&lt;/code&gt; bug was caught there, not in my account. I also run mutation tests on the safety checks: break the guard on purpose and confirm a test fails. If no test fails, the guard isn't really protected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Log what you decided, not just what you did.&lt;/strong&gt; "Skipped fill X: no order attribution" is the line that tells you a guard is working. Without it, a silent skip looks exactly like a bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  About how this was built
&lt;/h2&gt;

&lt;p&gt;I'm one person, and I write most of this code with an AI coding assistant (Claude Code). It's worth saying because it's relevant here: an assistant writes plausible code against an API just as fast as it writes correct code, and a parameter that is silently ignored looks the same either way. What caught this problem in the end was a blown account and a reconstruction afterwards, not the tooling. The guards above, the test harness and the habit of measuring first are what I'd now insist on, whoever or whatever writes the code.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The copier is called Syncopy. It runs locally and is in a small closed beta. If you build on the Tradovate API and have run into other surprises like this one, I'd like to hear about them in the comments.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>api</category>
      <category>showdev</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
