Deflow - autonomy, with limits.

Welcome to Deflow

Deflow is an autonomous options trading desk. Four specialised agents observe the market, structure defined-risk option spreads, audit them adversarially and route them to a live Alpaca paper account - under a deterministic risk gate that no language model can talk its way past.

The AI is not a chat feature bolted onto a trading bot. The agents run the desk end to end on a five-minute cycle, and refusing to trade is a first-class output: roughly half of all symbol-cycles end with the desk declining, on the record, with the stage and reason attached. Every decision is written to a hash-chained ledger anyone can verify.

  • Measured, not vibes - implied volatility against a jump-robust forecast of realised volatility
  • Bounded, always - every structure has a defined maximum loss before it is ever proposed
  • Checkable, forever - a tamper-evident ledger and the broker's own marks on the dashboard

Where everything lives

BrokerAlpaca paper account · options level 3 · $100,000 start
Reasoning modelQwen/Qwen2.5-72B-Instruct via Featherless
Risk gatev2.0.0 · 12 deterministic breakers · stdlib only
First live session2026-09-01

How it works

Every five minutes during US market hours the desk runs one cycle over its universe (SPY, QQQ, IWM, AAPL, MSFT, NVDA, AMD, TSLA):

analyse → structure → reason → audit → gate → route → reconcile

The Analyst measures each name and refuses anything without a measured edge. The Structurer builds candidate spreads from the live chain. The reasoning model picks among them - among them only; it cannot invent a trade. The Auditor attacks the choice with Monte Carlo and real transaction costs. The gate rules. The Executor routes. And on the next cycle the desk reconciles: an accepted order is not a fill, and the book only changes when the broker confirms one.


The four agents

Agent 1 · Macro & Volatility Analystmeasures the variance risk premium and the trend regime for every name, and stands down anything inside the noise band
Agent 2 · Options Structurerturns a tradeable view into defined-risk verticals and condors, strikes from the live chain, priced from real quotes
Agent 3 · Adversarial Risk Auditorargues against every proposal: jump-diffusion Monte Carlo under the physical measure, round-trip cost from the real bid/ask - a fatal objection kills the trade before the gate sees it
Agent 4 · Execution Agentroutes approved structures to Alpaca as native multi-leg orders, re-checking the gate immediately before submission

The edge: variance premium

Option prices embed a forecast of volatility. Deflow builds its own - bipower variation, a jump-robust estimator that a single earnings gap can't distort - and trades only the gap between the two, in either direction:

Implied rich vs forecast (> +2%)sell premium - credit spreads
Implied cheap vs forecast (< −1%)buy convexity - debit spreads
Inside the bandstand down - no measured edge, no trade

The desk also reads the IV term structure for priced-in catalysts: an inverted curve means the market is paying up for an event, and short-dated premium selling stands down around it.


The deterministic gate

Twelve circuit breakers, pure standard-library Python, zero LLM involvement, microseconds per evaluation. All twelve always run - no short-circuiting - and the gate runs twice: once at approval, again immediately before the order leaves. It fails closed, and it sizes trades down before it vetoes them.

01 defined_risk_structureevery structure must have a bounded max loss
02 max_loss_2pctmax loss of the trade ≤ 2% of account equity
03 trade_delta_boundnet delta of the structure within ±0.35
04 probability_of_profitcredit: ≥ 65% win rate · debit: ≥ 30% plus positive expectancy
05 aggregate_risk_6pctcapital at risk across the whole book ≤ 6% after the fill
06 symbol_concentration_3pctrisk in any one underlying ≤ 3%
07 portfolio_delta_boundbook net delta within ±1.2 after the fill
08 max_open_positionsat most 6 open structures
09 dte_window7 to 60 days to expiry
10 payoff_qualitycredit ≥ 15% of spread width · debit reward/risk ≥ 0.8
11 daily_drawdown_killswitchtrading halts at −3% on the day
12 vega_ceilingbook |vega| ≤ 2.5 per $1,000 of equity

Try it yourself: the dashboard's risk-gate panel submits a deliberately bad trade - a naked call - and shows which breakers trip, live, with the gate's own wording.

Order & exit lifecycle

Submitted is not filled. Entries and exits both live as working orders until the broker confirms a fill; only then does the book change, at the price actually given. A stale order is cancelled - and dropped only when the broker confirms the cancel, because a cancel acknowledgement is a request, not an outcome, and an order can still fill while it is pending.

Exits are priced from the position's current mark, never its entry price, with the concession always against the desk. Positions carry a profit target that tightens as expiry approaches, a stop at 50% of max loss, and a hard exit at 3 days to expiry. A mark that falls outside the structure's own payoff bounds is flagged suspect and cannot fire an exit - bad quote data defers one cycle rather than realising a phantom loss.


Decision ledger

Every event the desk produces - analyst views, proposals, audits, gate verdicts, orders, fills, exits, refusals - is appended to a ledger where each entry carries the SHA-256 of the one before it. Altering or deleting any historical record breaks the chain from that point forward, visibly and permanently.

Verify over HTTPGET /api/ledger/verify
Cross-process safetyfile-locked appends; the head is re-derived under the lock

Refusals

Most systems only show what they did. Deflow's most informative output is what it declined to do: every refusal is recorded with the stage that made it - the analyst saw no edge, the model abstained, the auditor objected fatally, or the gate vetoed - and its exact reason. The dashboard's refusals panel is the desk's actual behaviour, not an absence of it.


Self-hosting & running

git clone https://github.com/mrnetwork0001/Deflow.git && cd Deflow
python -m venv .venv && .venv/bin/pip install -r requirements.txt
cp .env.example .env   # add your Alpaca + Featherless keys
.venv/bin/python main.py
No credentialsruns against a seeded simulated market - everything works, nothing is live
DEFLOW_DRY_RUN=truefull pipeline, no orders submitted
DEFLOW_PORTAPI + dashboard port (default 8000)
DEFLOW_CYCLE_SECONDScycle cadence (default 300)
Deploy scriptsdeploy/ - additive installs for a shared VPS, systemd unit, Caddy site

One command brings up the desk, the API and the dashboard: the frontend is a static export served by the same FastAPI process, so there is no Node runtime in production.

HTTP API

Read-only observability plus two deliberate write endpoints. There is no endpoint that places an order directly - orders exist only as the output of a full pipeline that has cleared the gate.

GET /api/statuseverything the dashboard shows: performance, market state, working orders
GET /api/performanceequity and P&L on the broker's marks, with the desk's mid-marks labelled
GET /api/positionsopen and closed structures
GET /api/refusalsevery trade the desk declined, attributed to the stage that said no
GET /api/ledgerthe hash-chained decision ledger, filterable by event
GET /api/ledger/verifyre-derives the chain and reports the first break, if any
GET /api/pnl-card?date=one trading day summarised for a shareable card
GET /api/streamserver-sent events: the decision stream, live
POST /api/cyclerun one full trading cycle now
POST /api/risk/evaluatesubmit a hypothetical trade; the twelve breakers rule on it

Trust model & FAQ

Is this real money?No - a live Alpaca paper account with real market data and real order routing. Simulated results are hypothetical and do not represent actual trading.
Can the LLM bypass the risk gate?Structurally impossible: the gate is pure standard-library Python with no LLM in the call path, it runs twice, and the model's only power is choosing among structures the Structurer already built.
Whose numbers are on the dashboard?The broker's. Equity and P&L come from Alpaca's own marks and the panel says so; the desk's internal quote-mid marks are shown alongside, labelled, because the two genuinely differ and hiding either would be lying by omission.
What happens on a crash or redeploy?The book, working orders and working exits are persisted and restored; closing orders carry deterministic client ids so a restart cannot double-submit; and the hash chain makes any gap in the record visible.
Why so few trades?By design. The desk trades only when it measures an edge and the gate agrees the risk fits - a desk that must trade every cycle is a random number generator with commissions.