Architecture

Artic uses a hub-and-spoke architecture where a central hub orchestrates isolated Docker agent containers.

System Topology

System Topology

Module Responsibilities

Hub

  • Auth: JWT (15 min access token) + API key (SHA-256 hashed)
  • Agent Lifecycle: CRUD, Docker spawn/stop, heartbeat monitoring
  • Market Cache: TwelveData candles via APScheduler (60s staleness, 8 req/min budget)
  • WebSocket: Real-time streaming of agent status, trades, logs to clients
  • Secrets: AES-encrypted storage with 3-tier resolution
  • Database: PostgreSQL via async SQLAlchemy + Alembic migrations

App (Trading Engine)

  • Tick Loop: Configurable interval (default 1s). Fetch price → compute indicators → run strategy → execute trades
  • LLM Planner: Analyzes market data, selects optimal strategy, defines risk parameters
  • LLM Supervisor: Optional cycle-based check on open positions for dynamic TP/SL adjustments
  • Executors: Paper trading (in-memory) or HashKey Global REST API
  • On-chain Logging: Supervisor decisions → DecisionLogged event on HashKey Chain

Strategies

  • 30+ algorithms across 5 categories
  • Dispatcher: signals.py maps strategy name → algo function
  • Contract: Every algo returns (signal: float, detail: str)

Clients

  • Thin presentation layers — all state lives in the hub
  • Hub SDK (hub/client.py) used by all clients

Data Flow

Candle Data

TwelveData → Hub (APScheduler, 60s cache) → Agents (fetch from hub)

Rate-limited to 8 requests/minute. Hub manages budget centrally.

Live Prices

Pyth Hermes → Agent (direct, free, no rate limit)

Agent → Hub (Push-based)

EndpointFrequencyPayload
POST /internal/agents/{id}/statusEvery tickCurrent state, position, P&L
POST /internal/tradesOn open/closeTrade details
POST /internal/logsEvery 10 ticksLog batch

All internal endpoints use X-Internal-Secret header authentication.

Database Schema

8 PostgreSQL tables:

TablePurpose
usersAccounts (email, password hash, API key hash)
agentsAgent config (symbol, strategy, risk params, container ID)
tradesPosition records (side, entry/exit price, PnL)
log_entriesAppend-only logs (level, message, timestamp)
market_cacheCandle cache (symbol, timeframe, JSONB candles)
user_secretsEncrypted API keys (AES ciphertext)
agent_secret_overridesPer-agent encrypted secrets
onchain_decisionsOn-chain audit trail (tx hash, reasoning)

See Authentication for secret management details.

Key Invariants

  1. Agents are stateless across restarts — persistent state lives in hub PostgreSQL
  2. Clients never talk to agent containers — hub proxies everything
  3. One agent = one symbol — isolation guarantees
  4. API keys never stored in plaintext — AES encryption mandatory
  5. Agent→Hub is push-based — agents POST status/trades/logs to hub
  6. Hub owns TwelveData rate budget — 8 req/min, centrally managed