Skip to main content
Bot Found Trades, Never Executed Them
Engineering Learnings7 min readSeptember 19, 2026

Bot Found Trades, Never Executed Them

A trading bot failed to execute trades due to differing margin calculations between its scanning and execution stages.

By Tradewink Engineering
Share

Key takeaways

  • When one pipeline stage filters on a value another stage recomputes differently, the pipeline produces candidates that can never execute.
  • Broker account fields are not uniform: buying power, cash, equity and net liquidation are populated differently per broker and per asset class.
  • Read account capacity through one shared helper so a fallback added in one place cannot be missing in another.
  • Log the rejection reason and the value that caused it; insufficient margin with available 0.0 immediately pointed at a missing field rather than a real shortfall.
  • A stage that always rejects is easy to miss, because every earlier stage reports success.

The Scanner Found Trades the Executor Always Rejected

A trading bot failed to execute any opportunities because its execution stage incorrectly calculated available margin, rejecting every trade despite sufficient account equity. This was caused by a divergence in how the scanning and execution stages interpreted account margin, specifically for futures accounts at one broker.

What went wrong

Our automated trading system, Tradewink, was identifying profitable trade setups consistently. The scanning component of our pipeline would flag these opportunities, log them as actionable, and pass them to the execution stage. However, every single one was subsequently rejected by the executor with an "insufficient margin" error. The reported available margin was consistently zero, despite the account holding approximately $350 in real equity. This meant that while the system was brilliant at finding potential trades, it was incapable of acting on them.

Why it happens

The core of the problem lay in how two distinct stages of our trading pipeline computed available margin. The scan stage was designed with a fallback mechanism: it first checked for positive buying power, and if that was zero or negative, it would use the account equity as the available margin. This logic correctly reflected the actual capital available for trading.

The execution stage, however, had a more rigid check. It only considered buying power and cash. Crucially, for futures accounts at a specific broker we were using, both buying power and cash were reported as zero. This broker reported net liquidation value instead of the traditional buying power and cash figures that our execution logic expected. Because the execution stage lacked the equity fallback present in the scan stage, it saw zero available margin for every futures trade, leading to the constant rejections. The scan stage, meanwhile, logged the opportunities normally, making the pipeline appear healthy until the final execution gate.

What we changed

To rectify this, we implemented a unified approach to margin calculation across the entire trading pipeline. The rule we adopted is straightforward: any time an account's buying power or cash is read for a margin check, account equity is now the last-resort fallback. We refactored our code to use a single, shared helper function for all margin checks. This ensures that both the scan and execute stages, and indeed any other part of the system that needs to know available capital, use the exact same logic and data interpretation. This eliminated the discrepancy and allowed the execution stage to correctly identify the available equity when buying power and cash were reported as zero.

How to check your own system

If you suspect a similar issue in your trading bot, perform the following checks:

  • Review Margin Calculation Logic: Compare how your system's scanning/signal generation components determine available margin versus how your execution component does. Look for differences, especially in fallback mechanisms or how specific asset classes (like futures) are handled.
  • Broker API Data: Verify the exact fields your broker's API returns for buying power, cash, and equity. Understand how your broker reports these values, particularly for different account types (e.g., cash vs. margin, futures vs. equities).
  • Test with Known Equity: Manually set up a test account with a small, known amount of equity (e.g., $350 as in our case). Run your bot in a simulated environment and observe the reported available margin at both the signal and execution stages. Does it match your expectation?
  • Log Everything: Ensure your system logs the precise values used for margin checks at every relevant step. This data is invaluable for debugging discrepancies.

This systematic approach can help uncover hidden bugs that prevent your bot from acting on opportunities it correctly identifies.

Disclaimer

This article describes engineering decisions in a trading system. It is not investment advice. Trading involves substantial risk of loss and is not suitable for all investors. Past performance does not guarantee future results. Always do your own research and consider your financial situation before trading.

Frequently asked questions

Why does my trading bot say insufficient margin when the account has money?

Most often the code is reading a field the broker does not populate for that account type. Futures and cash accounts frequently report zero buying power while carrying real equity under a different field name. Log the raw account payload once and confirm which fields actually contain values.

How do you stop a screener from finding trades the executor rejects?

Make both stages call the same function for any shared constraint. If the screener filters on affordability, it must use the executor's affordability check, not a parallel implementation. A test that asserts a scanned candidate passes the execution gate catches the drift.

What is the difference between buying power, cash and equity?

Cash is the settled money balance, equity is the total account value including open positions, and buying power is what the broker will let you deploy, which may be a multiple of equity in a margin account or absent entirely for some account types. Never assume one can be substituted for another.

Related Topics

trading bot not executing tradesinsufficient margin errorbuying power calculationfutures margin requirementstrading pipeline bugbroker account fields
TW

Tradewink builds explainable market research for self-directed traders. Build a watchlist, inspect signal reasoning and risk context, and paper-track ideas before you decide. Live broker workflows are invite-only when available.

Found this useful? Share it.
Share

Put this knowledge to work

Tradewink uses AI to scan hundreds of stocks daily and delivers trade ideas with full signal breakdowns — free to start.

Build a Watchlist

Save a signal preview for later

Get a concise AI signal example in your inbox, then build a watchlist when you are ready. No spam, unsubscribe anytime.

Start with free AI trade ideas

See how Tradewink turns market structure, momentum, and risk rules into trade-ready signals. Free to start, with your broker staying in control.

Enter the email address where you want to receive a Tradewink AI signal preview.

More in Engineering Learnings