Live Trading Portfolio

How strategies trade real money: dollar amounts, automatic reconciliation, close-all, and the kill switch.

Overview

The trading portfolio is the set of strategies allowed to place real orders. Each strategy in it gets a fixed dollar amount; the reconciler daemon then keeps your exchange positions converged to the combined target — you never place these orders yourself.

strategy.py ──► state.json ──────────────┐
   (cron)                                ├──► reconciler.py ──► exchange
amounts     ──► portfolio_config.json ───┘

Amount-Based Sizing

Each strategy in the portfolio is assigned an amount in account currency (e.g. USD) — what the strategy trades with when its signal is at full size. The target position per symbol is the sum across strategies:

target[symbol] = Σ ( amount × position )

position is the strategy's signal and can be fractional (a vol-scaled strategy may emit 0.5 or 1.8). The amount you set is exactly what sizes positions — it does not drift with account equity.

Never edit manager/portfolio_config.json by hand. Set amounts from the workspace Trading setup page or ask the agent; optimizer weights are applied only through manager.py, which is dry-run by default and writes the config only with --apply after you confirm.

The Reconciler

The reconciler is a daemon that polls every 5 seconds and reconciles whenever:

  • a strategy updates its signal (state.json changes)
  • you save new amounts in Trading setup
  • the kill switch is tripped or cleared
  • 5 minutes passed without a reconcile — a safety net that catches position drift and dead exchange keys

Each pass compares the target against your actual exchange positions and places market orders to close the gap; differences under $10 are ignored. A position flip (long → short) is split into a reduce-only close plus a fresh open, so hedge-mode accounts never hold both sides at once.

If reading positions from the exchange fails 3 times in a row (revoked key, IP not whitelisted, outage), the reconciler trips the kill switch automatically. It never clears it — only you do.

Close All Positions

The Close all positions button in the workspace (or python3 manager/flatten.py) market-closes every open position on every connected exchange. It is a panic button, not portfolio management:

  • The kill switch is tripped first, so nothing re-opens after the flatten — trading stays paused until you press Start trading.
  • Positions below the exchange minimum can't be closed — the dust is logged and left.
  • Every close is written to the order history with its exchange-confirmed fill.

Kill Switch (HALT)

While the kill switch is on, any order that would add exposure is refused at the code level. Closing positions, stop-loss / take-profit, and cancels still go through — a halt never traps a position you are trying to reduce.

It is set by Pause trading or Close all positions in the workspace, by telling the agent to stop trading, or automatically on exchange disconnect. It is never cleared automatically — trading resumes only when you press Start trading or explicitly ask the agent to resume. Every order attempt and denial is written to an audit log.

Order History & Fills

Every executed order is appended to manager/orders.jsonl with its legs — the exchange-confirmed fill price and executed quantity of each individual leg. A position flip records two legs: the closing leg carries the exit price, the opening leg the entry price.

Partial failures are recorded too: if a flip's closing leg filled but the opening leg failed, the entry is kept and marked failed — the history never hides an order that moved real money. The workspace Order History tab renders this file.

Next: how amounts are suggested from your strategies' backtests is covered in Portfolio Management.