code.vegaprotocol.io/vega@v0.79.0/core/integration/features/capped-futures/0016-PFUT-023.feature (about)

     1  Feature: When max_price is specified and the market is ran in a fully-collateralised mode and it has parties with open positions settling it at a price of 0 works correctly
     2  
     3    Background:
     4      Given time is updated to "2019-11-30T00:00:00Z"
     5      And the average block duration is "1"
     6  
     7      And the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
     8        | property         | type         | binding         |
     9        | prices.ETH.value | TYPE_INTEGER | settlement data |
    10  
    11      And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
    12        | property           | type         | binding             |
    13        | trading.terminated | TYPE_BOOLEAN | trading termination |
    14  
    15      And the settlement data decimals for the oracle named "ethDec21Oracle" is given in "0" decimal places
    16  
    17      And the following network parameters are set:
    18        | name                                         | value |
    19        | market.auction.minimumDuration               | 1     |
    20        | network.markPriceUpdateMaximumFrequency      | 1s    |
    21        | market.liquidity.successorLaunchWindowLength | 1s    |
    22        | limits.markets.maxPeggedOrders               | 4     |
    23  
    24      And the fees configuration named "fees-config-1":
    25        | maker fee | infrastructure fee |
    26        | 0.005     | 0.02               |
    27      And the price monitoring named "price-monitoring-1":
    28        | horizon | probability | auction extension |
    29        | 3600000 | 0.99        | 300               |
    30      And the log normal risk model named "lognormal-risk-model-1":
    31        | risk aversion | tau  | mu | r   | sigma |
    32        | 0.0002        | 0.01 | 0  | 0.0 | 1.2   |
    33  
    34      And the markets:
    35        | id        | quote name | asset | risk model             | margin calculator                | auction duration | fees          | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params      | max price cap | fully collateralised | binary |
    36        | ETH/DEC21 | ETH        | USD   | lognormal-risk-model-1 | default-capped-margin-calculator | 1                | fees-config-1 | default-none     | ethDec21Oracle     | 0.25                   | 0                         | default-futures | 1500          | true                 | false  |
    37  
    38    @SLABug @NoPerp @Capped @CZero @CappedBug
    39    Scenario: 0016-PFUT-023: no closeout happens when mark to market settlement is carried out at a price of `0`
    40      Given the initial insurance pool balance is "10000" for all the markets
    41      And the parties deposit on asset's general account the following amount:
    42        | party    | asset | amount    |
    43        | party1   | USD   | 10000     |
    44        | party2   | USD   | 10000     |
    45        | aux1     | USD   | 100000    |
    46        | aux2     | USD   | 100000    |
    47        | aux3     | USD   | 100000    |
    48        | aux4     | USD   | 100000    |
    49        | aux5     | USD   | 100000    |
    50        | party-lp | USD   | 100000000 |
    51  
    52      And the parties submit the following liquidity provision:
    53        | id  | party    | market id | commitment amount | fee | lp type    |
    54        | lp2 | party-lp | ETH/DEC21 | 30000             | 0   | submission |
    55  
    56      When the parties place the following orders:
    57        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error |
    58        | aux1   | ETH/DEC21 | buy  | 2      | 1     | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |       |
    59        | aux2   | ETH/DEC21 | sell | 2      | 1499  | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |       |
    60        | party1 | ETH/DEC21 | buy  | 5      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |       |
    61        | party2 | ETH/DEC21 | sell | 5      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |       |
    62      And the network moves ahead "2" blocks
    63  
    64      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
    65      And the market state should be "STATE_ACTIVE" for the market "ETH/DEC21"
    66      And the mark price should be "1000" for the market "ETH/DEC21"
    67      And the parties should have the following account balances:
    68        | party  | asset | market id | margin | general |
    69        | party1 | USD   | ETH/DEC21 | 5000   | 5000    |
    70        | party2 | USD   | ETH/DEC21 | 2500   | 7500    |
    71  
    72      #order margin for aux1: limit price * size = 999*2=1998
    73      #order margin for aux2: (max price - limit price) * size = (1500-1301)*2=398
    74      #party1 maintenance margin level: position size * average entry price = 5*1000=5000
    75      #party2 maintenance margin level: position size * (max price - average entry price)=5*(1500-1000)=2500
    76      #aux1: potential position * average price on book = 2 * 0 = 0
    77      #aux2: potential position * (max price -  limit price) = 2 * 0 = 0
    78      And the parties should have the following margin levels:
    79        | party  | market id | maintenance | search | initial | release | margin mode  |
    80        | party1 | ETH/DEC21 | 5000        | 5000   | 5000    | 5000    | cross margin |
    81        | party2 | ETH/DEC21 | 2500        | 2500   | 2500    | 2500    | cross margin |
    82        | aux2   | ETH/DEC21 | 2           | 2      | 2       | 2       | cross margin |
    83        | aux1   | ETH/DEC21 | 2           | 2      | 2       | 2       | cross margin |
    84  
    85      #update mark price
    86      When the parties place the following orders:
    87        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    88        | aux1  | ETH/DEC21 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC | aux1-2    |
    89        | aux2  | ETH/DEC21 | sell | 1      | 1     | 1                | TYPE_LIMIT | TIF_GTC | aux2-2    |
    90  
    91      And debug trades
    92      And debug detailed orderbook volumes for market "ETH/DEC21"
    93      And the network moves ahead "2" blocks
    94      Then the mark price should be "1" for the market "ETH/DEC21"
    95  
    96      And the following trades should be executed:
    97        | buyer | price | size | seller |
    98        | aux1  | 1     | 1    | aux2   |
    99  
   100      # MTM settlement 5 long makes a loss of 5000, 5 short makes a profit of 5000
   101      # Now for aux1 and 2, the calculations from above still hold but more margin is required due to the open positions:
   102      # aux1: position * 1100 + 999*2 = 1100 + 1998 = 3098
   103      # aux2: then placing the order (max price - average order price) * 3 = (1500 - (1301 + 1301 + 1100)/3) * 3 = (1500 - 1234) * 3 = 266 * 3 = 798
   104      # aux2's short position and potential margins are calculated separately as 2 * (1500-1301) + 1 * (1500 - 1100) = 398 + 400 = 798
   105      And the parties should have the following account balances:
   106        | party  | asset | market id | margin | general |
   107        | party1 | USD   | ETH/DEC21 | 5      | 5000    |
   108        | party2 | USD   | ETH/DEC21 | 7495   | 7500    |
   109        | aux1   | USD   | ETH/DEC21 | 3      | 99998   |
   110        | aux2   | USD   | ETH/DEC21 | 1501   | 98497   |
   111  
   112      #update mark price to max_price
   113      When the parties place the following orders:
   114        | party | market id | side | volume | price | resulting trades | type       | tif     | reference | error |
   115        | aux3  | ETH/DEC21 | buy  | 2      | 1499  | 1                | TYPE_LIMIT | TIF_GTC | aux3-1    |       |
   116  
   117      And the following trades should be executed:
   118        | buyer | price | size | seller |
   119        | aux3  | 1499  | 2    | aux2   |
   120  
   121      And the network moves ahead "2" blocks
   122      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
   123      Then the mark price should be "1499" for the market "ETH/DEC21"
   124  
   125      # MTM settlement 5 long makes a profit of 2000, 5 short loses 2000
   126      # Now for aux1 and 2, the calculations from above still hold but more margin is required due to the open positions:
   127      # aux1: position * 1100 + 999*2 = 1100 + 1998 = 3098
   128      # aux2: short position of size 2, traded price at 1500, then margin: postion size * (max price - average entry price) = 3*(1100+1500*2)/3
   129      And the parties should have the following account balances:
   130        | party  | asset | market id | margin | general |
   131        | party1 | USD   | ETH/DEC21 | 7495   | 5000    |
   132        | party2 | USD   | ETH/DEC21 | 5      | 7500    |
   133        | aux1   | USD   | ETH/DEC21 | 1501   | 99998   |
   134        | aux2   | USD   | ETH/DEC21 | 3      | 98512   |
   135        | aux3   | USD   | ETH/DEC21 | 2998   | 96927   |
   136  
   137      And the parties should have the following margin levels:
   138        | party  | market id | maintenance | search | initial | release | margin mode  |
   139        | party1 | ETH/DEC21 | 7495        | 7495   | 7495    | 7495    | cross margin |
   140        | party2 | ETH/DEC21 | 5           | 5      | 5       | 5       | cross margin |
   141        | aux2   | ETH/DEC21 | 3           | 3      | 3       | 3       | cross margin |
   142        | aux1   | ETH/DEC21 | 1501        | 1501   | 1501    | 1501    | cross margin |