code.vegaprotocol.io/vega@v0.79.0/datanode/sqlstore/migrations/0008_iceberg_live_orders.sql (about)

     1  -- +goose Up
     2  -- +goose StatementBegin
     3  
     4  CREATE OR REPLACE FUNCTION archive_orders()
     5      RETURNS TRIGGER
     6      LANGUAGE PLPGSQL AS
     7  $$
     8  BEGIN
     9  
    10      DELETE from orders_live
    11      WHERE id = NEW.id;
    12  
    13      -- As per https://github.com/vegaprotocol/specs-internal/blob/master/protocol/0024-OSTA-order_status.md
    14  -- we consider an order 'live' if it either ACTIVE (status=1) or PARKED (status=8). Orders
    15  -- with statuses other than this are discarded by core, so we consider them candidates for
    16  -- eventual deletion according to the data retention policy by placing them in orders_history.
    17  -- As per https://github.com/vegaprotocol/vega/issues/8149, only LIMIT type (1) orders with status active (1) and parked (8)
    18  -- and time_in_force != IOC (3) and time_in_force != FOK (4) are considered live.
    19      IF NEW.status IN (1, 8) AND NEW.type = 1 AND NEW.time_in_force NOT IN (3, 4)
    20      THEN
    21          INSERT INTO orders_live
    22          VALUES(new.id, new.market_id, new.party_id, new.side, new.price,
    23                 new.size, new.remaining, new.time_in_force, new.type, new.status,
    24                 new.reference, new.reason, new.version, new.batch_id, new.pegged_offset,
    25                 new.pegged_reference, new.lp_id, new.created_at, new.updated_at, new.expires_at,
    26                 new.tx_hash, new.vega_time, new.seq_num, new.post_only, new.reduce_only, new.reserved_remaining, new.peak_size, new.minimum_visible_size);
    27      END IF;
    28  
    29      RETURN NEW;
    30  
    31  END;
    32  $$;
    33  -- +goose StatementEnd
    34  
    35  -- +goose Down
    36  
    37  -- +goose StatementBegin
    38  
    39  CREATE OR REPLACE FUNCTION archive_orders()
    40      RETURNS TRIGGER
    41      LANGUAGE PLPGSQL AS
    42  $$
    43  BEGIN
    44  
    45      DELETE from orders_live
    46      WHERE id = NEW.id;
    47  
    48      -- As per https://github.com/vegaprotocol/specs-internal/blob/master/protocol/0024-OSTA-order_status.md
    49  -- we consider an order 'live' if it either ACTIVE (status=1) or PARKED (status=8). Orders
    50  -- with statuses other than this are discarded by core, so we consider them candidates for
    51  -- eventual deletion according to the data retention policy by placing them in orders_history.
    52  -- As per https://github.com/vegaprotocol/vega/issues/8149, only LIMIT type (1) orders with status active (1) and parked (8)
    53  -- and time_in_force != IOC (3) and time_in_force != FOK (4) are considered live.
    54      IF NEW.status IN (1, 8) AND NEW.type = 1 AND NEW.time_in_force NOT IN (3, 4)
    55      THEN
    56          INSERT INTO orders_live
    57          VALUES(new.id, new.market_id, new.party_id, new.side, new.price,
    58                 new.size, new.remaining, new.time_in_force, new.type, new.status,
    59                 new.reference, new.reason, new.version, new.batch_id, new.pegged_offset,
    60                 new.pegged_reference, new.lp_id, new.created_at, new.updated_at, new.expires_at,
    61                 new.tx_hash, new.vega_time, new.seq_num, new.post_only, new.reduce_only);
    62      END IF;
    63  
    64      RETURN NEW;
    65  
    66  END;
    67  $$;
    68  -- +goose StatementEnd