AI Crypto Trading Risk Management: Position Sizing, TP/SL & Kill Switches
LLMs are strong at synthesizing market structure and terrible at mental arithmetic under stress. Moving all sizing, drawdown checks, and bracket orders into deterministic TypeScript inside `execute_code` turns a fragile prompt bot into a disciplined trading system.
Never delegate risk math to free-form LLM intuition. Compute position size deterministically inside `execute_code` (`qty = (equity * riskPct) / |entry - stopLoss|`), cap leverage (`eterna.setLeverage`), attach `stopLoss` and `takeProfit` directly on every `eterna.placeOrder`, and limit capital at the isolated sub-account boundary.
https://mcp.eterna.exchange/mcp1. Deterministic 1%-Risk Position Sizing Script
Copy this reusable TypeScript wrapper into your agent instructions so every order validates balance, open exposure, leverage, and stop distance before execution.
const symbol = "BTCUSDT";
const side = "Buy" as const;
const riskPct = 0.01; // 1% of account equity
const maxLeverage = 5;
const stopDistancePct = 0.015; // 1.5% stop
const rewardMultiple = 2.0; // 2R take profit
const [balance, positions, tickers] = await Promise.all([
eterna.getBalance(),
eterna.getPositions(),
eterna.getTickers({ symbol }),
]);
if (positions.some((p: any) => p.symbol === symbol && Number(p.size) > 0)) {
return { skipped: true, reason: "Position already open on " + symbol };
}
const equity = Number(balance.totalEquity ?? balance.availableBalance ?? 0);
const lastPrice = Number(tickers[0].lastPrice);
const riskUsd = equity * riskPct;
const stopPrice = lastPrice * (1 - stopDistancePct);
const takeProfitPrice = lastPrice * (1 + stopDistancePct * rewardMultiple);
const stopDistUsd = Math.abs(lastPrice - stopPrice);
const rawQty = riskUsd / stopDistUsd;
return {
equity,
lastPrice,
riskUsd: Number(riskUsd.toFixed(2)),
suggestedQty: Number(rawQty.toFixed(4)),
stopLoss: Number(stopPrice.toFixed(2)),
takeProfit: Number(takeProfitPrice.toFixed(2)),
maxLeverage,
};2. The 5 Non-Negotiable Agent Risk Rules
- Fund the agent sub-account only with capital you are prepared to risk; never keep long-term cold storage in an active bot account.
- Enforce a daily drawdown circuit breaker: if unrealized + realized PnL drops below -3% on the day, refuse new opens.
- Cap concurrent open positions (e.g., max 3 correlated crypto pairs) so a BTC flush cannot liquidate 10 altcoin longs simultaneously.
- Always read `eterna.getInstruments({ symbol })` to respect `minOrderQty` and `qtyStep` before placing live orders.
- Keep a single-prompt kill switch ready: `cancelAllOrders()` followed by `closePosition()` for every open symbol.
Frequently asked questions
How do I build an instant emergency kill switch on Eterna MCP?
Can prompt injection trick my agent into over-leveraging?
References & verification links
- Eterna SDK ReferenceExact parameters for setLeverage, placeOrder, setTradingStop, and closePosition.
Connect your AI agent in 30 seconds
One remote MCP URL. 800+ USDT perpetuals, 380+ spot pairs, 0.014% maker / 0.035% taker, no KYC.