Leverage Trading

Leverage Trading API for AI Agents

Give your AI agents access to leveraged perpetual futures. Up to 50x leverage on 275 markets including BTC, ETH, SOL, and hundreds of altcoins — via Purple Flea's simple REST API backed by Hyperliquid's institutional-grade order book.

Get Free API Key → Trading API Docs
275
Perpetual Markets
50x
Max Leverage
<100ms
Order Execution
24/7
Market Hours

Why Leverage Matters for AI Agents

Leverage multiplies both gains and losses. AI agents, unlike humans, can apply risk management rules with perfect consistency — making leverage safer in algorithmic hands.

📈
Capital Efficiency
With 10x leverage, $100 controls $1,000 of position. An agent can deploy its full capital across more positions simultaneously, diversifying risk while amplifying potential returns.
🎯
Precise Risk Sizing
Agents can target exact dollar-risk per trade regardless of leverage. A $10 risk on a $1,000 position is a 1% stop-loss with 1x leverage, or a 0.1% stop-loss with 10x. Precision impossible for humans.
🔄
Delta-Neutral Strategies
Low leverage (1-3x) enables delta-neutral funding rate harvesting — earning the funding payment without directional risk. A reliable 30-150% APY strategy that leverage makes efficient.
Instant Execution
Leveraged positions respond instantly to agent signals. When your LLM detects a market opportunity, Purple Flea executes the leveraged trade in under 100ms — before the opportunity closes.
🛡️
Programmatic Stop-Loss
Every leveraged position gets an automatic stop-loss. Agents never forget to set one (unlike humans). Set stop-loss and take-profit levels at trade opening, adjust via API as market moves.
📊
Real-Time P&L Tracking
Every position returns live P&L, liquidation price, margin ratio, and funding accrued. Agents monitor portfolio health and auto-deleverage before reaching dangerous margin levels.

Leverage Trading Code Examples

Open Leveraged Position

import purpleflea as pf client = pf.Client(api_key="YOUR_KEY") # Open 5x leveraged long on BTC trade = client.trading.open_trade( symbol="BTC", side="long", size=0.01, # 0.01 BTC leverage=5, # 5x leverage order_type="market", stop_loss=0.02, # 2% stop-loss take_profit=0.06 # 6% take-profit (3:1 RR) ) print(f"Position: {trade['position_id']}") print(f"Fill price: ${trade['fill_price']:,.2f}") print(f"Liquidation price: ${trade['liquidation_price']:,.2f}") print(f"Required margin: ${trade['margin_required']:.2f}") # Monitor position pos = client.trading.get_position(trade['position_id']) print(f"Unrealized P&L: ${pos['unrealized_pnl']:.2f}") print(f"Current leverage: {pos['effective_leverage']:.1f}x")

Risk-Managed Agent

class LeverageRiskManager: """Enforces leverage limits and position sizing.""" MAX_LEVERAGE = 5 MAX_PORTFOLIO_RISK = 0.02 # 2% per trade MAX_TOTAL_LEVERAGE = 2.0 # Portfolio-level def __init__(self, client): self.client = client def safe_open_trade(self, symbol: str, direction: str, confidence: float) -> dict | None: # Get current portfolio state balance = self.client.wallet.get_balance() positions = self.client.trading.get_all_positions() total_exposure = sum(p['notional_value'] for p in positions) portfolio_value = float(balance['total_usd']) current_leverage = total_exposure / portfolio_value if current_leverage >= self.MAX_TOTAL_LEVERAGE: print(f"Portfolio leverage {current_leverage:.1f}x at max. Skipping.") return None # Size based on confidence and risk limit risk_usd = portfolio_value * self.MAX_PORTFOLIO_RISK * confidence leverage = min(int(confidence * 10), self.MAX_LEVERAGE) price = self.client.trading.get_price(symbol)['price'] size = (risk_usd * leverage) / price / 0.02 # 2% stop trade = self.client.trading.open_trade( symbol=symbol, side=direction, size=size, leverage=leverage, stop_loss=0.02, take_profit=0.06 ) print(f"Opened {direction} {symbol} {leverage}x | risk: ${risk_usd:.2f}") return trade

Give Your Agents Leverage

Access 275 perpetual markets with up to 50x leverage through a simple REST API. Deploy agents that trade with capital efficiency and programmatic risk management.