GitHubBlog

Search Documentation

Search for a page in the docs

Accounts & Brokers

Every trading account in OpenAlice is a Unified Trading Account (UTA) — a self-contained entity that bundles a broker connection, a git-like operation history, a guard pipeline, and a snapshot scheduler.

AI and the frontend interact with UTAs exclusively. Brokers are internal implementation details.

Configuration

Accounts are defined in data/config/accounts.json:

[
  {
    "id": "alpaca-paper",
    "label": "Alpaca Paper",
    "type": "alpaca",
    "enabled": true,
    "guards": [
      { "type": "max-position-size", "options": { "maxPercentOfEquity": 20 } }
    ],
    "brokerConfig": {
      "apiKey": "your-key",
      "apiSecret": "your-secret",
      "paper": true
    }
  }
]
FieldDescription
idUnique identifier, used in source parameters and as the aliceId prefix
labelDisplay name (optional, defaults to id)
typeBroker type: ccxt, alpaca, or ibkr
enabledSet to false to skip loading this account
guardsArray of guard configs (type + options)
brokerConfigBroker-specific settings (schema varies by type)

Brokers

CCXT (Crypto)

Connects to 100+ crypto exchanges via the CCXT library. Supports Binance, Bybit, OKX, Coinbase, and more.

{
  "type": "ccxt",
  "brokerConfig": {
    "exchange": "bybit",
    "apiKey": "your-key",
    "secret": "your-secret",
    "sandbox": true,
    "demoTrading": false,
    "options": {}
  }
}
FieldDescription
exchangeCCXT exchange identifier (e.g. binance, bybit, okx, coinbase)
apiKey / secretExchange API credentials
passwordSome exchanges require a passphrase
sandboxUse the exchange's testnet/sandbox environment
demoTradingEnable demo trading mode (exchange-specific)
optionsExchange-specific options passed to CCXT constructor

For paper trading, use sandbox: true or demoTrading: true depending on the exchange. Check your exchange's documentation for testnet availability.

Alpaca (US Equities)

Commission-free US equities and ETFs with fractional share support via Alpaca.

{
  "type": "alpaca",
  "brokerConfig": {
    "apiKey": "your-key",
    "apiSecret": "your-secret",
    "paper": true
  }
}
FieldDescription
apiKey / apiSecretAlpaca API credentials
papertrue for paper trading, false for live

Alpaca paper accounts are free and provide realistic simulation with delayed market data.

IBKR (Interactive Brokers)

Professional-grade trading via TWS (Trader Workstation) or IB Gateway. Supports stocks, options, futures, and bonds.

{
  "type": "ibkr",
  "brokerConfig": {
    "host": "127.0.0.1",
    "port": 7497,
    "clientId": 1
  }
}
FieldDescription
hostTWS/Gateway host (usually 127.0.0.1)
portTWS paper: 7497, TWS live: 7496, Gateway paper: 4002, Gateway live: 4001
clientIdClient ID for the API connection (default: 1)

IBKR requires TWS or IB Gateway running locally. Enable the API in TWS under Configuration > API > Settings.

Contract Identity — aliceId

Every contract in OpenAlice has an aliceId in the format accountId|nativeKey:

alpaca-paper|AAPL          → AAPL on Alpaca paper account
bybit-demo|BTC/USDT:USDT   → BTC perpetual on Bybit demo
ibkr-live|265598            → AAPL by conId on IBKR

The nativeKey part is broker-specific:

  • Alpaca: ticker symbol (AAPL)
  • CCXT: unified symbol (BTC/USDT:USDT)
  • IBKR: conId (numeric contract identifier)

All trading tools accept aliceId to unambiguously identify which contract on which account. Use searchContracts to discover available contracts.

Account Lifecycle

The AccountManager manages UTA lifecycle:

  1. Init — Creates a UTA from config, starts async broker connection
  2. Connect — Broker initializes and verifies credentials
  3. Healthy — Broker responding normally
  4. Degraded — 3+ consecutive failures, still accepting requests
  5. Offline — 6+ failures, auto-recovery starts (exponential backoff)
  6. Disabled — Permanent error (bad credentials), requires manual fix

Health transitions emit events and are visible in the Web UI.

Multiple Accounts

You can run multiple accounts simultaneously — even across different brokers:

[
  { "id": "alpaca-paper", "type": "alpaca", "brokerConfig": { "paper": true, ... } },
  { "id": "bybit-demo", "type": "ccxt", "brokerConfig": { "exchange": "bybit", "sandbox": true, ... } }
]

Each account gets its own UTA with independent git history, guards, and snapshots. Tools that accept a source parameter let you target specific accounts or query all at once.

Runtime Management

Accounts can be added, enabled, or disabled at runtime:

  • Edit accounts.json and restart, or
  • Use the Web UI's account management panel (add/remove/enable/disable without restart)