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

     1  Feature: Test mark price changes and closeout under isolated margin mode
     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 closeout when party's open position is under maintenance level (0019-MCAL-070)
    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        | party1           | USD   | 172500       |
    23  
    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  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
    28        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    29        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    30        | party1           | ETH/FEB23 | sell | 8      | 15900  | 0                | TYPE_LIMIT | TIF_GTC | s-1       |
    31        | sellSideProvider | ETH/FEB23 | sell | 1      | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
    32        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
    33  
    34      When the network moves ahead "2" blocks
    35      Then the mark price should be "15900" for the market "ETH/FEB23"
    36      And the order book should have the following volumes for market "ETH/FEB23":
    37        | side | price  | volume |
    38        | buy  | 14900  | 10     |
    39        | buy  | 15800  | 6      |
    40        | sell | 15900  | 8      |
    41        | sell | 200000 | 1      |
    42        | sell | 200100 | 10     |
    43      And the parties should have the following margin levels:
    44        | party  | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
    45        | party1 | ETH/FEB23 | 68370       | 75207  | 82044   | 95718   | cross margin | 0             | 0     |
    46  
    47      Then the parties should have the following account balances:
    48        | party  | asset | market id | margin | general |
    49        | party1 | USD   | ETH/FEB23 | 82044  | 90456   |
    50  
    51      #switch to isolated margin
    52      And the parties submit update margin mode:
    53        | party  | market    | margin_mode     | margin_factor |
    54        | party1 | ETH/FEB23 | isolated margin | 0.6           |
    55  
    56      #maintenance margin level: 15900*10*(0.1+0.25)=55650
    57      And the parties should have the following margin levels:
    58        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    59        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.6           | 76320 |
    60  
    61      #order margin: 15900*8*0.6=76320
    62      #position margin: 15900*10*0.6=95400
    63      Then the parties should have the following account balances:
    64        | party  | asset | market id | margin | general | order margin |
    65        | party1 | USD   | ETH/FEB23 | 95400  | 780     | 76320        |
    66  
    67      #trigger more MTM with party has both short position and short orders
    68      And the parties place the following orders:
    69        | party            | market id | side | volume | price | resulting trades | type       | tif     |
    70        | buySideProvider  | ETH/FEB23 | buy  | 10     | 17000 | 1                | TYPE_LIMIT | TIF_GTC |
    71        | sellSideProvider | ETH/FEB23 | sell | 2      | 17000 | 1                | TYPE_LIMIT | TIF_GTC |
    72  
    73      And the orders should have the following status:
    74        | party  | reference | status        |
    75        | party1 | s-1       | STATUS_FILLED |
    76  
    77      And the market data for the market "ETH/FEB23" should be:
    78        | mark price | trading mode            |
    79        | 15900      | TRADING_MODE_CONTINUOUS |
    80      And the network moves ahead "1" blocks
    81  
    82      And the market data for the market "ETH/FEB23" should be:
    83        | mark price | trading mode            |
    84        | 17000      | TRADING_MODE_CONTINUOUS |
    85  
    86      #position margin: 15900*18*0.6=171720
    87      #MTM: 171720-(17000-15900)*18=151920
    88      Then the parties should have the following account balances:
    89        | party  | asset | market id | margin | general | order margin |
    90        | party1 | USD   | ETH/FEB23 | 151920 | 780     | 0            |
    91  
    92      #maintenance margin level: 17000*18*(0.1+0.25)=107100
    93      And the parties should have the following margin levels:
    94        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    95        | party1 | ETH/FEB23 | 107100      | 0      | 128520  | 0       | isolated margin | 0.6           | 0     |
    96  
    97      And the following transfers should happen:
    98        | from   | to              | from account            | to account              | market id | amount | asset |
    99        | party1 | market          | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 19800  | USD   |
   100        | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 19800  | USD   |
   101  
   102      #trigger more MTM with party has short position
   103      And the parties place the following orders:
   104        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   105        | buySideProvider  | ETH/FEB23 | buy  | 1      | 20000 | 0                | TYPE_LIMIT | TIF_GTC |
   106        | sellSideProvider | ETH/FEB23 | sell | 1      | 20000 | 1                | TYPE_LIMIT | TIF_GTC |
   107      And the market data for the market "ETH/FEB23" should be:
   108        | mark price | trading mode            |
   109        | 17000      | TRADING_MODE_CONTINUOUS |
   110      And the network moves ahead "1" blocks
   111      #maintenance margin level: 20000*18*(0.1+0.25)=126000
   112  
   113      Then the parties should have the following account balances:
   114        | party  | asset | market id | margin | general | order margin |
   115        | party1 | USD   | ETH/FEB23 | 0      | 780     | 0            |
   116  
   117      And the following transfers should happen:
   118        | from   | to     | from account        | to account              | market id | amount | asset |
   119        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 54000  | USD   |
   120        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 97920  | USD   |
   121  
   122    Scenario: 002 Open positions should be closed in the case of open positions dropping below maintenance margin level, active orders will be cancelled if closing positions lead order margin level to increase.
   123      Given the parties deposit on asset's general account the following amount:
   124        | party            | asset | amount       |
   125        | buySideProvider  | USD   | 100000000000 |
   126        | sellSideProvider | USD   | 100000000000 |
   127        | party1           | USD   | 215500       |
   128  
   129      And the parties place the following orders:
   130        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference  |
   131        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   132        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |            |
   133        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   134        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   135        | party1           | ETH/FEB23 | sell | 1      | 200000 | 0                | TYPE_LIMIT | TIF_GTC | party-sell |
   136        | sellSideProvider | ETH/FEB23 | sell | 10     | 200000 | 0                | TYPE_LIMIT | TIF_GTC |            |
   137        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |            |
   138  
   139      When the network moves ahead "2" blocks
   140      Then the mark price should be "15900" for the market "ETH/FEB23"
   141      And the order book should have the following volumes for market "ETH/FEB23":
   142        | side | price  | volume |
   143        | buy  | 14900  | 10     |
   144        | buy  | 15800  | 6      |
   145        | sell | 200000 | 11     |
   146        | sell | 200100 | 10     |
   147      And the parties should have the following margin levels:
   148        | party  | market id | maintenance | initial |
   149        | party1 | ETH/FEB23 | 57240       | 68688   |
   150      #slippage_per_unit: (19500+200000*9)/10-15900)=166050
   151      #margin: 10*min(166050, 15900*0.25)+0.1*15900*11=57240
   152  
   153      Then the parties should have the following account balances:
   154        | party  | asset | market id | margin | general |
   155        | party1 | USD   | ETH/FEB23 | 68688  | 146812  |
   156  
   157      #switch to isolated margin
   158      And the parties submit update margin mode:
   159        | party  | market    | margin_mode     | margin_factor |
   160        | party1 | ETH/FEB23 | isolated margin | 0.5           |
   161  
   162      And the parties should have the following margin levels:
   163        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order  |
   164        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.5           | 100000 |
   165  
   166      #margin level: 15900*10*0.5=79500
   167      Then the parties should have the following account balances:
   168        | party  | asset | market id | margin | general | order margin |
   169        | party1 | USD   | ETH/FEB23 | 79500  | 36000   | 100000       |
   170  
   171      #AC 0019-MCAL-132:increase margin factor in isolated margin with position and with orders successful in continuous mode
   172      And the parties submit update margin mode:
   173        | party  | market    | margin_mode     | margin_factor | error |
   174        | party1 | ETH/FEB23 | isolated margin | 0.50001       |       |
   175  
   176      And the parties should have the following margin levels:
   177        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order  |
   178        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.50001       | 100002 |
   179  
   180      Then the parties should have the following account balances:
   181        | party  | asset | market id | margin | general | order margin |
   182        | party1 | USD   | ETH/FEB23 | 79501  | 35997   | 100002       |
   183  
   184      #at this point you can't change to 0.4 as the initial margin = 66780 and the the position margin with 0.4 would be 63600
   185      And the parties submit update margin mode:
   186        | party  | market    | margin_mode     | margin_factor | error                                                        |
   187        | party1 | ETH/FEB23 | isolated margin | 0.4           | required position margin must be greater than initial margin |
   188  
   189      #the the position margin with 0.45 would be 71550 which is greater than initial margin, update of margin factor is accepted
   190      And the parties submit update margin mode:
   191        | party  | market    | margin_mode     | margin_factor | error |
   192        | party1 | ETH/FEB23 | isolated margin | 0.45          |       |
   193  
   194      And the parties should have the following margin levels:
   195        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   196        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.45          | 90000 |
   197  
   198      Then the parties should have the following account balances:
   199        | party  | asset | market id | margin | general | order margin |
   200        | party1 | USD   | ETH/FEB23 | 71550  | 53950   | 90000        |
   201  
   202      And the parties submit update margin mode:
   203        | party  | market    | margin_mode     | margin_factor | error |
   204        | party1 | ETH/FEB23 | isolated margin | 0.6           |       |
   205  
   206      And the parties should have the following margin levels:
   207        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order  |
   208        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.6           | 120000 |
   209  
   210      Then the parties should have the following account balances:
   211        | party  | asset | market id | margin | general | order margin |
   212        | party1 | USD   | ETH/FEB23 | 95400  | 100     | 120000       |
   213  
   214      #trigger MTM (18000-15900)*10= 21000 with party has both short position and short orders, when party is distressed, order will remain active
   215      And the parties place the following orders:
   216        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   217        | buySideProvider  | ETH/FEB23 | buy  | 1      | 18000 | 0                | TYPE_LIMIT | TIF_GTC |
   218        | sellSideProvider | ETH/FEB23 | sell | 1      | 18000 | 1                | TYPE_LIMIT | TIF_GTC |
   219  
   220      And the market data for the market "ETH/FEB23" should be:
   221        | mark price | trading mode            |
   222        | 15900      | TRADING_MODE_CONTINUOUS |
   223      And the network moves ahead "1" blocks
   224  
   225      #MTM for party1: 95400-21000=74400
   226      Then the parties should have the following account balances:
   227        | party  | asset | market id | margin | general | order margin |
   228        | party1 | USD   | ETH/FEB23 | 74400  | 100     | 120000       |
   229  
   230      #trigger MTM (25440-18000)*10= 74400 which will empty the position margin account
   231      And the parties place the following orders:
   232        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   233        | buySideProvider  | ETH/FEB23 | buy  | 1      | 25440 | 0                | TYPE_LIMIT | TIF_GTC |
   234        | sellSideProvider | ETH/FEB23 | sell | 1      | 25440 | 1                | TYPE_LIMIT | TIF_GTC |
   235  
   236      And the network moves ahead "1" blocks
   237      And the following transfers should happen:
   238        | from   | to     | from account              | to account              | market id | amount | asset |
   239        | party1 | market | ACCOUNT_TYPE_MARGIN       | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 74400  | USD   |
   240        | party1 | party1 | ACCOUNT_TYPE_ORDER_MARGIN | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 120000 | USD   |
   241  
   242      Then the parties should have the following account balances:
   243        | party  | asset | market id | margin | general | order margin |
   244        | party1 | USD   | ETH/FEB23 | 120000 | 100     | 0            |
   245  
   246      #MTM for party1: 10*(25540-25440)=1000
   247      And the parties place the following orders:
   248        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   249        | buySideProvider  | ETH/FEB23 | buy  | 1      | 25540 | 0                | TYPE_LIMIT | TIF_GTC |
   250        | sellSideProvider | ETH/FEB23 | sell | 1      | 25540 | 1                | TYPE_LIMIT | TIF_GTC |
   251  
   252      And the network moves ahead "2" blocks
   253  
   254      Then the parties should have the following profit and loss:
   255        | party  | volume | unrealised pnl | realised pnl |
   256        | party1 | -1     | 174460         | -269860      |
   257  
   258      And the market data for the market "ETH/FEB23" should be:
   259        | mark price | trading mode            |
   260        | 25540      | TRADING_MODE_CONTINUOUS |
   261  
   262      Then the parties should have the following account balances:
   263        | party  | asset | market id | margin | general | order margin |
   264        | party1 | USD   | ETH/FEB23 | 120000 | 100     | 0            |
   265  
   266    Scenario: 003 When a party (who holds open positions and bond account) gets distressed, open positions will be closed, the bond account will be emptied (0019-MCAL-072)
   267      Given the parties deposit on asset's general account the following amount:
   268        | party            | asset | amount       |
   269        | buySideProvider  | USD   | 100000000000 |
   270        | sellSideProvider | USD   | 100000000000 |
   271        | party1           | USD   | 172500       |
   272      When the parties submit the following liquidity provision:
   273        | id  | party  | market id | commitment amount | fee | lp type    |
   274        | lp1 | party1 | ETH/FEB23 | 1000              | 0.1 | submission |
   275  
   276      And the parties place the following orders:
   277        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   278        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   279        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
   280        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   281        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   282        | sellSideProvider | ETH/FEB23 | sell | 1      | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
   283        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
   284  
   285      When the network moves ahead "2" blocks
   286      And the market data for the market "ETH/FEB23" should be:
   287        | mark price | trading mode            |
   288        | 15900      | TRADING_MODE_CONTINUOUS |
   289  
   290      And the parties should have the following margin levels:
   291        | party  | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   292        | party1 | ETH/FEB23 | 55650       | 61215  | 66780   | 77910   | cross margin | 0             | 0     |
   293  
   294      Then the parties should have the following account balances:
   295        | party  | asset | market id | margin | general | bond |
   296        | party1 | USD   | ETH/FEB23 | 66780  | 104720  | 1000 |
   297  
   298      #switch to isolated margin
   299      And the parties submit update margin mode:
   300        | party  | market    | margin_mode     | margin_factor | error |
   301        | party1 | ETH/FEB23 | isolated margin | 0.5           |       |
   302  
   303      And the parties should have the following margin levels:
   304        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   305        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.5           | 0     |
   306  
   307      #order margin: 15900*8*0.6=76320
   308      #position margin: 15900*10*0.6=95400
   309      Then the parties should have the following account balances:
   310        | party  | asset | market id | margin | general | order margin | bond |
   311        | party1 | USD   | ETH/FEB23 | 79500  | 92000   | 0            | 1000 |
   312  
   313      #trigger more MTM (18285-15900)*10=23850 with party has both short position and bond account
   314      And the parties place the following orders:
   315        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   316        | buySideProvider  | ETH/FEB23 | buy  | 1      | 18285 | 0                | TYPE_LIMIT | TIF_GTC |
   317        | sellSideProvider | ETH/FEB23 | sell | 1      | 18285 | 1                | TYPE_LIMIT | TIF_GTC |
   318  
   319      When the network moves ahead "2" blocks
   320      And the market data for the market "ETH/FEB23" should be:
   321        | mark price | trading mode            |
   322        | 18285      | TRADING_MODE_CONTINUOUS |
   323  
   324      Then the parties should have the following account balances:
   325        | party  | asset | market id | margin | general | order margin | bond |
   326        | party1 | USD   | ETH/FEB23 | 0      | 92000   | 0            | 0    |
   327  
   328      And the following transfers should happen:
   329        | from   | to               | from account            | to account              | market id | amount | asset |
   330        | party1 | party1           | ACCOUNT_TYPE_BOND       | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 1000   | USD   |
   331        | party1 | market           | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 56650  | USD   |
   332        | market | market           | ACCOUNT_TYPE_INSURANCE  | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 56650  | USD   |
   333        | market | sellSideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 56650  | USD   |
   334  
   335    Scenario: 004 When a party (who holds open positions, orders and bond account) gets distressed, open positions will be closed, the bond account will be emptied (0019-MCAL-073)
   336      Given the parties deposit on asset's general account the following amount:
   337        | party            | asset | amount       |
   338        | buySideProvider  | USD   | 100000000000 |
   339        | sellSideProvider | USD   | 100000000000 |
   340        | party1           | USD   | 172500       |
   341      When the parties submit the following liquidity provision:
   342        | id  | party  | market id | commitment amount | fee | lp type    |
   343        | lp1 | party1 | ETH/FEB23 | 1000              | 0.1 | submission |
   344  
   345      And the parties place the following orders:
   346        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   347        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   348        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
   349        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   350        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   351        | sellSideProvider | ETH/FEB23 | sell | 10     | 28900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   352        | party1           | ETH/FEB23 | sell | 2      | 28910  | 0                | TYPE_LIMIT | TIF_GTC |           |
   353        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
   354  
   355      When the network moves ahead "2" blocks
   356      And the market data for the market "ETH/FEB23" should be:
   357        | mark price | trading mode            |
   358        | 15900      | TRADING_MODE_CONTINUOUS |
   359  
   360      And the parties should have the following margin levels:
   361        | party  | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   362        | party1 | ETH/FEB23 | 58830       | 64713  | 70596   | 82362   | cross margin | 0             | 0     |
   363  
   364      Then the parties should have the following account balances:
   365        | party  | asset | market id | margin | general | bond |
   366        | party1 | USD   | ETH/FEB23 | 70596  | 100904  | 1000 |
   367  
   368      #switch to isolated margin
   369      And the parties submit update margin mode:
   370        | party  | market    | margin_mode     | margin_factor | error |
   371        | party1 | ETH/FEB23 | isolated margin | 0.5           |       |
   372  
   373      And the parties should have the following margin levels:
   374        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   375        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.5           | 28910 |
   376      Then the parties should have the following account balances:
   377        | party  | asset | market id | margin | general | order margin | bond |
   378        | party1 | USD   | ETH/FEB23 | 79500  | 63090   | 28910        | 1000 |
   379  
   380      #trigger more MTM (18385-15900)*10=24850 with party has both short position and bond account
   381      And the parties place the following orders:
   382        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   383        | buySideProvider  | ETH/FEB23 | buy  | 1      | 18385 | 0                | TYPE_LIMIT | TIF_GTC |
   384        | sellSideProvider | ETH/FEB23 | sell | 1      | 18385 | 1                | TYPE_LIMIT | TIF_GTC |
   385  
   386      When the network moves ahead "2" blocks
   387      And the market data for the market "ETH/FEB23" should be:
   388        | mark price | trading mode            |
   389        | 18385      | TRADING_MODE_CONTINUOUS |
   390  
   391      Then the parties should have the following account balances:
   392        | party  | asset | market id | margin | general | order margin | bond |
   393        | party1 | USD   | ETH/FEB23 | 0      | 63090   | 28910        | 0    |
   394  
   395      And the following transfers should happen:
   396        | from   | to               | from account            | to account              | market id | amount | asset |
   397        | party1 | party1           | ACCOUNT_TYPE_BOND       | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 1000   | USD   |
   398        | party1 | market           | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 55650  | USD   |
   399        | market | market           | ACCOUNT_TYPE_INSURANCE  | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 55650  | USD   |
   400        | market | sellSideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 55650  | USD   |
   401  
   402    Scenario: 005 Open positions should be closed in the case of open positions dropping below maintenance margin level, active orders will be cancelled if closing positions lead order margin level to increase. (0019-MCAL-071)
   403      Given the parties deposit on asset's general account the following amount:
   404        | party            | asset | amount       |
   405        | buySideProvider  | USD   | 100000000000 |
   406        | sellSideProvider | USD   | 100000000000 |
   407        | party1           | USD   | 172500       |
   408  
   409      And the parties place the following orders:
   410        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   411        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   412        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   413        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   414        | sellSideProvider | ETH/FEB23 | sell | 10     | 28900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   415        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
   416  
   417      When the network moves ahead "2" blocks
   418      And the market data for the market "ETH/FEB23" should be:
   419        | mark price | trading mode            |
   420        | 15900      | TRADING_MODE_CONTINUOUS |
   421  
   422      And the parties should have the following margin levels:
   423        | party  | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   424        | party1 | ETH/FEB23 | 55650       | 61215  | 66780   | 77910   | cross margin | 0             | 0     |
   425  
   426      #switch to isolated margin
   427      And the parties submit update margin mode:
   428        | party  | market    | margin_mode     | margin_factor | error |
   429        | party1 | ETH/FEB23 | isolated margin | 0.5           |       |
   430  
   431      And the parties should have the following margin levels:
   432        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   433        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.5           | 0     |
   434      When the network moves ahead "1" blocks
   435  
   436      And the parties place the following orders:
   437        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   438        | party1 | ETH/FEB23 | buy  | 6      | 15800 | 0                | TYPE_LIMIT | TIF_GTC | b-1       |
   439  
   440      Then the parties should have the following account balances:
   441        | party  | asset | market id | margin | general | order margin |
   442        | party1 | USD   | ETH/FEB23 | 79500  | 93000   | 0            |
   443  
   444      #trigger more MTM (18385-15900)*10=24850 with party has both short position and bond account
   445      And the parties place the following orders:
   446        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   447        | buySideProvider  | ETH/FEB23 | buy  | 1      | 18385 | 0                | TYPE_LIMIT | TIF_GTC |
   448        | sellSideProvider | ETH/FEB23 | sell | 1      | 18385 | 1                | TYPE_LIMIT | TIF_GTC |
   449  
   450      When the network moves ahead "2" blocks
   451      And the market data for the market "ETH/FEB23" should be:
   452        | mark price | trading mode            |
   453        | 18385      | TRADING_MODE_CONTINUOUS |
   454      And the orders should have the following status:
   455        | party  | reference | status         |
   456        | party1 | b-1       | STATUS_STOPPED |
   457  
   458      Then the parties should have the following account balances:
   459        | party  | asset | market id | margin | general | order margin |
   460        | party1 | USD   | ETH/FEB23 | 0      | 93000   | 0            |
   461  
   462      And the following transfers should happen:
   463        | from   | to               | from account            | to account              | market id | amount | asset |
   464        | party1 | market           | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 54650  | USD   |
   465        | market | market           | ACCOUNT_TYPE_INSURANCE  | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 54650  | USD   |
   466        | market | sellSideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 54650  | USD   |
   467  
   468    Scenario: 006 When a party (who holds open positions, orders and bond account) gets distressed, open positions will be closed, the bond account will be emptied (0019-MCAL-074)
   469      Given the parties deposit on asset's general account the following amount:
   470        | party            | asset | amount       |
   471        | buySideProvider  | USD   | 100000000000 |
   472        | sellSideProvider | USD   | 100000000000 |
   473        | party1           | USD   | 172500       |
   474      When the parties submit the following liquidity provision:
   475        | id  | party  | market id | commitment amount | fee | lp type    |
   476        | lp1 | party1 | ETH/FEB23 | 1000              | 0.1 | submission |
   477  
   478      And the parties place the following orders:
   479        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference |
   480        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   481        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   482        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
   483        | sellSideProvider | ETH/FEB23 | sell | 10     | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
   484        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
   485  
   486      When the network moves ahead "2" blocks
   487      And the market data for the market "ETH/FEB23" should be:
   488        | mark price | trading mode            |
   489        | 15900      | TRADING_MODE_CONTINUOUS |
   490  
   491      #margin maintenance: min(10*(200000-15900),15900*10*0.25)+10*0.1*15900
   492      And the parties should have the following margin levels:
   493        | party  | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   494        | party1 | ETH/FEB23 | 55650       | 61215  | 66780   | 77910   | cross margin | 0             | 0     |
   495  
   496      Then the parties should have the following account balances:
   497        | party  | asset | market id | margin | general | bond |
   498        | party1 | USD   | ETH/FEB23 | 66780  | 104720  | 1000 |
   499  
   500      #switch to isolated margin
   501      And the parties submit update margin mode:
   502        | party  | market    | margin_mode     | margin_factor | error |
   503        | party1 | ETH/FEB23 | isolated margin | 0.5           |       |
   504  
   505      And the parties should have the following margin levels:
   506        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   507        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.5           | 0     |
   508      Then the parties should have the following account balances:
   509        | party  | asset | market id | margin | general | order margin | bond |
   510        | party1 | USD   | ETH/FEB23 | 79500  | 92000   | 0            | 1000 |
   511  
   512      And the parties place the following orders:
   513        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   514        | party1 | ETH/FEB23 | buy  | 6      | 15800 | 0                | TYPE_LIMIT | TIF_GTC | b-1       |
   515  
   516      Then the parties should have the following account balances:
   517        | party  | asset | market id | margin | general | order margin | bond |
   518        | party1 | USD   | ETH/FEB23 | 79500  | 92000   | 0            | 1000 |
   519  
   520      #trigger more MTM (18585-15900)*10=26850 with party has both short position and bond account
   521      And the parties place the following orders:
   522        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   523        | buySideProvider  | ETH/FEB23 | buy  | 1      | 23585 | 0                | TYPE_LIMIT | TIF_GTC |
   524        | sellSideProvider | ETH/FEB23 | sell | 1      | 23585 | 1                | TYPE_LIMIT | TIF_GTC |
   525  
   526      When the network moves ahead "1" blocks
   527      #margin maintenance: min(10*(20000-18585),18585*10*0.25)+10*0.1*18585=32735
   528      And the parties should have the following margin levels:
   529        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   530        | party1 | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.5           | 0     |
   531  
   532      Then the parties should have the following account balances:
   533        | party  | asset | market id | margin | general | order margin | bond |
   534        | party1 | USD   | ETH/FEB23 | 0      | 92000   | 0            | 0    |
   535  
   536      And the orders should have the following status:
   537        | party  | reference | status         |
   538        | party1 | b-1       | STATUS_STOPPED |
   539  
   540      And the following transfers should happen:
   541        | from   | to              | from account            | to account              | market id | amount | asset |
   542        | party1 | market          | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 76850  | USD   |
   543        | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 76850  | USD   |
   544        | party1 | market          | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 3650   | USD   |
   545        | party1 | party1          | ACCOUNT_TYPE_BOND       | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 1000   | USD   |
   546  
   547  
   548  
   549  
   550