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

     1  Feature: Test closeout under isolated margin mode when party has bond account
     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 has open position and bond account (0019-MCAL-072)
    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   | 173500       |
    23  
    24      When the parties submit the following liquidity provision:
    25        | id  | party  | market id | commitment amount | fee | lp type    |
    26        | lp1 | party1 | ETH/FEB23 | 1000              | 0.1 | submission |
    27  
    28      And the parties place the following orders:
    29        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference |
    30        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    31        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |           |
    32        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    33        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    34        | party1           | ETH/FEB23 | sell | 8      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |           |
    35        | sellSideProvider | ETH/FEB23 | sell | 1      | 200000 | 0                | TYPE_LIMIT | TIF_GTC |           |
    36        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |           |
    37  
    38      When the network moves ahead "2" blocks
    39      Then the mark price should be "15900" for the market "ETH/FEB23"
    40      And the order book should have the following volumes for market "ETH/FEB23":
    41        | side | price  | volume |
    42        | buy  | 14900  | 10     |
    43        | buy  | 15800  | 6      |
    44        | sell | 15900  | 8      |
    45        | sell | 200000 | 1      |
    46        | sell | 200100 | 10     |
    47      And the parties should have the following margin levels:
    48        | party  | market id | maintenance | search | initial | release |
    49        | party1 | ETH/FEB23 | 68370       | 75207  | 82044   | 95718   |
    50      #margin = min(3*(100000-15900), 15900*(0.25))+0.1*15900=5565
    51  
    52      Then the parties should have the following account balances:
    53        | party  | asset | market id | margin | general | bond |
    54        | party1 | USD   | ETH/FEB23 | 82044  | 90456   | 1000 |
    55  
    56      #switch to isolated margin
    57      And the parties submit update margin mode:
    58        | party  | market    | margin_mode     | margin_factor |
    59        | party1 | ETH/FEB23 | isolated margin | 0.6           |
    60  
    61      And the parties should have the following margin levels:
    62        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    63        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.6           | 76320 |
    64  
    65      Then the parties should have the following account balances:
    66        | party  | asset | market id | margin | general | order margin |
    67        | party1 | USD   | ETH/FEB23 | 95400  | 780     | 76320        |
    68  
    69      #trigger more MTM with party has both short position and short orders
    70      And the parties place the following orders:
    71        | party            | market id | side | volume | price | resulting trades | type       | tif     |
    72        | buySideProvider  | ETH/FEB23 | buy  | 10     | 17000 | 1                | TYPE_LIMIT | TIF_GTC |
    73        | sellSideProvider | ETH/FEB23 | sell | 2      | 17000 | 1                | TYPE_LIMIT | TIF_GTC |
    74  
    75      And the market data for the market "ETH/FEB23" should be:
    76        | mark price | trading mode            |
    77        | 15900      | TRADING_MODE_CONTINUOUS |
    78      And the network moves ahead "1" blocks
    79  
    80      And the market data for the market "ETH/FEB23" should be:
    81        | mark price | trading mode            |
    82        | 17000      | TRADING_MODE_CONTINUOUS |
    83  
    84      Then the parties should have the following account balances:
    85        | party  | asset | market id | margin | general | order margin | bond |
    86        | party1 | USD   | ETH/FEB23 | 151920 | 780     | 0            | 1000 |
    87  
    88      #MTM for party1: 18*(17000-15900)=19800
    89      And the following transfers should happen:
    90        | from   | to              | from account            | to account              | market id | amount | asset |
    91        | party1 | market          | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 19800  | USD   |
    92        | market | buySideProvider | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 19800  | USD   |
    93  
    94      #increase margin factor
    95      And the parties submit update margin mode:
    96        | party  | market    | margin_mode     | margin_factor | error                                                                      |
    97        | party1 | ETH/FEB23 | isolated margin | 0.9           | insufficient balance in general account to cover for required order margin |
    98  
    99      #trigger more MTM with party has both short position and short orders
   100      And the parties place the following orders:
   101        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   102        | buySideProvider  | ETH/FEB23 | buy  | 1      | 20000 | 0                | TYPE_LIMIT | TIF_GTC |
   103        | sellSideProvider | ETH/FEB23 | sell | 1      | 20000 | 1                | TYPE_LIMIT | TIF_GTC |
   104      And the market data for the market "ETH/FEB23" should be:
   105        | mark price | trading mode            |
   106        | 17000      | TRADING_MODE_CONTINUOUS |
   107  
   108      Then the parties should have the following account balances:
   109        | party  | asset | market id | margin | general | order margin | bond |
   110        | party1 | USD   | ETH/FEB23 | 151920 | 780     | 0            | 1000 |
   111  
   112      And the network moves ahead "1" blocks
   113  
   114      # what happens here is that the party gets closed out, their general account balance is untouched
   115      # but their bond balance is taken and then topped up from the general account
   116      # it's a bit weird but that's how it works
   117      Then the parties should have the following account balances:
   118        | party  | asset | market id | margin | general | order margin | bond |
   119        | party1 | USD   | ETH/FEB23 | 0      | 0       | 0            | 780  |
   120  
   121      And the following transfers should happen:
   122        | from   | to     | from account        | to account              | market id | amount | asset |
   123        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/FEB23 | 54000  | USD   |
   124        | party1 | party1 | ACCOUNT_TYPE_BOND   | ACCOUNT_TYPE_MARGIN     | ETH/FEB23 | 1000   | USD   |
   125        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_INSURANCE  | ETH/FEB23 | 98920  | USD   |
   126  
   127    Scenario: 002 closeout when party has open position, order, and bond account(0019-MCAL-073)
   128      Given the parties deposit on asset's general account the following amount:
   129        | party            | asset | amount       |
   130        | buySideProvider  | USD   | 100000000000 |
   131        | sellSideProvider | USD   | 100000000000 |
   132        | party1           | USD   | 216500       |
   133      When the parties submit the following liquidity provision:
   134        | id  | party  | market id | commitment amount | fee | lp type    |
   135        | lp1 | party1 | ETH/FEB23 | 1000              | 0.1 | submission |
   136  
   137      And the parties place the following orders:
   138        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference  |
   139        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   140        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15800  | 0                | TYPE_LIMIT | TIF_GTC |            |
   141        | buySideProvider  | ETH/FEB23 | buy  | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   142        | party1           | ETH/FEB23 | sell | 10     | 15900  | 0                | TYPE_LIMIT | TIF_GTC |            |
   143        | party1           | ETH/FEB23 | sell | 1      | 200000 | 0                | TYPE_LIMIT | TIF_GTC | party-sell |
   144        | sellSideProvider | ETH/FEB23 | sell | 10     | 200000 | 0                | TYPE_LIMIT | TIF_GTC |            |
   145        | sellSideProvider | ETH/FEB23 | sell | 10     | 200100 | 0                | TYPE_LIMIT | TIF_GTC |            |
   146  
   147      When the network moves ahead "2" blocks
   148      Then the mark price should be "15900" for the market "ETH/FEB23"
   149      And the order book should have the following volumes for market "ETH/FEB23":
   150        | side | price  | volume |
   151        | buy  | 14900  | 10     |
   152        | buy  | 15800  | 6      |
   153        | sell | 200000 | 11     |
   154      #   | sell | 200100 | 10     |
   155      And the parties should have the following margin levels:
   156        | party  | market id | maintenance | initial |
   157        | party1 | ETH/FEB23 | 57240       | 68688   |
   158      #slippage_per_unit: (19500+200000*9)/10-15900)=166050
   159      #margin: 10*min(166050, 15900*0.25)+0.1*15900*11=57240
   160  
   161      Then the parties should have the following account balances:
   162        | party  | asset | market id | margin | general | bond |
   163        | party1 | USD   | ETH/FEB23 | 68688  | 146812  | 1000 |
   164  
   165      #switch to isolated margin
   166      And the parties submit update margin mode:
   167        | party  | market    | margin_mode     | margin_factor |
   168        | party1 | ETH/FEB23 | isolated margin | 0.6           |
   169  
   170      And the parties should have the following margin levels:
   171        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order  |
   172        | party1 | ETH/FEB23 | 55650       | 0      | 66780   | 0       | isolated margin | 0.6           | 120000 |
   173  
   174      Then the parties should have the following account balances:
   175        | party  | asset | market id | margin | general | order margin | bond |
   176        | party1 | USD   | ETH/FEB23 | 95400  | 100     | 120000       | 1000 |
   177  
   178      #trigger more MTM (18000-15900)*10= 21000 with party has both short position and short orders, when party is distressed, order will remain active
   179      And the parties place the following orders:
   180        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   181        | buySideProvider  | ETH/FEB23 | buy  | 1      | 18000 | 0                | TYPE_LIMIT | TIF_GTC |
   182        | sellSideProvider | ETH/FEB23 | sell | 1      | 18000 | 1                | TYPE_LIMIT | TIF_GTC |
   183  
   184      And the market data for the market "ETH/FEB23" should be:
   185        | mark price | trading mode            |
   186        | 15900      | TRADING_MODE_CONTINUOUS |
   187      And the network moves ahead "1" blocks
   188  
   189      And the market data for the market "ETH/FEB23" should be:
   190        | mark price | trading mode            |
   191        | 18000      | TRADING_MODE_CONTINUOUS |
   192  
   193      #party1's open position is distressed
   194      Then the parties should have the following account balances:
   195        | party  | asset | market id | margin | general | order margin | bond |
   196        | party1 | USD   | ETH/FEB23 | 74400  | 100     | 120000       | 1000 |
   197  
   198      # #MTM for party1: 10*(25440-18000)=74400
   199      #trigger more MTM with party has both short position and short orders and empty the margin account
   200      And the parties place the following orders:
   201        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   202        | buySideProvider  | ETH/FEB23 | buy  | 1      | 25440 | 0                | TYPE_LIMIT | TIF_GTC |
   203        | sellSideProvider | ETH/FEB23 | sell | 1      | 25440 | 1                | TYPE_LIMIT | TIF_GTC |
   204  
   205      And the network moves ahead "1" blocks
   206  
   207      And the market data for the market "ETH/FEB23" should be:
   208        | mark price | trading mode            |
   209        | 25440      | TRADING_MODE_CONTINUOUS |
   210  
   211      # @jiajia this is quite a funny case... their long position is getting closed out
   212      # but they have short order, so the network is trading with them which gets them back into a position
   213      # this time the other side
   214      Then the parties should have the following account balances:
   215        | party  | asset | market id | margin | general | order margin | bond |
   216        | party1 | USD   | ETH/FEB23 | 120000 | 0       | 0            | 100  |
   217  
   218      # #MTM for party1: 10*(25540-25440)=1000
   219      #trigger more MTM with party has both short position and the margin account is already empty
   220      And the parties place the following orders:
   221        | party            | market id | side | volume | price | resulting trades | type       | tif     |
   222        | buySideProvider  | ETH/FEB23 | buy  | 1      | 25540 | 0                | TYPE_LIMIT | TIF_GTC |
   223        | sellSideProvider | ETH/FEB23 | sell | 1      | 25540 | 1                | TYPE_LIMIT | TIF_GTC |
   224  
   225      And the network moves ahead "1" blocks
   226  
   227      And the market data for the market "ETH/FEB23" should be:
   228        | mark price | trading mode            |
   229        | 25540      | TRADING_MODE_CONTINUOUS |
   230  
   231      Then the parties should have the following account balances:
   232        | party  | asset | market id | margin | general | order margin | bond |
   233        | party1 | USD   | ETH/FEB23 | 120000 |         | 0            | 100  |
   234  
   235      And the insurance pool balance should be "0" for the market "ETH/FEB23"
   236  
   237