Risk Management7 min read2026-11-23

Risk Controls for Crypto Trading Bots and Agents: The Options Compared

Five places a risk limit can live for a crypto trading bot or AI agent: strategy code, framework protections, exchange settings, wallet policies and an external risk API. What each one sees and what it misses.

By Alvaro Villacorta, Founder, RiskState

Short answer

A position limit for a crypto bot can live in five places: in the strategy code, in the bot framework's built-in protections, at the exchange (sub-accounts, API key permissions, leverage settings), in the wallet for onchain agents (spending limits, session keys), and in an external risk API that reads market conditions. They are layers and not substitutes: the first four know your account and nothing about the market, and the last knows the market and nothing about your account unless you tell it.

The short answer

A position limit for a crypto bot can live in five places: in the strategy code, in the bot framework's built-in protections, at the exchange (sub-accounts, API key permissions, leverage settings), in the wallet for onchain agents (spending limits, session keys), and in an external risk API that reads market conditions. They are layers and not substitutes: the first four know your account and nothing about the market, and the last knows the market and nothing about your account unless you tell it.

Below, each option with what it is good at and the gap it leaves. RiskState is the fifth kind; the section on it says what it does not do.

1. Rules in the strategy code

The limit is part of the strategy: a maximum stake, a stop after a losing day, a filter that stops entries below a moving average.

Good at: anything that depends on the strategy's own state. It has no dependency and you can read every line.

Gap: it shares a process with the code it is meant to restrain. A bug in the strategy is often a bug in the limit, and in an AI agent a limit written in the prompt can be argued away. It also sees only the data the strategy already loads.

2. Protections built into the bot framework

Most open-source bots ship controls of their own. Freqtrade has protections that pause trading on a pair or on the whole bot after a run of stop-losses, after a drawdown or for a cooldown period, plus a cap on the number of open trades. Hummingbot has a kill switch that stops the bot at a set loss and limits on the balance a strategy may use.

Good at: stopping a bot that is already losing, with no code to write.

Gap: they react to your results after the fact. They do not reduce size because conditions have become dangerous before you have lost anything, and their coverage has edges. In Freqtrade, a size cap in the stake callback does not apply to position increases; we list the cases in three ways a position size limit fails silently.

3. Limits at the exchange

The venue enforces some limits for you: a sub-account that holds only the capital the bot may lose, an API key with trading permission and no withdrawal permission, a maximum leverage per symbol, and on perps the choice of isolated margin so that one position cannot draw on the whole balance.

Good at: being impossible to bypass from your own code. If the sub-account holds 5,000, the bot cannot lose 50,000.

Gap: they are static and coarse. They bound the worst case and say nothing about what size is sensible today. They also stop at the venue: a bot that trades on two exchanges and holds a DeFi loan has three separate limits and no total.

4. Limits in the wallet, for onchain agents

An agent that signs its own transactions can be bounded at the wallet: a smart account with a spending limit per day, an allowlist of contracts it may call, or a session key that expires and carries its own caps.

Good at: bounding what a compromised or confused agent can move. This is the onchain equivalent of the API key without withdrawal rights.

Gap: the wallet does not know what a trade is. It can cap the amount per transaction; it cannot tell that the tenth small swap has built a position four times larger than intended, or that the market is in a liquidation cascade. Pre-execution guardrails covers what a check before each action has to look at.

5. An external risk API

A service outside your bot reads market conditions and returns the limit: how much exposure is allowed now, which actions are blocked, and why. RiskState is one of these, for BTC and ETH. One call to the RiskState API returns max_size_fraction, blocked_actions and a policy_hash that lets the decision be verified later; a second endpoint checks a proposed position against the rest of a portfolio.

Good at: reacting to conditions before you have lost anything, using data most bots do not collect (derivatives positioning, on-chain valuation, macro, the health factor of a DeFi loan); giving several bots and agents one shared limit; leaving a record a third party can check.

Gap, stated plainly: it executes nothing and holds nothing. It cannot stop a withdrawal, place a stop-loss or close a position; your code has to obey it. It covers two assets. It is a network dependency, so the client needs a rule for when it is unreachable. And it knows your positions only if you send them.

What each layer can see

• Strategy rules: your signals and your profit and loss. Not the market beyond what the strategy loads. • Framework protections: your recent trades and drawdown. Not conditions before a loss. • Exchange limits: the balance and leverage on that venue. Not other venues, not the market. • Wallet limits: amounts and destinations of transactions. Not positions, not the market. • External risk API: market conditions, and your portfolio if you send it. Not your keys or your funds.

The useful question is which gap you are currently leaving open. A bot with good strategy rules and an API key that can withdraw has the wrong layer missing; so does an agent with a tight wallet policy and no idea how much exposure it has built.

A reasonable minimum

For a bot on a centralized exchange: a sub-account sized to what you can lose, an API key without withdrawal rights, a fixed ceiling in your own code, and the framework's drawdown protection switched on.

For an onchain agent: a wallet with a daily spending limit and a contract allowlist, and a check before each action that lives outside the model.

Add a market-aware limit on top when the capital is large enough that being fully sized into a bad week matters more than the cost of one more dependency. Whether to write that limit yourself or read it from a service is a separate decision, covered in build your own risk rules or use a risk API.

See the current limit for BTC and ETH

The app shows the live limit and the reason that is binding. The API returns the same decision to your bot.