code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-200.feature (about)

     1  Feature: Amending order does not result in trades, margin is not covered, orders are cancelled
     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.000125               | 0                         | 2                       | default-futures |
    22  
    23    @MCAL200
    24    Scenario: amending party has a position, and is increasing its potential position
    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        | lprov1  | USD   | 100000000000 |
    32  
    33      And the parties submit the following liquidity provision:
    34        | id  | party  | market id | commitment amount | fee | lp type    |
    35        | lp1 | lprov1 | ETH/FEB23 | 1000              | 0.1 | submission |
    36  
    37      And the parties place the following orders with ticks:
    38        | party   | market id | side | volume | price  | resulting trades | type       | tif     | reference |
    39        | trader1 | ETH/FEB23 | buy  | 1000   | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    40        | trader1 | ETH/FEB23 | buy  | 300    | 15600  | 0                | TYPE_LIMIT | TIF_GTC |           |
    41        | lprov1  | ETH/FEB23 | buy  | 100    | 15700  | 0                | TYPE_LIMIT | TIF_GTC | lp-buy-1  |
    42        | trader3 | ETH/FEB23 | buy  | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
    43        | lprov1  | ETH/FEB23 | sell | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC | lp-sell-1 |
    44        | trader2 | ETH/FEB23 | sell | 600    | 15802  | 0                | TYPE_LIMIT | TIF_GTC | t2-sell-1 |
    45        | trader2 | ETH/FEB23 | sell | 300    | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
    46        | trader2 | ETH/FEB23 | sell | 1000   | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
    47  
    48      When the network moves ahead "2" blocks
    49      Then the market data for the market "ETH/FEB23" should be:
    50        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
    51        | 15800      | TRADING_MODE_CONTINUOUS | 5       | 15701     | 15899     | 0            | 1000           | 300           |
    52  
    53      When the parties place the following pegged orders:
    54        | party  | market id | side | volume | pegged reference | offset | reference |
    55        | lprov1 | ETH/FEB23 | buy  | 100    | BID              | 10     | buy_peg_1 |
    56        | lprov1 | ETH/FEB23 | buy  | 200    | BID              | 20     | buy_peg_2 |
    57  
    58      Then the parties should have the following margin levels:
    59        | party   | market id | maintenance | margin mode  | margin factor | order |
    60        | lprov1  | ETH/FEB23 | 9486        | cross margin | 0             | 0     |
    61        | trader1 | ETH/FEB23 | 20540       | cross margin | 0             | 0     |
    62        | trader3 | ETH/FEB23 | 4746        | cross margin | 0             | 0     |
    63  
    64      When the parties place the following orders with ticks:
    65        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference   |
    66        | trader3 | ETH/FEB23 | buy  | 100    | 15500 | 0                | TYPE_LIMIT | TIF_GTC | t3-to-amend |
    67      Then the parties should have the following margin levels:
    68        | party   | market id | maintenance | margin mode  | margin factor | order |
    69        | trader3 | ETH/FEB23 | 6326        | cross margin | 0             | 0     |
    70  
    71      When the parties submit update margin mode:
    72        | party   | market    | margin_mode     | margin_factor | error |
    73        | trader3 | ETH/FEB23 | isolated margin | 0.3           |       |
    74      Then the parties should have the following margin levels:
    75        | party   | market id | maintenance | search | release | margin mode     | margin factor | order |
    76        | trader3 | ETH/FEB23 | 4746        | 0      | 0       | isolated margin | 0.3           | 4650  |
    77  
    78      When the parties withdraw the following assets:
    79        | party   | asset | amount      | error |
    80        | trader3 | USD   | 99999981130 |       |
    81      Then the parties should have the following margin levels:
    82        | party   | market id | maintenance | search | release | margin mode     | margin factor | order |
    83        | trader3 | ETH/FEB23 | 4746        | 0      | 0       | isolated margin | 0.3           | 4650  |
    84      And the parties should have the following account balances:
    85        | party   | asset | market id | margin | general | order margin |
    86        | trader3 | USD   | ETH/FEB23 | 14220  | 0       | 4650         |
    87  
    88      # amend the order to increase the required margin, but ensure the order does not trade
    89      When the parties amend the following orders:
    90        | party   | reference   | price | size delta | tif     | error               |
    91        | trader3 | t3-to-amend | 15801 | 400        | TIF_GTC | margin check failed |
    92      Then the orders should have the following status:
    93        | party   | reference   | status         |
    94        | trader3 | t3-to-amend | STATUS_STOPPED |
    95      And the parties should have the following margin levels:
    96        | party   | market id | maintenance | search | release | margin mode     | margin factor | order |
    97        | trader3 | ETH/FEB23 | 4746        | 0      | 0       | isolated margin | 0.3           | 0     |
    98      And the parties should have the following account balances:
    99        | party   | asset | market id | margin | general |
   100        | trader3 | USD   | ETH/FEB23 | 14220  | 4650    |
   101  
   102  
   103    @MCAL200
   104    Scenario: amending party does not hold a position, and is increasing its potential position
   105      Given the parties deposit on asset's general account the following amount:
   106        | party   | asset | amount       |
   107        | trader1 | USD   | 100000000000 |
   108        | trader2 | USD   | 100000000000 |
   109        | trader3 | USD   | 100000000000 |
   110        | trader4 | USD   | 100000000000 |
   111        | lprov1  | USD   | 100000000000 |
   112  
   113      And the parties submit the following liquidity provision:
   114        | id  | party  | market id | commitment amount | fee | lp type    |
   115        | lp1 | lprov1 | ETH/FEB23 | 1000              | 0.1 | submission |
   116  
   117      And the parties place the following orders with ticks:
   118        | party   | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   119        | trader1 | ETH/FEB23 | buy  | 1000   | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   120        | trader1 | ETH/FEB23 | buy  | 300    | 15600  | 0                | TYPE_LIMIT | TIF_GTC |           |
   121        | lprov1  | ETH/FEB23 | buy  | 100    | 15700  | 0                | TYPE_LIMIT | TIF_GTC | lp-buy-1  |
   122        | trader3 | ETH/FEB23 | buy  | 300    | 15795  | 0                | TYPE_LIMIT | TIF_GTC | t3-base-1 |
   123        | trader4 | ETH/FEB23 | buy  | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
   124        | lprov1  | ETH/FEB23 | sell | 300    | 15800  | 0                | TYPE_LIMIT | TIF_GTC | lp-sell-1 |
   125        | trader2 | ETH/FEB23 | sell | 600    | 15802  | 0                | TYPE_LIMIT | TIF_GTC | t2-sell-1 |
   126        | trader2 | ETH/FEB23 | sell | 300    | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
   127        | trader2 | ETH/FEB23 | sell | 1000   | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
   128  
   129      When the network moves ahead "2" blocks
   130      Then the market data for the market "ETH/FEB23" should be:
   131        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   132        | 15800      | TRADING_MODE_CONTINUOUS | 5       | 15701     | 15899     | 0            | 1000           | 300           |
   133  
   134      When the parties place the following pegged orders:
   135        | party  | market id | side | volume | pegged reference | offset | reference |
   136        | lprov1 | ETH/FEB23 | buy  | 100    | BID              | 10     | buy_peg_1 |
   137        | lprov1 | ETH/FEB23 | buy  | 200    | BID              | 20     | buy_peg_2 |
   138  
   139      Then the parties should have the following margin levels:
   140        | party   | market id | maintenance | margin mode  | margin factor | order |
   141        | lprov1  | ETH/FEB23 | 9486        | cross margin | 0             | 0     |
   142        | trader1 | ETH/FEB23 | 20540       | cross margin | 0             | 0     |
   143        | trader3 | ETH/FEB23 | 4740        | cross margin | 0             | 0     |
   144        | trader4 | ETH/FEB23 | 4746        | cross margin | 0             | 0     |
   145      And the parties should have the following account balances:
   146        | party   | asset | market id | margin | general     | bond |
   147        | lprov1  | USD   | ETH/FEB23 | 11383  | 99999987617 | 1000 |
   148        | trader1 | USD   | ETH/FEB23 | 23496  | 99999976504 |      |
   149        | trader3 | USD   | ETH/FEB23 | 5686   | 99999994314 |      |
   150        | trader4 | USD   | ETH/FEB23 | 5688   | 99999994312 |      |
   151  
   152      When the parties place the following orders with ticks:
   153        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference   |
   154        | trader3 | ETH/FEB23 | buy  | 100    | 15500 | 0                | TYPE_LIMIT | TIF_GTC | t3-to-amend |
   155      Then the parties should have the following margin levels:
   156        | party   | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   157        | trader3 | ETH/FEB23 | 6320        | 6952   | 7584    | 8848    | cross margin | 0             | 0     |
   158      And the parties should have the following account balances:
   159        | party   | asset | market id | margin | general     |
   160        | trader3 | USD   | ETH/FEB23 | 7584   | 99999992416 |
   161  
   162      When the parties submit update margin mode:
   163        | party   | market    | margin_mode     | margin_factor | error |
   164        | trader3 | ETH/FEB23 | isolated margin | 0.3           |       |
   165      Then the parties should have the following margin levels:
   166        | party   | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   167        | trader3 | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.3           | 18865 |
   168      And the parties should have the following account balances:
   169        | party   | asset | market id | margin | general     | order margin |
   170        | trader3 | USD   | ETH/FEB23 | 0      | 99999981135 | 18865        |
   171  
   172      When the parties withdraw the following assets:
   173        | party   | asset | amount      | error |
   174        | trader3 | USD   | 99999981135 |       |
   175      Then the parties should have the following margin levels:
   176        | party   | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   177        | trader3 | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.3           | 18865 |
   178      And the parties should have the following account balances:
   179        | party   | asset | market id | margin | general | order margin |
   180        | trader3 | USD   | ETH/FEB23 | 0      | 0       | 18865        |
   181  
   182      # amend the order to increase the required margin, but ensure the order does not trade
   183      When the parties amend the following orders:
   184        | party   | reference   | price | size delta | tif     | error               |
   185        | trader3 | t3-to-amend | 15801 | 400        | TIF_GTC | margin check failed |
   186      Then the orders should have the following status:
   187        | party   | reference   | status         |
   188        | trader3 | t3-to-amend | STATUS_STOPPED |
   189        | trader3 | t3-base-1   | STATUS_STOPPED |
   190      And the parties should have the following margin levels:
   191        | party   | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   192        | trader3 | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.3           | 0     |
   193      And the parties should have the following account balances:
   194        | party   | asset | market id | margin | general |
   195        | trader3 | USD   | ETH/FEB23 | 0      | 18865   |
   196