Skip to content

Database Schema

Ground truth for the schema lives in gordon-migrate/migrations/. This page is a navigable inventory — for exact column definitions, consult the migration files directly.

38 migrations as of 2026-05-17. search_path = trading, market_data, public.

market_data schema

Written exclusively by gordon-data. Other services read via named views (migration 0019). gordon_lab_reader role has INSERT/UPDATE/DELETE revoked — any write attempt fails with InsufficientPrivilege.

TablePurpose
spot_klines1m canonical klines from Binance spot; higher TFs precomputed by gordon-data from this source
perp_klinesBinance perpetual futures klines
funding_rates8h Binance funding rates per symbol
open_interestHourly open interest snapshots
metricsDerived metrics: VPIN, long/short ratio, liquidation volumes
fear_greedDaily Fear & Greed index from alternative.me
stablecoin_supplyDaily stablecoin supply ratio (SSR) from DefiLlama
gamma_exposureGEX aggregate snapshots (flip point, call/put walls, regime) from Deribit
gamma_exposure_strikesGEX per-strike profile for replay
source_freshnessPer-source ingest liveness. Written by gordon-data scheduler; consumed by console via manager WS source_freshness channel.
macro_dataFRED macro series (DXY, VIX, etc.)

Named reader views (migration 0019)

Direct SELECT on market_data.* underlying tables is revoked for gordon_manager and gordon_risk roles. Access is via:

ViewUnderlying sourceUsed by
v_klines_readerspot_klinesgordon-manager (backtest, warmup BFF)
v_metrics_readermetricsgordon-manager, gordon-risk (VPIN breaker)
v_macro_readermacro_datagordon-risk (MacroBreaker)
v_funding_rates_readerfunding_ratesgordon-manager
v_open_interest_readeropen_interestgordon-manager
v_gex_readergamma_exposuregordon-manager (migration 0028)

trading schema

Backed up hourly to srv-core via restic. Multiple writers per table (see Database configuration for the role matrix).

Bot lifecycle

TablePurpose
bot_configsDeclarative bot config: desired_state, image_tag, strategy_params. Full-row lifecycle owned by gordon-manager; desired_state column also updated by gordon-risk (pause/resume).
bot_leasesAdvisory-lock lease per bot. holder_bot_id, fence_token, lease_key
bot_deploysGreen/blue deploy state machine records
bot_strategy_statePersisted strategy state per bot (serialized Rust struct)
symbol_subscriptionsPer-bot symbol subscription records
service_deploysService-level deploy records (migration 0029)

Order flow

TablePurpose
order_intentsIntent queue from gordon-bot to gordon-executor
ordersOrder state machine: submitted → acked → filled/rejected/cancelled
order_eventsState-transition events per order
fill_eventsFill records from the exchange. Keyed on deterministic trade_fingerprint.
shadow_ordersShadow compare orders during green/blue deploys (migration 0030)
agg_tradesAggregated trade records (migration 0032)

Runs and analytics

TablePurpose
runsTrading sessions: backtest, paper, and live. Carries strategy_code_revision (migration 0038).
tradesIndividual fills aggregated to trade level
roundtripsEntry-exit pairs
signalsStrategy signal log
equity_pointsPortfolio equity curve time series
performance_snapshotsAggregate metrics snapshots per run

Risk and control

TablePurpose
risk_stateHalt latch: halted boolean. Flips TRUE on flatten/breaker trip; clears on POST /risk/resume.
risk_eventsCircuit-breaker trip audit log. Written by gordon-risk only.
risk_audit_logOperator action audit: flatten, resume, pause. Written by gordon-risk only.
risk_configRuntime-tunable breaker thresholds (key/value store)
bot_commandsCommands from gordon-risk to executor/bot (flatten, pause). At-least-once via NOTIFY cursor.
bot_eventsLifecycle events from bots and executor (heartbeat, drain, fill, flatten step)
positionsCurrent open positions. Updated by positions_apply_trade() trigger on trading.trades.
reconcile_runsExecutor reconcile outcomes per startup
pipeline_stateLISTEN/NOTIFY consumer cursor offsets per service/channel

Daily notional caps (migration 0036)

TablePurpose
daily_notional_per_botRolling UTC-day notional per bot (optional enforcement — see EXECUTOR_CAP_REJECT_PER_BOT_DAILY)
daily_notional_globalRolling UTC-day notional across all bots (optional enforcement — see EXECUTOR_CAP_REJECT_GLOBAL_DAILY)

bus schema

TablePurpose
bus.outboxDual-write buffer for NATS delivery. Drain worker atomically reads and publishes to JetStream.

Source of truth

gordon-migrate/migrations/ is the authoritative source. Run cargo test -p gordon-migrate --test grant_matrix to verify role privileges match the documented matrix.

Gordon — keep compounding without blowing up