Skip to content

Database

The project uses PostgreSQL with SQLModel (SQLAlchemy + Pydantic) and Alembic for schema migrations.

Models

All models are defined in db/models.py.

Tenants / Users / Teams

Multi-tenant hierarchy:

Tenant
  └── Team
       └── User
Model Table Key Fields
Tenant tenants id, name, slug, plan
Team teams id, tenant_id, name
User users id, tenant_id, team_id, email, role

Exchange & Accounts

Model Table Key Fields
Asset assets symbol (PK), name, asset_type, precision
ExchangeCredential exchange_credentials user_id, venue, api_key, api_secret
Account accounts user_id, venue, exchange_account_id, base_currency
AccountBalanceSnapshot account_balance_snapshots account_id, currency, total, free, locked

Trading

Model Table Key Fields
Strategy strategies strategy_id, venue, instrument_id, status
StrategyBudget strategy_budgets strategy_id, currency, allocated, reserved
StrategySignal strategy_signals strategy_id, signal_type, direction, strength
Order orders client_order_id, strategy_id, status, side, quantity
OrderFill order_fills order_id, strategy_id, fill_qty, fill_px, realized_pnl
Position positions strategy_id, instrument_id, side, quantity, avg_open_px
AuditLog audit_logs entity_type, entity_id, action, severity, before, after

Migrations

# Generate a new migration
just migration-generate "describe your change"

# Apply all pending migrations
just migration-run

# Migrate to a specific revision
just migration-run <revision>

Migrations are stored in migrations/versions/ and managed by Alembic (alembic.ini).

Notes

  • All primary keys are PostgreSQL UUID generated with gen_random_uuid()
  • Decimal fields use Numeric(precision=36, scale=18) for financial precision
  • AuditLog.before and AuditLog.after are JSONB columns for change tracking