GapGuard Built on Bitget

Architecture

How GapGuard works

A deterministic pipeline turns each market tick into a risk-governed, auditable decision. The model gates conviction; it never overrides the risk rules.

The edge

Tokenized US stocks trade 24/7, but the underlying market is open only ~6.5 hours per weekday. Off-hours, the token has no real price discovery — it drifts on crypto-market sentiment, then snaps toward fair value at the next US open. GapGuard only takes the trade while the underlying is closed, and realizes it into the reopen.

The pipeline

One tick — a token price, a fair-value anchor, and recent volatility — flows through seven stages:

  • Session clock (marketClock.ts) — classifies the US session against a verified 2026 NYSE calendar; underlyingOpen gates the edge.
  • Dislocation (dislocation.ts) — measures the token-vs-fair-value gap in volatility units (a z-score) and labels it rich / cheap / fair with a confidence.
  • Fair value (proxyReturn.ts) — blends 24/7 proxy signals (index futures, sector-ETF tokens) into an implied underlying return, damped by the blend’s own confidence so a weak or scattered proxy can’t swing fair value at full strength.
  • LLM gate (convergenceGate.ts + Qwen) — classifies the gap as fadeable noise or justified repricing; a non-fadeable verdict zeroes conviction so the agent never fades real overnight news.
  • Risk governor (riskGovernor.ts) — the differentiator below.
  • Glass box (glassbox.ts) — appends the decision to a tamper-evident hash chain.
  • Hedge router (hedgeRouter.ts) — maps the decision onto Bitget’s real instruments.

The risk governor

The convergence edge exists only while the underlying is closed, so the governor sizes positions by confidence and volatility under a tighter off-hours cap, realizes into the reopen, and halts on a hard drawdown breaker. A rebalance deadband keeps it from churning on noise. This directly counters the documented failure mode of LLM traders that ignore sizing and risk.

The glass box

Every decision is appended verbatim to a JSONL audit trail and sealed into a sha256 hash chain: each record carries a recordHash over its canonical payload plus the previous record’s hash. Alter any past decision and verifyChain() breaks. The cockpit recomputes that chain in your browser — so the audit trail isn’t just transparent, it’s verifiable.

The hedge router

GapGuard’s signal is on the token, but Bitget’s tokenized xStocks are spot-only — long-or-flat, no native short. So a long discount rests on the token (onchain-spot), while a “rich” short routes to the matching USDT-margined stock perpetual (TSLAUSDT, usdt-futures), which is shortable and trades ~24/7. That hedge is what makes a rich-gap fade executable at all.

Honest limits. The router is deterministic — live API execution isn’t wired (no trading keys), and Bitget’s docs conflict on whether a new perp can be opened during a US-market closure, so the router surfaces that as a closureCaveat rather than assuming it. The Playbook backtest runs on daily bars, which validate the reversion logic but understate the intraday snap-back; and Bitget’s managed backtest path is crypto-only, so the equity run logs real metrics author-side rather than as a managed run.

Run it

Everything is reproducible from the repo:

  • npm run demo — replay a weekend gap end-to-end; writes the hash-chained glass box.
  • npm run gate-demo — the Qwen convergence gate on noise vs a real earnings beat.
  • npm run hedge-demo — how each decision routes to a Bitget instrument.
  • npm test — 43 tests across the pipeline.

Watch it decide — and verify it.

The cockpit renders a real run and recomputes the audit chain live.