code.vegaprotocol.io/vega@v0.79.0/core/integration/features/orders/amend-trade-panic.feature (about)

     1  Feature: Amending orders with isolated margins should never panic
     2    Background:
     3      Given the average block duration is "1"
     4      And the following network parameters are set:
     5        | name                                    | value |
     6        | network.markPriceUpdateMaximumFrequency | 0s    |
     7        | limits.markets.maxPeggedOrders          | 6     |
     8        | market.auction.minimumDuration          | 1     |
     9      And the price monitoring named "my-price-monitoring-1":
    10        | horizon | probability | auction extension |
    11        | 5       | 0.99        | 6                 |
    12  
    13      And the liquidity monitoring parameters:
    14        | name       | triggering ratio | time window | scaling factor |
    15        | lqm-params | 0.00             | 24h         | 1e-9           |
    16      And the simple risk model named "simple-risk-model":
    17        | long | short | max move up | min move down | probability of trading |
    18        | 0.1  | 0.2   | 100         | -100          | 0.2                    |
    19      And the markets:
    20        | id        | quote name | asset | liquidity monitoring | risk model        | margin calculator         | auction duration | fees         | price monitoring      | data source config     | linear slippage factor | quadratic slippage factor | position decimal places | sla params      |
    21        | ETH/FEB23 | ETH        | USD   | lqm-params           | simple-risk-model | default-margin-calculator | 1                | default-none | my-price-monitoring-1 | default-eth-for-future | 0.1                    | 0                         | 2                       | default-futures |
    22  
    23    @AmendEdge
    24    Scenario: Edge-case 1: Amending an order will cause it to trade in full, but leaves the party with insufficient margin to maintain its position. The old order should be restored, without any trades beign made
    25      Given the parties deposit on asset's general account the following amount:
    26        | party   | asset | amount       |
    27        | trader1 | USD   | 100000000000 |
    28        | trader2 | USD   | 100000000000 |
    29        | trader3 | USD   | 100000000000 |
    30        | trader4 | USD   | 100000000000 |
    31        | trader5 | USD   | 100000000000 |
    32        | lprov1  | USD   | 100000000000 |
    33  
    34      And the parties submit the following liquidity provision:
    35        | id  | party  | market id | commitment amount | fee | lp type    |
    36        | lp1 | lprov1 | ETH/FEB23 | 1000              | 0.1 | submission |
    37  
    38      And the parties place the following orders with ticks:
    39        | party   | market id | side | volume | price  | resulting trades | type       | tif     | reference |
    40        | trader1 | ETH/FEB23 | buy  | 1000   | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    41        | trader1 | ETH/FEB23 | buy  | 300    | 15600  | 0                | TYPE_LIMIT | TIF_GTC |           |
    42        | lprov1  | ETH/FEB23 | buy  | 100    | 15700  | 0                | TYPE_LIMIT | TIF_GTC | lp-buy-1  |
    43        | trader3 | ETH/FEB23 | buy  | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
    44        | lprov1  | ETH/FEB23 | sell | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC | lp-sell-1 |
    45        | trader2 | ETH/FEB23 | sell | 600    | 15802  | 0                | TYPE_LIMIT | TIF_GTC | t2-sell-1 |
    46        | trader2 | ETH/FEB23 | sell | 300    | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
    47        | trader2 | ETH/FEB23 | sell | 1000   | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
    48  
    49      When the network moves ahead "2" blocks
    50      Then the market data for the market "ETH/FEB23" should be:
    51        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
    52        | 15800      | TRADING_MODE_CONTINUOUS | 5       | 15701     | 15899     | 0            | 1000           | 300           |
    53  
    54      When the parties place the following pegged orders:
    55        | party  | market id | side | volume | pegged reference | offset | reference |
    56        | lprov1 | ETH/FEB23 | buy  | 100    | BID              | 10     | buy_peg_1 |
    57        | lprov1 | ETH/FEB23 | buy  | 200    | BID              | 20     | buy_peg_2 |
    58  
    59      Then the parties should have the following margin levels:
    60        | party   | market id | maintenance | margin mode  | margin factor | order |
    61        | lprov1  | ETH/FEB23 | 14220       | cross margin | 0             | 0     |
    62        | trader1 | ETH/FEB23 | 20540       | cross margin | 0             | 0     |
    63        | trader3 | ETH/FEB23 | 9480        | cross margin | 0             | 0     |
    64      And the parties should have the following account balances:
    65        | party   | asset | market id | margin | general     | bond |
    66        | lprov1  | USD   | ETH/FEB23 | 17064  | 99999981936 | 1000 |
    67        | trader1 | USD   | ETH/FEB23 | 23496  | 99999976504 |      |
    68        | trader3 | USD   | ETH/FEB23 | 11376  | 99999988624 |      |
    69  
    70      When the parties place the following orders with ticks:
    71        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference   |
    72        | trader3 | ETH/FEB23 | buy  | 100    | 15500 | 0                | TYPE_LIMIT | TIF_GTC | t3-to-amend |
    73      Then the parties should have the following margin levels:
    74        | party   | market id | maintenance | margin mode  | margin factor | order |
    75        | trader3 | ETH/FEB23 | 11060       | cross margin | 0             | 0     |
    76      And the parties should have the following account balances:
    77        | party   | asset | market id | margin | general     |
    78        | trader3 | USD   | ETH/FEB23 | 13272  | 99999986728 |
    79  
    80      When the parties submit update margin mode:
    81        | party   | market    | margin_mode     | margin_factor | error |
    82        | trader3 | ETH/FEB23 | isolated margin | 0.31          |       |
    83      Then the parties should have the following margin levels:
    84        | party   | market id | maintenance | margin mode     | margin factor | order |
    85        | trader3 | ETH/FEB23 | 9480        | isolated margin | 0.31          | 4805  |
    86      And the parties should have the following account balances:
    87        | party   | asset | market id | margin | general     |
    88        | trader3 | USD   | ETH/FEB23 | 14694  | 99999980501 |
    89  
    90      When the parties withdraw the following assets:
    91        | party   | asset | amount      | error |
    92        | trader3 | USD   | 99999980501 |       |
    93      Then the parties should have the following margin levels:
    94        | party   | market id | maintenance | release | margin mode     | margin factor | order |
    95        | trader3 | ETH/FEB23 | 9480        | 0       | isolated margin | 0.31          | 4805  |
    96      And the parties should have the following account balances:
    97        | party   | asset | market id | margin | general | order margin |
    98        | trader3 | USD   | ETH/FEB23 | 14694  | 0       | 4805         |
    99  
   100      When the parties amend the following orders:
   101        | party   | reference   | price | size delta | tif     | error               |
   102        | trader3 | t3-to-amend | 15805 | 400        | TIF_GTC | margin check failed |
   103      Then the parties should have the following margin levels:
   104        | party   | market id | maintenance | margin mode     | margin factor | order |
   105        | trader3 | ETH/FEB23 | 9480        | isolated margin | 0.31          | 0     |
   106      And the parties should have the following account balances:
   107        | party   | asset | market id | margin | general |
   108        | trader3 | USD   | ETH/FEB23 | 14694  | 4805    |
   109  
   110  And debug detailed orderbook volumes for market "ETH/FEB23"
   111  When the parties place the following orders with ticks:
   112    | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
   113    | trader5 | ETH/FEB23 | buy  | 90     | 15802 | 1                | TYPE_LIMIT | TIF_GTC |           |
   114  Then the following trades should be executed:
   115    | buyer   | seller  | price | size |
   116    | trader5 | trader2 | 15802 | 90   |
   117  # And debug detailed orderbook volumes for market "ETH/FEB23"