Agent Configuration

Each agent is configured at creation time via the Hub API. This page covers all configuration options.

Creating an Agent

POST /api/agents
Authorization: Bearer <token>
Content-Type: application/json

{
  "symbol": "BTC/USDT",
  "strategy_name": "momentum_breakout",
  "interval_seconds": 1,
  "live_mode": false,
  "risk_params": {
    "max_position_usd": 1000,
    "stop_loss_pct": 2.0,
    "take_profit_pct": 4.0,
    "leverage": 1
  }
}

Configuration Fields

FieldTypeRequiredDescription
symbolstringYesTrading pair (e.g., BTC/USDT, ETH/USDT)
strategy_namestringYesAlgorithm name from Strategy Catalog
interval_secondsintNoTick interval in seconds (default: 1)
live_modeboolNofalse = paper trading, true = live execution
risk_paramsobjectNoRisk management configuration (see below)

Risk Parameters

The risk_params JSONB field controls position sizing and risk management:

ParameterTypeDescription
max_position_usdfloatMaximum position size in USD
stop_loss_pctfloatStop-loss percentage (e.g., 2.0 = 2%)
take_profit_pctfloatTake-profit percentage (e.g., 4.0 = 4%)
leverageintLeverage multiplier (1-125x)

Dynamic TP/SL

When the LLM supervisor is enabled, it can dynamically adjust stop-loss and take-profit levels based on:

  • ATR-based stop-loss calculation
  • Automated risk:reward ratio
  • Market condition changes

The supervisor runs on a configurable cycle (every N ticks on open positions).

LLM Configuration

The LLM provider is configured via secrets (environment variables or encrypted DB storage):

Secret KeyPurpose
LLM_PROVIDERProvider name: openai, anthropic, deepseek, gemini
LLM_MODELModel name (e.g., gpt-4o, claude-3-opus, deepseek-chat)
OPENAI_API_KEYOpenAI API key
ANTHROPIC_API_KEYAnthropic API key
DEEPSEEK_API_KEYDeepSeek API key
GEMINI_API_KEYGoogle Gemini API key

LLM Planning Cycle

  1. Agent collects market data (candles, indicators, price history)
  2. LLM analyzes the data and selects the best strategy
  3. LLM defines lookback period, threshold, and max loss percentage
  4. Strategy runs on the selected parameters
  5. LLM reasoning is captured for audit trail

Execution Modes

Paper Trading (Default)

  • live_mode: false
  • Positions tracked in-memory
  • No real orders placed
  • Full P&L simulation

Live Trading

  • live_mode: true
  • Requires HASHKEY_API_KEY and HASHKEY_SECRET
  • Orders placed on HashKey Global exchange
  • Set HASHKEY_SANDBOX: true for sandbox testing

Per-Agent Secrets

Override user-level secrets for specific agents:

POST /api/agents/{id}/secrets
Authorization: Bearer <token>
Content-Type: application/json

{
  "key_name": "OPENAI_API_KEY",
  "encrypted_value": "<AES-encrypted-value>"
}

Secret resolution order (first match wins):

  1. Ephemeral override (per-request, never stored)
  2. Agent-specific override (encrypted in DB)
  3. User-level secret (encrypted in DB)
  4. Process .env fallback

Agent Lifecycle

StatusDescription
creatingDocker container being provisioned
runningTrading loop active
stoppedManually stopped, container preserved
errorFailed to start or crashed

Management Commands

# List all agents
GET /api/agents

# Get agent details
GET /api/agents/{id}

# Stop an agent
POST /api/agents/{id}/stop

# Delete an agent (removes container)
DELETE /api/agents/{id}

Log Levels

Agent logs use structured levels for filtering:

LevelWhen
initAgent startup and config loading
llmLLM planning/supervisor calls
startTrading loop started
tickEach price tick processed
actionPosition opened or closed
sl_tpStop-loss or take-profit triggered
stopAgent stopped
errorError occurred
warnWarning condition
supervisorLLM supervisor adjustment