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

     1  Feature: Test magin under isolated margin mode when there is not enough collateral
     2    Background:
     3      # Set liquidity parameters to allow "zero" target-stake which is needed to construct the order-book defined in the ACs
     4      Given the following network parameters are set:
     5        | name                                    | value |
     6        | network.markPriceUpdateMaximumFrequency | 0s    |
     7      And the liquidity monitoring parameters:
     8        | name       | triggering ratio | time window | scaling factor |
     9        | lqm-params | 0.00             | 24h         | 1e-9           |
    10      And the simple risk model named "simple-risk-model":
    11        | long | short | max move up | min move down | probability of trading |
    12        | 0.1  | 0.1   | 100         | -100          | 0.2                    |
    13      And the markets:
    14        | id        | quote name | asset | liquidity monitoring | risk model        | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    15        | ETH/FEB23 | ETH        | USD   | lqm-params           | simple-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
    16  
    17    Scenario: 001 Check margin update when party does not have sufficient collateral
    18      Given the parties deposit on asset's general account the following amount:
    19        | party            | asset | amount       |
    20        | buySideProvider  | USD   | 100000000000 |
    21        | sellSideProvider | USD   | 100000000000 |
    22        | party            | USD   | 48050        |
    23        | party1           | USD   | 48050        |
    24      And the parties place the following orders:
    25        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference   |
    26        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    27        | buySideProvider  | ETH/FEB23 | buy  | 1      | 15000  | 0                | TYPE_LIMIT | TIF_GTC |             |
    28        | buySideProvider  | ETH/FEB23 | buy  | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    29        | party            | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    30        | party            | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC | party-sell  |
    31        | party1           | ETH/FEB23 | sell | 3      | 16100  | 0                | TYPE_LIMIT | TIF_GTC | party1-sell |
    32        | sellSideProvider | ETH/FEB23 | sell | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC |             |
    33        | sellSideProvider | ETH/FEB23 | sell | 10     | 100100 | 0                | TYPE_LIMIT | TIF_GTC |             |
    34  
    35      And the markets are updated:
    36        | id        | linear slippage factor |
    37        | ETH/FEB23 | 0                      |
    38      # Checks for 0019-MCAL-031
    39      When the network moves ahead "2" blocks
    40      # Check mark-price matches the specification
    41      Then the mark price should be "15900" for the market "ETH/FEB23"
    42      # Check order book matches the specification
    43      And the order book should have the following volumes for market "ETH/FEB23":
    44        | side | price  | volume |
    45        | buy  | 14900  | 10     |
    46        | buy  | 15000  | 1      |
    47        | sell | 100000 | 1      |
    48        | sell | 100100 | 10     |
    49      # Check party margin levels match the specification
    50      And the average fill price is:
    51        | market    | volume | side | ref price | mark price | equivalent linear slippage factor |
    52        | ETH/FEB23 | 3      | sell | 15900     | 15900      | 0                                 |
    53  
    54      And the parties should have the following margin levels:
    55        | party | market id | maintenance |
    56        | party | ETH/FEB23 | 9540        |
    57  
    58      Then the parties should have the following account balances:
    59        | party | asset | market id | margin | general |
    60        | party | USD   | ETH/FEB23 | 11448  | 36602   |
    61  
    62      #AC: 0019-MCAL-032, switch to isolated margin is rejected becuase selected margin factor is too small
    63      And the parties submit update margin mode:
    64        | party | market    | margin_mode     | margin_factor | error                                                        |
    65        | party | ETH/FEB23 | isolated margin | 0.11          | required position margin must be greater than initial margin |
    66  
    67      And the parties should have the following margin levels:
    68        | party | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
    69        | party | ETH/FEB23 | 9540        | 10494  | 11448   | 13356   | cross margin | 0             | 0     |
    70  
    71      Then the parties should have the following account balances:
    72        | party | asset | market id | margin | general |
    73        | party | USD   | ETH/FEB23 | 11448  | 36602   |
    74  
    75      And the network moves ahead "1" blocks
    76  
    77      #AC: 0019-MCAL-066, 0019-MCAL-037 switch to isolated margin is rejected when party got insufficent balance
    78      And the parties submit update margin mode:
    79        | party | market    | margin_mode     | margin_factor | error                                                                      |
    80        | party | ETH/FEB23 | isolated margin | 0.9           | insufficient balance in general account to cover for required order margin |
    81      And the network moves ahead "2" blocks
    82  
    83      And the parties should have the following margin levels:
    84        | party | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
    85        | party | ETH/FEB23 | 9540        | 10494  | 11448   | 13356   | cross margin | 0             | 0     |
    86  
    87      #AC: 0019-MCAL-066 switch to isolated margin is accepted when party has sufficent balance
    88      And the parties submit update margin mode:
    89        | party  | market    | margin_mode     | margin_factor |
    90        | party  | ETH/FEB23 | isolated margin | 0.5           |
    91        | party1 | ETH/FEB23 | isolated margin | 0.3           |
    92      And the network moves ahead "2" blocks
    93  
    94      And the parties should have the following margin levels:
    95        | party | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    96        | party | ETH/FEB23 | 4770        | 0      | 5724    | 0       | isolated margin | 0.5           | 23850 |
    97  
    98      Then the parties should have the following account balances:
    99        | party | asset | market id | margin | general | order margin |
   100        | party | USD   | ETH/FEB23 | 23850  | 350     | 23850        |
   101  
   102      #AC 0019-MCAL-035 order will be rejected if the party does not have enough asset in the general account
   103      And the parties place the following orders:
   104        | party | market id | side | volume | price | resulting trades | type       | tif     | reference    | error               |
   105        | party | ETH/FEB23 | sell | 10     | 15910 | 0                | TYPE_LIMIT | TIF_GTC | sell-order-1 | margin check failed |
   106  
   107      #trigger MTM with party has both short position and short orders
   108      And the parties place the following orders:
   109        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   110        | buySideProvider  | ETH/FEB23 | buy  | 1      | 15890 | 0                | TYPE_LIMIT | TIF_GTC |
   111        | sellSideProvider | ETH/FEB23 | sell | 1      | 15890 | 1                | TYPE_LIMIT | TIF_GTC |
   112  
   113      And the network moves ahead "1" blocks
   114  
   115      Then the parties should have the following account balances:
   116        | party | asset | market id | margin | general | order margin |
   117        | party | USD   | ETH/FEB23 | 23880  | 350     | 23850        |
   118  
   119      #trigger more MTM with party has both short position and short orders
   120      #AC 0019-MCAL-067:When the mark price moves, the margin account should be updated while order margin account should not
   121      And the parties place the following orders:
   122        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   123        | buySideProvider  | ETH/FEB23 | buy  | 1      | 15850 | 0                | TYPE_LIMIT | TIF_GTC |
   124        | sellSideProvider | ETH/FEB23 | sell | 1      | 15850 | 1                | TYPE_LIMIT | TIF_GTC |
   125  
   126      And the network moves ahead "1" blocks
   127      Then the parties should have the following account balances:
   128        | party | asset | market id | margin | general | order margin |
   129        | party | USD   | ETH/FEB23 | 24000  | 350     | 23850        |
   130  
   131      #AC 0019-MCAL-068 amend the order so that new side margin + margin account balance < maintenance margin, the remainding should be stopped
   132      When the parties amend the following orders:
   133        | party | reference  | price | size delta | tif     | error               |
   134        | party | party-sell | 19000 | 0          | TIF_GTC | margin check failed |
   135      # If the new side margin + margin account balance < maintenance margin =>
   136      # As the evaluation is the result of any other position/order update, all open orders are stopped and margin re-evaluated.
   137  
   138      And the orders should have the following status:
   139        | party | reference  | status         |
   140        | party | party-sell | STATUS_STOPPED |
   141      And the network moves ahead "1" blocks
   142  
   143      And the parties should have the following margin levels:
   144        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   145        | party1 | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.3           | 14490 |
   146  
   147      #AC 0019-MCAL-069 when order is partially filled, the order margin should be udpated
   148      And the parties place the following orders:
   149        | party           | market id | side | volume | price | resulting trades | type       | tif     |
   150        | buySideProvider | ETH/FEB23 | buy  | 1      | 16100 | 1                | TYPE_LIMIT | TIF_GTC |
   151  
   152      And the parties should have the following margin levels:
   153        | party  | market id | maintenance | margin mode     | margin factor | order |
   154        | party1 | ETH/FEB23 | 1585        | isolated margin | 0.3           | 9660  |
   155  
   156    @MCAL037
   157    Scenario: 002 replicate panic in testnet: when party has an long order and they increase the price, (the order would be filled and then party does not have enough to cover the margin), the order should be stopped
   158      #and for party1, part of the orders are filled immediately, and the rest should fail
   159      Given the parties deposit on asset's general account the following amount:
   160        | party            | asset | amount       |
   161        | buySideProvider  | USD   | 100000000000 |
   162        | sellSideProvider | USD   | 100000000000 |
   163        | party            | USD   | 5400         |
   164        | party1           | USD   | 54000        |
   165        | party2           | USD   | 100000000000 |
   166        | party3           | USD   | 100000000000 |
   167  
   168      And the parties place the following orders:
   169        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference  |
   170        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   171        | party            | ETH/FEB23 | buy  | 1      | 15000  | 0                | TYPE_LIMIT | TIF_GTC | party-buy  |
   172        | party1           | ETH/FEB23 | buy  | 10     | 15000  | 0                | TYPE_LIMIT | TIF_GTC | party1-buy |
   173        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15400  | 0                | TYPE_LIMIT | TIF_GTC |            |
   174        | buySideProvider  | ETH/FEB23 | buy  | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   175        | sellSideProvider | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   176        | sellSideProvider | ETH/FEB23 | sell | 3      | 16900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   177        | sellSideProvider | ETH/FEB23 | sell | 3      | 17000  | 0                | TYPE_LIMIT | TIF_GTC |            |
   178        | sellSideProvider | ETH/FEB23 | sell | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC |            |
   179        | sellSideProvider | ETH/FEB23 | sell | 10     | 100100 | 0                | TYPE_LIMIT | TIF_GTC |            |
   180  
   181      When the network moves ahead "2" blocks
   182      # Check mark-price matches the specification
   183      Then the mark price should be "15900" for the market "ETH/FEB23"
   184      # Check order book matches the specification
   185  
   186      # Check party margin levels match the specification
   187      And the parties should have the following margin levels:
   188        | party | market id | maintenance | search | initial | release |
   189        | party | ETH/FEB23 | 1590        | 1749   | 1908    | 2226    |
   190  
   191      Then the parties should have the following account balances:
   192        | party  | asset | market id | margin | general |
   193        | party  | USD   | ETH/FEB23 | 1800   | 3600    |
   194        | party1 | USD   | ETH/FEB23 | 18000  | 36000   |
   195  
   196      And the parties submit update margin mode:
   197        | party  | market    | margin_mode     | margin_factor | error |
   198        | party  | ETH/FEB23 | isolated margin | 0.36          |       |
   199        | party1 | ETH/FEB23 | isolated margin | 0.36          |       |
   200  
   201      And the parties should have the following margin levels:
   202        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   203        | party  | ETH/FEB23 | 0           | 0      | 0       |         | isolated margin | 0.36          | 5400  |
   204        | party1 | ETH/FEB23 | 0           | 0      | 0       |         | isolated margin | 0.36          | 54000 |
   205  
   206      Then the parties should have the following account balances:
   207        | party  | asset | market id | margin | general | order margin |
   208        | party  | USD   | ETH/FEB23 | 0      | 0       | 5400         |
   209        | party1 | USD   | ETH/FEB23 | 0      | 0       | 54000        |
   210  
   211      And the network moves ahead "1" blocks
   212  
   213      And the average fill price is:
   214        | market    | volume | side | ref price | mark price | equivalent linear slippage factor |
   215        | ETH/FEB23 | 10     | buy  | 15900     | 15900      | 0                                 |
   216      And the markets are updated:
   217        | id        | linear slippage factor |
   218        | ETH/FEB23 | 0                      |
   219      When the parties amend the following orders:
   220        | party  | reference  | price | size delta | tif     | error               |
   221        | party  | party-buy  | 16900 | 0          | TIF_GTC | margin check failed |
   222        | party1 | party1-buy | 16900 | 0          | TIF_GTC | margin check failed |
   223  
   224      And the orders should have the following status:
   225        | party  | reference  | status         |
   226        | party  | party-buy  | STATUS_STOPPED |
   227        | party1 | party1-buy | STATUS_STOPPED |
   228  
   229      Then the network moves ahead "2" blocks
   230      And the parties should have the following margin levels:
   231        | party  | market id | maintenance | margin mode     | margin factor | order |
   232        | party  | ETH/FEB23 | 0           | isolated margin | 0.36          | 0     |
   233        | party1 | ETH/FEB23 | 5070        | isolated margin | 0.36          | 0     |
   234  
   235      Then the parties should have the following account balances:
   236        | party  | asset | market id | margin | general | order margin |
   237        | party  | USD   | ETH/FEB23 | 0      | 5400    | 0            |
   238        | party1 | USD   | ETH/FEB23 | 18252  | 35748   |              |
   239      When the parties submit update margin mode:
   240        | party  | market    | margin_mode  |
   241        | party1 | ETH/FEB23 | cross margin |
   242      Then the network moves ahead "2" blocks
   243      Then the parties should have the following account balances:
   244        | party  | asset | market id | margin | general | order margin |
   245        | party1 | USD   | ETH/FEB23 | 18252  | 35748   | 0            |
   246  
   247    Scenario: 003 test when party holds short orders
   248      #and for party1, part of the orders are filled immediately, and the rest should fail
   249      Given the parties deposit on asset's general account the following amount:
   250        | party            | asset | amount       |
   251        | buySideProvider  | USD   | 100000000000 |
   252        | sellSideProvider | USD   | 100000000000 |
   253        | party            | USD   | 60840        |
   254        | party1           | USD   | 360000       |
   255  
   256      And the parties place the following orders:
   257        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference   |
   258        | buySideProvider  | ETH/FEB23 | buy  | 20     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |             |
   259        | buySideProvider  | ETH/FEB23 | buy  | 3      | 14900  | 0                | TYPE_LIMIT | TIF_GTC |             |
   260        | buySideProvider  | ETH/FEB23 | buy  | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
   261        | sellSideProvider | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
   262        | party            | ETH/FEB23 | sell | 10     | 16900  | 0                | TYPE_LIMIT | TIF_GTC | party-sell  |
   263        | party1           | ETH/FEB23 | sell | 10     | 100000 | 0                | TYPE_LIMIT | TIF_GTC | party1-sell |
   264        | sellSideProvider | ETH/FEB23 | sell | 10     | 100100 | 0                | TYPE_LIMIT | TIF_GTC |             |
   265  
   266      When the network moves ahead "2" blocks
   267      # Check mark-price matches the specification
   268      Then the mark price should be "15900" for the market "ETH/FEB23"
   269  
   270      And the parties submit update margin mode:
   271        | party  | market    | margin_mode     | margin_factor | error |
   272        | party  | ETH/FEB23 | isolated margin | 0.36          |       |
   273        | party1 | ETH/FEB23 | isolated margin | 0.36          |       |
   274  
   275      And the parties should have the following margin levels:
   276        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order  |
   277        | party  | ETH/FEB23 | 0           | 0      | 0       |         | isolated margin | 0.36          | 60840  |
   278        | party1 | ETH/FEB23 | 0           | 0      | 0       |         | isolated margin | 0.36          | 360000 |
   279  
   280      Then the parties should have the following account balances:
   281        | party  | asset | market id | margin | general | order margin |
   282        | party  | USD   | ETH/FEB23 | 0      | 0       | 60840        |
   283        | party1 | USD   | ETH/FEB23 | 0      | 0       | 360000       |
   284      And the markets are updated:
   285        | id        | linear slippage factor |
   286        | ETH/FEB23 | 0.08                   |
   287      And the network moves ahead "1" blocks
   288  
   289      When the parties amend the following orders:
   290        | party | reference  | price | size delta | tif     | error |
   291        | party | party-sell | 14900 | 0          | TIF_GTC |       |
   292  
   293      And the markets are updated:
   294        | id        | linear slippage factor |
   295        | ETH/FEB23 | 1                      |
   296  
   297      And the parties amend the following orders:
   298        | party  | reference   | price | size delta | tif     | error               |
   299        | party1 | party1-sell | 14900 | 0          | TIF_GTC | margin check failed |
   300  
   301      And the orders should have the following status:
   302        | party  | reference   | status         |
   303        | party  | party-sell  | STATUS_FILLED  |
   304        | party1 | party1-sell | STATUS_STOPPED |
   305  
   306      And the parties should have the following margin levels:
   307        | party  | market id | maintenance | margin mode     | margin factor | order |
   308        | party  | ETH/FEB23 | 28620       | isolated margin | 0.36          | 0     |
   309        | party1 | ETH/FEB23 | 0           | isolated margin | 0.36          | 0     |
   310  
   311      Then the parties should have the following account balances:
   312        | party  | asset | market id | margin | general | order margin |
   313        | party  | USD   | ETH/FEB23 | 53640  | 7200    | 0            |
   314        | party1 | USD   | ETH/FEB23 | 0      | 360000  | 0            |