Ignore:
Timestamp:
09/24/26 17:43:19 (6 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/reports_demo_data.sql

    ra531b45 ref1c1c7  
    2828-- description/source) before re-inserting.
    2929
     30-- P7: users' cash (available + reserved) must equal their ledger at
     31-- COMMIT, so the balance moves by exactly what this script removes and
     32-- re-adds to the ledger, all in one transaction. The historical orders are
     33-- imported as completely filled.
     34
     35BEGIN;
     36
    3037SET search_path TO project, public;
     38
     39UPDATE users u
     40   SET available_balance = u.available_balance - d.total
     41  FROM (SELECT user_id, SUM(amount) AS total FROM transactions
     42         WHERE description = 'P6 demo data' GROUP BY user_id) d
     43 WHERE u.id = d.user_id;
    3144
    3245DELETE FROM transactions  WHERE description = 'P6 demo data';
    … …  
    98111-- Executed orders: who participated in which market, across the same quarters.
    99112-- ============================================================================
    100 INSERT INTO orders (id, user_id, market_id, side, type, status, quantity, price, placed_at, executed_at) VALUES
     113INSERT INTO orders (id, user_id, market_id, side, type, status, quantity, filled_quantity, price, placed_at, executed_at) VALUES
    101114    ('e1111111-1111-1111-1111-111111111111', 'b1111111-1111-1111-1111-111111111111',
    102      'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 0.5000, 40000.000000,
     115     'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 0.5000, 0.5000, 40000.000000,
    103116     '2025-07-15 10:00', '2025-07-15 10:00'),
    104117    ('e2222222-2222-2222-2222-222222222222', 'b1111111-1111-1111-1111-111111111111',
    105      'a2222222-2222-2222-2222-222222222222', 'sell', 'market', 'executed', 3.0000, 4000.000000,
     118     'a2222222-2222-2222-2222-222222222222', 'sell', 'market', 'executed', 3.0000, 3.0000, 4000.000000,
    106119     '2025-10-15 10:00', '2025-10-15 10:00'),
    107120    ('e3333333-3333-3333-3333-333333333333', 'b2222222-2222-2222-2222-222222222222',
    108      'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 1.2000, 55000.000000,
     121     'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 1.2000, 1.2000, 55000.000000,
    109122     '2026-01-15 10:00', '2026-01-15 10:00'),
    110123    ('e4444444-4444-4444-4444-444444444444', 'b2222222-2222-2222-2222-222222222222',
    111      'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 1.0000, 60000.000000,
     124     'a1111111-1111-1111-1111-111111111111', 'buy', 'market', 'executed', 1.0000, 1.0000, 60000.000000,
    112125     '2026-04-15 10:00', '2026-04-15 10:00'),
    113126    ('e5555555-5555-5555-5555-555555555555', 'b3333333-3333-3333-3333-333333333333',
    114      'a2222222-2222-2222-2222-222222222222', 'sell', 'market', 'executed', 2.0000, 3600.000000,
     127     'a2222222-2222-2222-2222-222222222222', 'sell', 'market', 'executed', 2.0000, 2.0000, 3600.000000,
    115128     '2026-01-15 10:00', '2026-01-15 10:00');
     129
     130UPDATE users u
     131   SET available_balance = u.available_balance + d.total
     132  FROM (SELECT user_id, SUM(amount) AS total FROM transactions
     133         WHERE description = 'P6 demo data' GROUP BY user_id) d
     134 WHERE u.id = d.user_id;
     135
     136COMMIT;
Note: See TracChangeset for help on using the changeset viewer.