Agentic tradingRiskCryptoDevelopers

How to keep crypto trading agents inside hard limits they cannot cross

Hard limits in API infrastructure prevent AI agents from overspending or overleveraging in crypto markets, even if the model is compromised or hallucinates.

By the Felix team9 min read
Key takeaways
  • 01Crypto markets trade continuously with high volatility, so an AI agent without hard limits can lose money faster than any human can intervene.
  • 02Hard limits are API-enforced constraints on budget, position size, and venue access that the agent cannot override, regardless of prompts or reasoning errors.
  • 03A kill switch must be tested before going live, because it is the final backstop when markets move against the agent or the model behaves unexpectedly.
  • 04Paper trading validates your safety infrastructure, but it cannot replicate live liquidity and slippage, so treat it as a test of limits, not a promise of performance.
  • 05Continuous monitoring of audit logs, rejection rates, and aggregate exposure is necessary to detect when an agent is pressing against its boundaries.

Crypto markets trade continuously, often with high leverage and sudden volatility, so an AI agent without enforced hard limits can accumulate losses faster than a human can react. Hard limits are owner-set constraints baked into the API infrastructure that the agent cannot override, even if its reasoning or a prompt injection tells it to try. These limits include budget caps, maximum position sizes, approved venues, and a kill switch that flattens positions and revokes the key. Together they form a non-custodial safety layer that keeps the agent's behavior inside a boundary you define, not one it interprets.

What makes crypto markets especially dangerous for autonomous agents?

Crypto markets do not close. While traditional equity markets have session hours and circuit breakers, a crypto venue runs twenty-four hours a day, every day. An agent that encounters a bug, a bad signal, or a misunderstood headline at 3:00 AM will keep trading until something stops it. That something must be infrastructure, not a person asleep at the other end of a phone.

Volatility is another factor. Price swings of ten percent or more within minutes are not rare. If your agent uses leverage, whether intentionally or because a perpetual futures venue defaults to margin trading, those swings can liquidate a position or wipe out a budget before a log entry finishes writing. An agent that rebalances aggressively can turn a small dip into a realized loss by selling low and buying high in the same hour. Some instruments that look like spot assets are actually leveraged tokens or derivatives with embedded margin, which means the agent may be taking on more risk than the plain price suggests.

Then there is the agent itself. Large language models can hallucinate prices, misread timestamps, or interpret a vague prompt as permission to double exposure. A scoped API key is meant to prevent this, but if the scope is too broad, the agent still has room to err. Add prompt injection from social media or malformed market data feeds, and you have an autonomous system that can be tricked into placing orders it never should have considered. Without hard limits, the only boundary is the model's best guess, and that guess can be wrong in seconds.

How do hard limits differ from soft prompts?

A soft prompt is a sentence in the system message. It says things like 'never risk more than one hundred dollars' or 'only trade spot markets.' These instructions work until they do not. A model can ignore them, a developer can overwrite them during a debugging session, or an adversarial input can reframe them. Soft prompts are suggestions, not enforceable rules.

Hard limits live in the API and wallet infrastructure. When you create a scoped key for your agent, you attach a budget cap in US dollars. The API rejects any order that would push cumulative spend above that cap, regardless of how the agent phrases the request. You also set position limits, so an agent cannot open a perp position larger than your specified notional value, even if the model decides it has found a favorable setup. Withdrawal addresses are owner-approved and immutable by the agent, which means the funds stay in your wallet and the agent can never send them elsewhere.

This distinction matters because crypto venues often expose complex contract mechanics. The Felix API normalizes order sizing to plain US dollars, but the agent still sees leverage, margin ratios, and funding rates. A soft prompt might tell the agent to avoid leverage, but if the agent connects to a perps venue and the prompt is bypassed, leverage is available. Hard limits remove the option entirely by restricting the key to spot markets or capping the maximum notional at a level you can afford to lose. How an AI agent trades perpetual futures within hard limits it cannot cross explains how these boundaries work in leveraged environments.

What should your budget cap and position sizing look like?

Start with a number you are willing to lose completely. This is not pessimism. It is a realistic baseline for any speculative trading, and crypto is especially unforgiving. The budget cap should be a fraction of your total portfolio, not the whole thing. If your agent has a one thousand dollar cap, the API will block the one thousand and first dollar of attempted spend, even if the agent believes it is averaging down into a recovery.

Position sizing needs two layers: per-trade size and total exposure. A per-trade limit prevents a single large order from moving the market against you or from carrying too much concentration risk. A total exposure limit prevents the agent from opening ten correlated positions that add up to more risk than you intended. How to size positions for an AI trading agent from first principles covers the math behind these splits, but the practical rule is simple: the agent should not be able to put more than your predefined amount at risk at any moment.

Because the API uses dollar-based sizing, the agent does not need to calculate satoshis, contract multipliers, or decimal places. It sends a number like fifty dollars, and the infrastructure translates that to the venue's native format. This reduces arithmetic errors, but it does not eliminate sizing risk. An agent that repeatedly sends fifty dollar orders in a tight loop can still burn through a budget cap in minutes. Rate limits and order frequency controls are therefore part of a complete sizing strategy. Remember that trading can lose money, including everything, and fast automation only accelerates that outcome.

Why is a kill switch not optional?

A kill switch is a control that immediately flattens all open positions and revokes the agent's API key. It exists because no monitoring system is perfect, and no set of limits anticipates every black swan. When a stablecoin depegs, a venue API lags, or a model begins looping on a bad strategy, you need a way to stop the agent in seconds, not minutes.

The kill switch is non-custodial by construction. It does not move your funds to a third party. It simply cancels orders, closes positions, and disables the key. Because withdrawal addresses are owner-approved only, the agent cannot steal funds during the shutdown, nor can it redirect assets to a new wallet. The panic action is irreversible for that key, which means you must issue a new one to resume trading, but that friction is intentional. It forces a human review after an emergency.

You should test the kill switch during paper trading. Know the latency between pressing the button and seeing positions flatten. Know whether a venue accepts market orders in all conditions, or whether the switch needs a fallback to limit orders. If your agent trades across multiple venues through one API, understand whether the switch targets all venues or can be scoped to one. In illiquid markets, flattening may take longer or execute at worse prices, so the kill switch stops new bleeding rather than guaranteeing a perfect exit. These details determine whether your safety net actually catches you. How to set up audit logs and observability for trading agents with hard limits describes how to verify that the kill switch fired correctly.

How do you test limits without risking real capital?

Paper trading lets you observe how an agent behaves when it thinks it is using real money, without the actual downside. This is where you validate that your budget cap triggers correctly, that position limits block oversized orders, and that the agent handles rejection gracefully rather than retrying aggressively.

However, paper environments are not perfect mirrors of live markets. Latency is lower, liquidity is infinite, and some error messages differ. Common mistakes developers make with paper trading for AI agents details the gaps that cause agents to fail on their first live trade. The key point is to treat paper trading as a test of your safety infrastructure, not just your strategy.

Run adversarial tests. Give the agent a prompt that explicitly asks it to exceed the budget cap and see if the API blocks it. Simulate a rapid sequence of orders to test rate limits. Introduce malformed market data to see if the agent hallucinates a signal and tries to trade on it. If the agent cannot breach your hard limits in paper mode, you have evidence that the scaffolding works. If it can, you have found a bug before it costs money.

What should you monitor after the agent goes live?

Monitoring is not about watching profit and loss. It is about confirming that the agent stays inside its cage. You need audit logs that record every order request, rejection, and key scope check. These logs should live outside the agent's control, so a compromised model cannot erase them.

Set alerts for rejection spikes. A sudden cluster of 'budget cap exceeded' errors means the agent is trying to spend more than allowed, which could indicate a strategy runaway or a loop. Watch for venue changes. If your key is scoped to one or two crypto venues and you see attempts to reach a third, that is a sign of key misuse or a configuration drift. Monitoring should also track the agent's reasoning chain if available. If the logs show the agent is repeatedly revising its strategy because of recent losses, it may be overfitting to noise. An agent that changes its logic after every trade is an agent that has no stable boundary. The hard limits will still block the orders, but the monitoring should tell you why the agent keeps trying to breach them.

Finally, review position correlation. An agent trading multiple crypto assets might build a portfolio that is effectively one giant bet on a single asset's direction, even if the individual trades look small. Monitoring tools should aggregate notional exposure across all open positions and compare it to your total limit. If the aggregate approaches the cap, the system should warn you before the hard limit blocks the next trade, because a block during volatile conditions can leave an agent with half a hedge and no way to adjust. The goal of monitoring is to catch pressure on the boundaries before the boundaries have to enforce themselves.

Frequently asked questions

Can a hard limit ever be bypassed by a clever prompt?

No. Hard limits are enforced by the API infrastructure, not by the language model. Even if the agent is tricked into requesting a trade that violates the limit, the order is rejected at the infrastructure level before it reaches a venue.

What happens if the API rejects an order because of a limit?

The agent receives an error response, exactly as it would from a venue for insufficient margin. A well-built agent should log the rejection and stop, not retry in a loop that wastes compute or triggers a rate limit.

Does a kill switch close positions at a loss?

Yes. A kill switch is designed to stop trading immediately, which may mean closing positions at the current market price. The goal is to prevent further damage, not to optimize the exit price.

Are paper trading limits identical to live trading limits?

The hard limits and scopes are identical, but market conditions differ. Paper trading uses simulated fills, so slippage and liquidity behavior may not match live markets. Use paper mode to validate controls, not to predict returns.

How quickly can I revoke an agent's access?

Revocation is instant at the API key level. The time to flatten open positions depends on market conditions and venue latency, but the agent cannot place new orders the moment the key is revoked.

Can I set different limits for different agents?

Yes. Each scoped key can have its own budget cap, position limits, and approved venues. This lets you run multiple strategies with independent risk boundaries so one agent cannot spend another's budget.

Give your agent a key.

One key to trade stocks, crypto, perps, options, and prediction markets. Live after owner authorization.

Keep reading

Not a brokerage, exchange, or investment adviser. Not investment advice. Trading involves risk, including total loss.