Ignore:
Timestamp:
09/24/26 17:43:19 (5 days ago)
Author:
Stefan <trsunovstefan@…>
Branches:
main
Children:
0cee8ec
Parents:
a531b45
Message:

Wiki docs, phase 6 and phase 7 added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/db/schema_creation.sql

    ra531b45 ref1c1c7  
    2626    available_balance numeric(18,4)   NOT NULL DEFAULT 0 CHECK (available_balance >= 0),
    2727    invested_balance  numeric(18,4)   NOT NULL DEFAULT 0 CHECK (invested_balance  >= 0),
     28    -- P7: cash committed to the user's active buy orders, moved out of
     29    -- available_balance when the order is placed and consumed as it fills.
     30    reserved_balance  numeric(18,4)   NOT NULL DEFAULT 0 CHECK (reserved_balance  >= 0),
    2831    created_at        timestamptz     NOT NULL DEFAULT now(),
    2932    updated_at        timestamptz
    … …  
    8689    side        varchar(4)     NOT NULL CHECK (side   IN ('buy', 'sell')),
    8790    type        varchar(20)    NOT NULL CHECK (type   IN ('market', 'limit')),
    88     status      varchar(20)    NOT NULL CHECK (status IN ('open', 'executed', 'cancelled')),
     91    status      varchar(20)    NOT NULL CHECK (status IN ('open', 'partially_filled', 'executed', 'cancelled')),
    8992    quantity    numeric(20,4)  NOT NULL CHECK (quantity > 0),
     93    -- P7: how much of the order has been traded so far; remaining is
     94    -- quantity - filled_quantity. Maintained from market_trades.
     95    filled_quantity numeric(20,4) NOT NULL DEFAULT 0
     96                               CHECK (filled_quantity >= 0 AND filled_quantity <= quantity),
    9097    price       numeric(18,6),
    9198    placed_at   timestamptz    NOT NULL DEFAULT now(),
    … …  
    125132    quantity    numeric(20,6)  NOT NULL CHECK (quantity > 0),
    126133    side        varchar(4)     CHECK (side IN ('buy', 'sell')),
    127     source      varchar(50)    NOT NULL DEFAULT 'simulation'
     134    source      varchar(50)    NOT NULL DEFAULT 'simulation',
     135    -- P7: the orders this trade filled. NULL on a side means the counterparty
     136    -- was the simulated market (bot ticks have both NULL).
     137    buy_order_id  uuid         REFERENCES project.orders(id),
     138    sell_order_id uuid         REFERENCES project.orders(id)
    128139);
    129140
    130141CREATE INDEX idx_market_trades_market_time ON project.market_trades(market_id, executed_at DESC);
     142CREATE INDEX idx_market_trades_buy_order  ON project.market_trades(buy_order_id)  WHERE buy_order_id  IS NOT NULL;
     143CREATE INDEX idx_market_trades_sell_order ON project.market_trades(sell_order_id) WHERE sell_order_id IS NOT NULL;
    131144
    132145-- ============================================================================
Note: See TracChangeset for help on using the changeset viewer.