Skip to main content

Trading Agent

The Trading vertical provides quantitative backtesting, signal generation, and execution with comprehensive safety controls.

Capabilities

  • Backtesting — Test any strategy against historical data with realistic slippage and commission modeling
  • Signal Scanner — 452 quantitative factors across RSI, MACD, momentum, volume, volatility, cross-asset correlations
  • Paper Trading — Simulated execution with real-time market prices
  • Live Trading — Real broker execution (Alpaca, Binance, Coinbase, Tradier) with safety guards
  • Pine Script Export — Generate TradingView-compatible strategy code
  • MT5 Export — Generate MetaTrader 5 Expert Advisors

API Endpoints

Run a Backtest

POST /trading/backtest
{
  "symbol": "SPY",
  "strategy": "momentum",
  "timeframe": "1d",
  "start_date": "2024-01-01",
  "end_date": "2024-12-31"
}
Returns win rate, profit factor, Sharpe ratio, max drawdown, net P&L.

Scan Signals

POST /trading/signals
{
  "symbols": ["SPY", "QQQ", "AAPL", "MSFT", "NVDA"],
  "factors": ["rsi", "macd", "momentum", "volume"],
  "timeframe": "1d"
}

Open Position (Paper)

POST /trading/positions/open
{
  "symbol": "AAPL",
  "side": "long",
  "quantity": 10,
  "stop_loss": 170.00,
  "take_profit": 195.00
}

Close Position

POST /trading/positions/{position_id}/close

Kill All Positions (Emergency)

POST /trading/positions/kill-all

Export to Pine Script

POST /trading/export/pinescript
{"strategy_id": "strat-abc123"}

Broker Connections

Connect a live broker for real execution:
GET /trading/brokers          # List available brokers
POST /trading/brokers/connect # Connect with API keys
Supported brokers:
  • Alpaca — US equities, paper + live
  • Binance — Crypto spot and futures
  • Coinbase — Crypto spot
  • Tradier — US equities and options
  • Interactive Brokers — Multi-asset (coming)
  • MetaTrader 5 — Forex and CFDs (coming)

Safety Guards

Every trade passes through the SafetyGuard before execution:
GuardDefaultPurpose
Max position size$10,000Cap per-trade risk
Max daily loss$500Stop trading if losing too much
Max drawdown5%Kill switch if portfolio drops
Max open positions20Prevent over-concentration
Mandate expiry24 hoursAuto-revoke trading authority
Require stop lossYesEvery position must have a stop

Desktop Integration

In the Desktop app, the Trading Operator can:
  • Open TradingView charts directly in the embedded browser
  • Visually identify setups from chart patterns (via LLM vision)
  • Execute trades with one-click confirmation
  • Monitor positions with real-time P&L