code.vegaprotocol.io/vega@v0.79.0/core/integration/features/closeouts/0012-POSR-010.feature (about)

     1  Feature: When the network party holds a non-zero position and there are not enough funds in market's insurance pool
     2           to meet the mark-to-market payment the network's position is unaffected and loss socialisation is applied. (0012-POSR-010)
     3  
     4    Background:
     5      Given the liquidation strategies:
     6        | name           | disposal step | disposal fraction | full disposal size | max fraction consumed | disposal slippage range |
     7        | disposal-strat | 1000          | 1.0               | 1000               | 1.0                   | 0.1                     |
     8  
     9      Given the markets:
    10        | id        | quote name | asset | risk model                  | margin calculator                  | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      | liquidation strategy |
    11        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-2 | default-overkill-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures | disposal-strat       |
    12      And the following network parameters are set:
    13        | name                                    | value |
    14        | market.auction.minimumDuration          | 1     |
    15        | network.markPriceUpdateMaximumFrequency | 0s    |
    16  
    17    Scenario: Implement trade and order network. Covers both 0012-POSR-012 and 0012-POSR-011
    18      # setup accounts
    19      Given the parties deposit on asset's general account the following amount:
    20        | party            | asset | amount        |
    21        | sellSideProvider | BTC   | 1000000000000 |
    22        | buySideProvider  | BTC   | 1000000000000 |
    23        | designatedLoser  | BTC   | 120           |
    24        | aux              | BTC   | 1000000000000 |
    25        | aux2             | BTC   | 1000000000000 |
    26  
    27      # insurance pool generation - setup orderbook
    28      When the parties place the following orders:
    29        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    30        | sellSideProvider | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    31        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    32        | aux              | ETH/DEC19 | sell | 100    | 159   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1         |
    33        | aux              | ETH/DEC19 | sell | 1      | 149   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-2         |
    34        | aux2             | ETH/DEC19 | buy  | 1      | 149   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1         |
    35        | aux2             | ETH/DEC19 | buy  | 100    | 140   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-2         |
    36      Then the opening auction period ends for market "ETH/DEC19"
    37      When the network moves ahead "1" blocks
    38      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    39  
    40      And the mark price should be "149" for the market "ETH/DEC19"
    41  
    42      Then the parties should have the following account balances:
    43        | party           | asset | market id | general |
    44        | designatedLoser | BTC   | ETH/DEC19 | 120     |
    45  
    46      # insurance pool generation - trade
    47      When the parties place the following orders:
    48        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    49        | designatedLoser  | ETH/DEC19 | buy  | 250    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
    50      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    51      When the network moves ahead "1" blocks
    52  
    53      And the mark price should be "150" for the market "ETH/DEC19"
    54  
    55      # The designatedLoser will be closed out and have all their funds moved to the insurance pool
    56      Then the parties should have the following account balances:
    57        | party            | asset | market id | general       | margin      |
    58        | designatedLoser  | BTC   | ETH/DEC19 | 0             | 0           |
    59        | aux              | BTC   | ETH/DEC19 | 999999999848  | 151         |
    60        | aux2             | BTC   | ETH/DEC19 | 999999999848  | 153         |
    61        | sellSideProvider | BTC   | ETH/DEC19 | 999999962500  | 37500       |
    62        | buySideProvider  | BTC   | ETH/DEC19 | 1000000000000 | 0           |
    63  
    64      And the insurance pool balance should be "120" for the market "ETH/DEC19"    
    65  
    66      # check the network trades happened and the network party holds the volume
    67      Then the following network trades should be executed:
    68        | party           | aggressor side | volume |
    69        | designatedLoser | buy            | 250    |
    70  
    71      And the parties should have the following profit and loss:
    72        | party            | volume | unrealised pnl | realised pnl |
    73        | aux2             | 1      | 1              | 0            |
    74        | aux              | -1     | -1             | 0            |
    75        | sellSideProvider | -250   | 0              | 0            |
    76        | designatedLoser  | 0      | 0              | -120         |
    77        | network          | 250    | 0              | 0            |
    78  
    79      # Move the mark price to make our network trader lose money
    80      When the parties place the following orders:
    81        | party | market id | side | volume | price | resulting trades | type       | tif     |
    82        | aux   | ETH/DEC19 | buy  | 1      | 145   | 0                | TYPE_LIMIT | TIF_GTC |
    83        | aux2  | ETH/DEC19 | sell | 1      | 145   | 1                | TYPE_LIMIT | TIF_GTC |
    84      When the network moves ahead "1" blocks
    85  
    86      And the mark price should be "145" for the market "ETH/DEC19"
    87  
    88      # The insurance pool will be depleted due to the price move
    89      And the insurance pool balance should be "0" for the market "ETH/DEC19"    
    90  
    91      # Check that funds have not been fully paid (lose socialisation has taken place)
    92      # aux is short and should gain 6 but only gets 1 (will lose 5),
    93      # sellSideProvider is short and should gain 1250 but only gets 124 (will lose 1126)
    94      # Total distributed is 125 when it should have been 1255
    95      Then the parties should have the following account balances:
    96        | party            | asset | market id | general       | margin      |
    97        | aux              | BTC   | ETH/DEC19 | 1000000000000 | 0           |
    98        | aux2             | BTC   | ETH/DEC19 | 999999999996  | 0           |
    99        | sellSideProvider | BTC   | ETH/DEC19 | 999999962500  | 37624       |
   100        | buySideProvider  | BTC   | ETH/DEC19 | 1000000000000 | 0           |
   101      # This part explicitly covers 0012-POSR-011:
   102      # The insurance pool balance is zero, so the network does not meet the required margin balance
   103      # Despite this, it can maintain its position, and loss socialisation kicks in during the MTM settlement.
   104      And the parties should have the following profit and loss:
   105        | party            | volume | unrealised pnl | realised pnl |
   106        | aux2             | 0      | 0              | -4           |
   107        | aux              | 0      | 0              | 0            |
   108        | sellSideProvider | -250   | 1250           | -1126        |
   109        | designatedLoser  | 0      | 0              | -120         |
   110        | network          | 250    | -1250          | 0            |
   111      And the parties should have the following margin levels:
   112        | party   | market id | maintenance |
   113        | network | ETH/DEC19 | 9063        |
   114      And the insurance pool balance should be "0" for the market "ETH/DEC19"