Behvandi Build intelligent systems
Back to blog

Studio notes

AI Agent Trading Bots: The Model Sends the Order, but You Own It

Connecting an AI agent to a trading account? You own every order. Build a least-privilege API key, pre-trade gate, kill switch and decision logs outside the model.

A trader's hand beside a red emergency stop button in front of a laptop showing a candlestick chart, with an AI agent whose orders pass through a control gate and one is rejected

Connecting a large language model to an exchange or broker API now takes an afternoon. A few lines of code, an API key and a simple instruction such as "follow the trend with this capital" are enough to build an agent that reads the market and sends orders on its own. That simplicity has made a question urgent that, until recently, mattered mainly to funds and brokers: if the agent gets it wrong, who is accountable, and what should stop it?

This article is for traders and developers who plan to connect an AI agent to a live account, or already have. The short answer: the responsibility is yours, and the essential controls have to live outside the model, not inside the prompt. Below, we look at exactly which controls those are.

Why this question matters now

In recent weeks, both a US regulator and a US exchange operator have addressed agentic trading head-on. On 28 October 2026, the Commodity Futures Trading Commission (CFTC) held its first "Frontier Forum", and one of its two panels was devoted to agentic trading. In his opening remarks, the CFTC chairman raised questions that still have no official answer, including who is liable if an agent "goes rogue" (the chairman's remarks on the CFTC website).

A week later, on 4 November, CME Group's chief regulatory officer gave a clearer answer on a panel at FIA Expo. According to FIA's report, he said it makes no difference to him whether an order comes from an agentic AI system or a human trader: the person issuing the instructions is still liable. He added that CME's rule on disruptive trading practices does not accept a claim of not knowing. He also said CME had already sent inquiries to participants using large language models to build trading strategies, and that the number of inquiries sent to one such participant was "far greater" than for a conventional trader placing a large market order into a thin book (FIA report, 16 November 2026).

These statements concern US futures markets and are not law in your market. Their logic, however, travels well: an order that leaves your account is your order. If you cannot explain why it was sent, the problem is not only legal; it means there was no real control in place.

How an agent differs from a rule-based bot

An Expert Advisor or rule-based bot does exactly what it was written to do. If an entry condition is wrong, it repeats the same mistake every time, and backtesting and code review can find it. An AI agent is different: you give it a goal and it chooses how to pursue it. The lawyer moderating the FIA panel made the same point: with a classic algorithm, the code shows what the trader asked for; an agent receives only a goal and devises the strategy itself.

That difference has three practical consequences:

  • Behaviour is not fixed. The same input can lead to different decisions on two runs, and behaviour can change when the model version or the prompt changes.
  • Ambiguous language is dangerous. The chief compliance officer of Robinhood Derivatives warned on the same panel that poorly built prompts or ambiguous wording can change how a model interprets a request.
  • One round of testing is not enough. An agent that behaved well today offers no guarantee for tomorrow, so controls must apply to every order, not just before launch.

Principle one: the agent does not set the limits

The OWASP Gen AI Security Project lists "Excessive Agency" among the main risks of LLM-based applications: an agent with more functionality, permissions or autonomy than it needs. One of its explicit mitigations is to enforce authorization in downstream systems rather than trusting the model to decide whether an action is allowed (OWASP LLM06:2025).

In trading, the translation is simple. "Never risk more than 2% of capital" written in a prompt is not risk control; it is a request. Real control is code the agent cannot change or bypass.

An API key with the least access

The first and cheapest layer is the API key itself. The key your agent uses should be allowed to read and trade, not to withdraw or transfer funds. Many exchanges define these permissions separately. For example, Binance's official documentation lists separate permissions for reading, trading, withdrawals and internal transfers on each key, and withdrawals cannot be enabled unless the key is restricted to specific IP addresses (API key permission documentation). The details differ by exchange and broker, so read the documentation of the service you actually use.

The next layer is separating the money. According to Robinhood's compliance officer in the FIA report, agentic trading at Robinhood runs in a separate, pre-funded account: the customer decides how much goes in, and the AI cannot add or withdraw funds on its own. The same pattern works at a personal scale: a sub-account or separate account holding only capital you have accepted you could lose entirely.

A pre-trade gate

The most important layer is code that sits between the agent and the broker API. The agent only produces an order proposal, and this gate decides, using fixed rules, whether the order goes out. A simple example in Python:

from dataclasses import dataclass

@dataclass
class Limits:
    allowed_symbols: set
    max_qty: float            # maximum size of a single order
    max_position: float       # maximum open position per symbol
    max_price_dev: float      # maximum distance of order price from last price (0.01 means 1%)
    daily_loss_limit: float   # daily loss limit in account currency

def check_order(order, position, last_price, daily_pnl, limits, kill_switch_on):
    """Returns (allowed?, reason). This function only applies rules and does not trust model text."""
    if kill_switch_on:
        return False, "kill switch on"
    if order["symbol"] not in limits.allowed_symbols:
        return False, "symbol not allowed"
    if order["type"] != "limit":
        return False, "only limit orders"
    if not (0 < order["qty"] <= limits.max_qty):
        return False, "qty out of range"
    if abs(order["price"] - last_price) / last_price > limits.max_price_dev:
        return False, "price too far from market"
    signed = order["qty"] if order["side"] == "buy" else -order["qty"]
    if abs(position + signed) > limits.max_position:
        return False, "position limit"
    if daily_pnl <= -limits.daily_loss_limit:
        return False, "daily loss limit hit"
    return True, "ok"

This code has been run with Python 3.13 against nine simple unit tests, but it has not been connected to any exchange and is not sufficient for a live account. For example, it does not calculate daily P&L, limit the number of orders per minute or reconcile positions with the broker. Its purpose is to show one idea: limits are written in deterministic, testable code, and the agent has no way to change them. Rate limiting matters too; OWASP describes it as a way to reduce damage before an error is detected.

Human approval and a kill switch

Not all decisions carry the same weight. Reading positions is low risk; opening a large position or trading an illiquid symbol is high risk. OWASP recommends human approval before high-impact actions are carried out. Robinhood, according to its compliance officer, asks the customer to approve each trade by default before the agent sends it to the market, although customers can turn that step off.

Alongside approval, you need an emergency stop (kill switch) that sits outside the agent: one command that halts new orders and, if needed, cancels open ones. It should be in the hands of someone who does not need to talk to the agent to use it.

The agent's inputs are an attack surface too

An agent that reads news, social media posts, web pages or other people's analysis is exposed to indirect prompt injection. OWASP puts prompt injection at the top of its list of risks for LLM applications: external content, such as a website or a file, can contain instructions that change the model's behaviour (OWASP LLM01).

A hypothetical scenario: your agent reads posts on a social network to gauge market sentiment. Someone publishes text that looks like analysis but contains a hidden sentence telling the model to put the entire balance into an illiquid symbol. If the agent's output goes straight to the API, that text has effectively become an order.

The main defence is the same pre-trade gate, because it does not trust text; it sees only numbers and rules. Two other measures help: the agent that reads external content should have no order-sending tool and should only produce summaries or scores, and the list of allowed symbols should be short and fixed.

Every decision must be reconstructable

CME's chief regulatory officer said on the same panel that anyone building an agentic trading system should be able to produce timestamped logs of commands, prompts and decisions, together with the data the system relied on, and recommended that a system should "generate a log every time a trading decision is made."

Even if no regulator ever asks for your logs, you will need them to understand your losses. For each decision, record at least the following:

What Why
Time, model name and version, full prompt text Behaviour changes when the model or prompt changes
The data the agent saw (prices, news, positions) Without it, the decision cannot be reconstructed
The agent's raw output To spot misinterpretation or prompt injection
The gate's result and the reason for rejection or approval To confirm the controls actually worked
Order ID, fill price, fees To compare expectations with reality

A lower-risk path to a live account

Backtesting an LLM-based agent has a specific trap. If the test period falls before the model's training-data cutoff, the model may have seen news and events from that period during training. That is a form of look-ahead leakage, and it makes results look better than reality. For evaluation, choose a period after the model's knowledge cutoff, and even then, do not treat a backtest as a forecast.

After that, a sensible sequence is:

  1. Paper trading. Several weeks on live data without real money, with the same gate and the same logging.
  2. Small, separate capital. In a separate account, with strict limits and human approval switched on.
  3. Cost monitoring. Look at trading fees, slippage and the model's token costs together. A strategy with a thin gross profit may lose money once those three are counted.
  4. Regular review. Go through the orders the gate rejected. If the agent keeps proposing orders outside the limits, the problem lies in the goal or the prompt, not in the gate.

Conclusion

An AI agent can make analysis faster and broader, but it does not take responsibility for your orders off your shoulders. The real controls are the ones the model cannot change: a least-privilege API key, a separate account, a pre-trade gate, human approval, a kill switch and complete logging. If any of these is missing from your system, build it before you add more capital.

If you are working on an AI trading bot and want help designing the risk layer, connecting securely to a broker or reviewing code, you can reach us through the Order page on the Behvandi website.

This article is not investment advice and does not guarantee any return. Backtest or paper-trading results are no guarantee of future performance.

Comments

No comments yet. Be the first to write one.

Email or mobile is for the studio only and is not shown on the site.