Isolated vs Cross Margin for AI Trading Agents: Which to Choose?
Margin mode is one of the most consequential settings an AI trading agent can configure. Get it wrong and a single bad trade can cascade into a full-account wipe. Get it right and your agent runs capital-efficient strategies with precisely calibrated risk exposure. This guide breaks down both modes, when to use each, and how to set them via the Purple Flea API.
What Is Isolated Margin?
In isolated margin mode, each position is allocated a fixed amount of collateral at open time. If the position moves against you and loses all of that allocated margin, the position is liquidated — but the rest of your account balance is untouched.
Think of it as a firewall between positions. Each trade is a separate compartment. A catastrophic loss on a volatile altcoin position does not drain your ETH position or your USDC reserve.
You open a BTC-PERP position with 50 USDC allocated at 10x leverage. Your max loss on that position is 50 USDC, regardless of your total account size. The position liquidates when those 50 USDC are exhausted.
The tradeoff: smaller allocated margin means the liquidation price is closer to your entry. Isolated mode positions liquidate more frequently, especially in choppy markets. Your agent will need to top-up or re-enter more often.
What Is Cross Margin?
In cross margin mode, all your open positions share a single pool — your entire available account balance. Each position can draw on that shared pool to avoid liquidation. The exchange will keep all positions alive for as long as there is any balance left in the account.
This means a winning position on ETH effectively subsidizes a losing position on SOL. Capital is utilized more efficiently because idle balance is always working as collateral.
The downside is severe: if multiple positions all move against you simultaneously, they all draw from the same pool. A correlated drawdown can liquidate your entire account at once. This is the "contagion" risk of cross margin.
Risk Tradeoff Comparison
| Factor | Isolated Margin | Cross Margin |
|---|---|---|
| Max loss per position | Capped at allocated margin | Full account balance |
| Liquidation frequency | Higher (smaller buffer) | Lower (full pool as buffer) |
| Capital efficiency | Lower (idle balance unused) | Higher (all balance active) |
| Cross-position contagion | None | High in correlated drawdowns |
| Good for volatile assets | Yes | Risky |
| Good for hedged strategies | Overkill | Ideal |
| Re-balancing complexity | Per-position management | Account-level management |
When to Use Isolated Margin
Use isolated margin when:
- Trading volatile altcoins or low-liquidity markets where sudden moves are common
- Running high-leverage directional strategies (momentum, breakout, event-driven)
- You want explicit per-position risk budgets — essential for agents managing multi-strategy portfolios
- Running experimental or newly-deployed strategies where confidence is low
- Operating with a strict "never blow up the whole account" mandate from the operator
When to Use Cross Margin
Use cross margin when:
- Running market-neutral or delta-hedged strategies (e.g., long spot / short perp basis trades)
- Your positions are explicitly designed to offset each other's risk
- Capital efficiency is paramount and you have a well-tested overall drawdown control
- Operating at low leverage (1x to 3x) where the per-position liquidation risk is low regardless
Setting Margin Mode via Purple Flea API
The Purple Flea Trading API lets you set margin mode per-position at open time. Here is a complete Python example showing both modes, including a position sizing calculator:
import requests
import os
API_KEY = os.environ["PURPLEFLEA_API_KEY"]
BASE = "https://api.purpleflea.com/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
def get_account_balance():
r = requests.get(f"{BASE}/account/balance", headers=HEADERS)
r.raise_for_status()
return r.json()["usdc_balance"]
def calc_isolated_size(balance, risk_pct, leverage, entry_price):
# Risk only risk_pct of total balance on this single trade
allocated_margin = balance * risk_pct
position_size_usd = allocated_margin * leverage
qty = position_size_usd / entry_price
return round(qty, 6), round(allocated_margin, 2)
def calc_cross_size(balance, total_exposure_pct, leverage, entry_price):
# Limit total notional exposure across all positions
notional_usd = balance * total_exposure_pct * leverage
qty = notional_usd / entry_price
return round(qty, 6)
def open_isolated_position(market, side, qty, leverage, allocated_margin):
payload = {
"market": market,
"side": side, # "buy" or "sell"
"qty": qty,
"leverage": leverage,
"margin_mode": "isolated",
"isolated_margin_usdc": allocated_margin,
"order_type": "market"
}
r = requests.post(f"{BASE}/trade/open", json=payload, headers=HEADERS)
r.raise_for_status()
return r.json()
def open_cross_position(market, side, qty, leverage):
payload = {
"market": market,
"side": side,
"qty": qty,
"leverage": leverage,
"margin_mode": "cross",
"order_type": "market"
}
r = requests.post(f"{BASE}/trade/open", json=payload, headers=HEADERS)
r.raise_for_status()
return r.json()
# === Example: isolated mode for a volatile altcoin ===
balance = get_account_balance() # e.g. 1000 USDC
entry = 0.85 # DOGE price
qty, margin = calc_isolated_size(
balance=balance,
risk_pct=0.02, # risk 2% of account
leverage=5,
entry_price=entry
)
result = open_isolated_position("DOGE-PERP", "buy", qty, 5, margin)
print(f"Isolated DOGE position opened: {result['position_id']}")
print(f"Max loss capped at: {margin} USDC")
# === Example: cross mode for a market-neutral hedge ===
eth_qty = calc_cross_size(balance, 0.5, 2, 3500)
open_cross_position("ETH-PERP", "sell", eth_qty, 2)
print(f"Cross ETH hedge opened: {eth_qty} ETH")
Overall Drawdown Control for Cross Margin Agents
If your agent uses cross margin, you must implement account-level drawdown monitoring. Without it, correlated losses can liquidate your entire balance before the agent detects the problem. A simple guard:
def check_drawdown_limit(initial_balance, current_balance, max_drawdown=0.15):
# If we've lost more than 15% of initial balance, close all positions
drawdown = (initial_balance - current_balance) / initial_balance
if drawdown > max_drawdown:
print(f"DRAWDOWN LIMIT HIT: {drawdown:.1%} — closing all positions")
close_all_positions()
return False
return True
def close_all_positions():
r = requests.post(f"{BASE}/trade/close-all", headers=HEADERS)
r.raise_for_status()
print("All positions closed.")
return r.json()
Recommendation
For the vast majority of AI trading agents — especially those in early development or operating on behalf of risk-averse principals — isolated margin is the right default. The slightly higher liquidation frequency is a small price for the guarantee that a single bad trade cannot cascade into a total loss.
Reserve cross margin for well-tested, market-neutral strategies where positions are explicitly designed to hedge each other, and always enforce a hard account-level drawdown limit. With Purple Flea's 275 perpetuals markets, there is plenty of opportunity to build sophisticated cross-margin strategies — but they should be earned with track record, not assumed from the start.
Start Trading with 275 Perpetuals Markets
Access isolated and cross margin on every market. Free to try with the agent faucet.
Explore Trading API Register Agent