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

     1  Feature: Position resolution case 4
     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.5349                 | 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 enough orders on the orderbook to cover the position (0008-TRAD-006, 0008-TRAD-007))
    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   | 10000         |
    20        | auxiliary        | BTC   | 1000000000000 |
    21        | auxiliary2       | 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     | reference |
    26        | auxiliary2 | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1   |
    27        | auxiliary  | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1   |
    28        | auxiliary  | ETH/DEC19 | sell | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-2   |
    29        | auxiliary2 | ETH/DEC19 | buy  | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-2   |
    30      Then the opening auction period ends for market "ETH/DEC19"
    31      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    32      And the mark price should be "180" 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 | 150    | 200   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    38        | buySideProvider  | ETH/DEC19 | buy  | 50     | 190   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    39        | buySideProvider  | ETH/DEC19 | buy  | 50     | 180   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2  |
    40  
    41      # update linear slippage factor more in line with what book-based slippage used to be
    42      And the markets are updated:
    43          | id          | linear slippage factor |
    44          | ETH/DEC19   | 0.1111111111111111     |
    45  
    46      # insurance pool generation - trade
    47      When the parties place the following orders with ticks:
    48        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    49        | designatedLooser | ETH/DEC19 | sell | 100    | 180   | 2                | TYPE_LIMIT | TIF_GTC | ref-1     |
    50  
    51      And the mark price should be "180" for the market "ETH/DEC19"
    52  
    53      Then the order book should have the following volumes for market "ETH/DEC19":
    54        | side | price | volume |
    55        | sell | 1000  | 1      |
    56        | sell | 200   | 150    |
    57  
    58      And the average fill price is:
    59          | market     | volume | side | ref price | mark price | equivalent linear slippage factor |
    60          | ETH/DEC19  | 100    | sell | 180       | 180        | 0.1111111111111111                |
    61  
    62      Then the parties should have the following account balances:
    63        | party            | asset | market id | margin | general |
    64        | designatedLooser | BTC   | ETH/DEC19 | 8000   | 2500    |
    65  
    66      Then the parties should have the following margin levels:
    67        | party            | market id | maintenance | search | initial | release |
    68        | designatedLooser | ETH/DEC19 | 2000        | 6400   | 8000    | 10000   |
    69  
    70      # insurance pool generation - modify order book
    71      Then the parties cancel the following orders:
    72        | party            | reference       |
    73        | sellSideProvider | sell-provider-1 |
    74  
    75      # add back some volume on the sell side
    76      When the parties place the following orders with ticks:
    77        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    78        | sellSideProvider | ETH/DEC19 | sell | 150    | 350   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-2 |
    79  
    80      # insurance pool generation - set new mark price (and trigger closeout)
    81      When the parties place the following orders with ticks:
    82        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    83        | sellSideProvider | ETH/DEC19 | sell | 1      | 300   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    84        | buySideProvider  | ETH/DEC19 | buy  | 1      | 300   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    85  
    86      And the mark price should be "300" for the market "ETH/DEC19"
    87  
    88      #check positions
    89      Then the parties should have the following profit and loss:
    90        | party            | volume | unrealised pnl | realised pnl |
    91        | designatedLooser | 0      | 0              | -10000       |
    92        | buySideProvider  | 101    | 11500          | -1363        |
    93  
    94      # checking margins
    95      Then the parties should have the following account balances:
    96        | party            | asset | market id | margin | general |
    97        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
    98  
    99      # then we make sure the insurance pool collected the funds
   100      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   101  
   102  
   103      # now we check what's left in the orderbook
   104      # we expect 50 orders to be left there on the sell side
   105      # we buy a first time 50 to consume the book
   106      # then try to buy 1 again -> result in no trades -> sell side empty.
   107      # Try to sell one for low price -> no trades -> buy side empty -> order book empty.
   108      When the parties place the following orders with ticks:
   109        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
   110        | buySideProvider  | ETH/DEC19 | buy  | 50     | 350   | 1                | TYPE_LIMIT | TIF_FOK | ref-1     |
   111        | buySideProvider  | ETH/DEC19 | buy  | 1      | 350   | 0                | TYPE_LIMIT | TIF_FOK | ref-2     |
   112        | sellSideProvider | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_FOK | ref-3     |