code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/verified-positions-resolution-2.feature (about)

     1  Feature: Position resolution case 2
     2  
     3    Background:
     4      Given the markets:
     5        | id        | quote name | asset | risk model                  | margin calculator                  | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
     6        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-2 | default-overkill-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.535                  | 0                         | default-futures |
     7      And the following network parameters are set:
     8        | name                                    | value |
     9        | market.auction.minimumDuration          | 1     |
    10        | network.markPriceUpdateMaximumFrequency | 0s    |
    11  
    12    @Liquidation
    13    Scenario: close out when there is not enough orders on the orderbook to cover the position (0008-TRAD-003, 0008-TRAD-004)
    14      # setup accounts
    15      Given the parties deposit on asset's general account the following amount:
    16        | party            | asset | amount        |
    17        | sellSideProvider | BTC   | 1000000000000 |
    18        | buySideProvider  | BTC   | 1000000000000 |
    19        | designatedLooser | BTC   | 12000         |
    20        | aux              | BTC   | 1000000000000 |
    21        | aux2             | BTC   | 1000000000000 |
    22  
    23      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    24      Then the parties place the following orders:
    25        | party | market id | side | volume | price | resulting trades | type       | tif     |
    26        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    27        | aux   | ETH/DEC19 | sell | 1      | 151   | 0                | TYPE_LIMIT | TIF_GTC |
    28        | aux   | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    29        | aux2  | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    30      Then the opening auction period ends for market "ETH/DEC19"
    31      And the mark price should be "150" for the market "ETH/DEC19"
    32      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    33  
    34      # insurance pool generation - setup orderbook
    35      When the parties place the following orders with ticks:
    36        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    37        | sellSideProvider | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    38        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    39  
    40      # insurance pool generation - trade
    41      When the parties place the following orders with ticks:
    42        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    43        | designatedLooser | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
    44  
    45      # margin level: vol* slippage = vol * (MarkPrice-ExitPrice) =290 * (150-(1*1+140*1)/2) = 290*80 = 23200
    46  
    47      Then the parties should have the following account balances:
    48        | party            | asset | market id | margin | general |
    49        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
    50  
    51      And the parties should have the following margin levels:
    52        | party            | market id | maintenance | search | initial | release |
    53        | designatedLooser | ETH/DEC19 | 0           | 0      | 0       | 0       |
    54  
    55  
    56      When the parties place the following orders with ticks:
    57        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference      |
    58        | buySideProvider | ETH/DEC19 | buy  | 1      | 40    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
    59  
    60      # check the party accounts
    61      Then the parties should have the following account balances:
    62        | party            | asset | market id | margin | general |
    63        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
    64  
    65      # insurance pool generation - set new mark price (and trigger closeout)
    66      When the parties place the following orders with ticks:
    67        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    68        | sellSideProvider | ETH/DEC19 | sell | 1      | 120   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    69        | buySideProvider  | ETH/DEC19 | buy  | 1      | 120   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    70  
    71      # margin level: vol* slippage = vol * (MarkPrice-ExitPrice) =290 * (120-(1*1+40*1)/2) = 290*100 = 29000
    72      # margin account with MTM: 12000 - 290*(150-120)= 3300
    73  
    74      Then the parties should have the following account balances:
    75        | party            | asset | market id | margin | general |
    76        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
    77  
    78      And the parties should have the following margin levels:
    79        | party            | market id | maintenance | search | initial | release |
    80        | designatedLooser | ETH/DEC19 | 0           | 0      | 0       | 0       |
    81  
    82      # check positions
    83      Then the parties should have the following profit and loss:
    84        | party            | volume | unrealised pnl | realised pnl |
    85        | designatedLooser | 0      | 0              | -12000       |
    86  
    87      # checking margins
    88      Then the parties should have the following account balances:
    89        | party            | asset | market id | margin | general |
    90        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
    91  
    92      # then we make sure the insurance pool collected the funds
    93      And the insurance pool balance should be "3121" for the market "ETH/DEC19"
    94