Overview
Autonome’s autonomous trading system orchestrates AI agents that continuously analyze market data, manage positions, and execute trades with minimal human intervention. Each agent operates on a 5-minute polling cycle, using real-time indicators, portfolio state, and performance metrics to make informed decisions.Trading Loop Architecture
The trading loop follows a structured workflow that ensures consistency and auditability:Market Data Aggregation
Fetch real-time OHLCV data, technical indicators (RSI, MACD, EMA, Bollinger Bands), and funding rates from exchange APIs.
Portfolio State Snapshot
Retrieve current account balance, open positions with unrealized P&L, available cash, and exposure metrics.
AI Agent Invocation
Execute the trading agent with a structured prompt containing market intelligence, portfolio state, performance history, and strategy-specific instructions.
Tool Execution
Process agent tool calls (
createPosition, closePosition, updateExitPlan, holding) and execute orders via the exchange simulator or live API.Decision Framework
Agents use a multi-step reasoning process powered by the AI SDK v6:Tool Context
Agents receive a ToolContext object that tracks session state and enforces constraints:The
actedSymbols set prevents duplicate actions on the same symbol within a single invocation, while symbolActionCounts enforces session-wide limits (default: 3 actions per symbol per session).Agent Tools
Agents interact with the trading system via four core tools:createPosition
Opens one or more positions atomically. Validates cooldown periods, available cash, and symbol limits.
invalidation_condition: Qualitative thesis break (e.g., “Reversal candle”)invalidation_price: Exact price where thesis is invalidatedtime_exit: Time-based exit rule (e.g., “Close if held >2h”)cooldown_minutes: Prevents direction flips (1-15 min)
closePosition
Closes one or more open positions at market price.
updateExitPlan
Modifies stop loss, take profit, or invalidation levels for open positions (e.g., trailing stops).
holding
Explicit no-action decision with reasoning. Required when no trades are taken.
Cooldown System
To prevent impulsive direction flips, Autonome enforces cooldown periods:- While Holding: Cannot open opposite direction until cooldown expires
- After Closing: Cooldown persists after exit (tracked in
closedPositionCooldowns) - Same Direction: Cooldown does not block adding to existing positions
Prompt Structure
Prompts follow a spoon-feeding philosophy: provide all data explicitly, never require the AI to infer or calculate.- Explicit labels:
risk_usd $128.56notrisk $128.56 - Show zeros:
scaled_realized $0.00is meaningful - Omit N/A: Don’t show data that doesn’t exist
- No duplication: Each metric lives in exactly one section
Execution Pipeline
WhencreatePosition is called, the system:
- Validates cooldowns, symbol limits, and available cash
- Normalizes decisions (uppercase symbols, clamp leverage)
- Executes orders via
ExchangeSimulatoror Lighter API - Tracks fills using
fillTracker.ts(polls for actual execution price) - Records tool calls in
ToolCallstable for audit trail - Updates
Orderstable (single source of truth for positions) - Emits SSE events to update UI in real-time
Auto-Close Triggers
The simulator monitors open positions and automatically closes them when:- Stop Loss Hit: Mark price <= stop loss (longs) or >= stop loss (shorts)
- Take Profit Hit: Mark price >= take profit (longs) or <= take profit (shorts)
ToolCalls table with autoTrigger metadata for transparency.
State Synchronization
The system maintains consistency between simulator state and database:- Bootstrap: On startup,
restorePositionsFromDb()rehydrates simulator fromOrderstable - Polling: Every
refreshIntervalMs(default: 5s), fetch market prices and check triggers - SSE Events: Emit
allDataChangedevents to invalidate TanStack Query caches
Related Resources
AI Strategy Prompts
Explore variant-specific prompts and reasoning styles
Trading Simulator
Learn how the simulator mirrors live trading
Portfolio Analytics
Deep dive into performance metrics and calculations
Configuration
Configure API keys, schedulers, and simulator options

