code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/closeout-lognormal.feature (about)

     1  Feature: Closeout scenarios
     2    # This is a test case to demonstrate an order can be rejected when the trader (who places an initial order) does not have enouge collateral to cover the initial margin level
     3  
     4    Background:
     5  
     6      Given the log normal risk model named "log-normal-risk-model-1":
     7        | risk aversion | tau | mu | r | sigma |
     8        | 0.000001      | 0.1 | 0  | 0 | 1.0   |
     9      #risk factor short = 3.55690359157934000
    10      #risk factor long = 0.801225765
    11      And the margin calculator named "margin-calculator-1":
    12        | search factor | initial factor | release factor |
    13        | 1.5           | 2              | 3              |
    14      And the markets:
    15        | id        | quote name | asset | risk model              | margin calculator   | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    16        | ETH/DEC19 | BTC        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
    17        | ETH/DEC20 | BTC        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | default-basic    | default-eth-for-future | 0.25                   | 0                         | default-futures |
    18      And the following network parameters are set:
    19        | name                                    | value |
    20        | market.auction.minimumDuration          | 1     |
    21        | network.markPriceUpdateMaximumFrequency | 0s    |
    22        | limits.markets.maxPeggedOrders          | 2     |
    23  
    24    @EndBlock @Liquidation
    25    Scenario: 001, 2 parties get close-out at the same time. Distressed position gets taken over by LP, distressed order gets canceled (0005-COLL-002; 0012-POSR-001; 0012-POSR-002; 0012-POSR-004; 0012-POSR-005; 0007-POSN-015)
    26      # setup accounts, we are trying to closeout trader3 first and then trader2
    27  
    28      Given the insurance pool balance should be "0" for the market "ETH/DEC19"
    29  
    30      Given the parties deposit on asset's general account the following amount:
    31        | party      | asset | amount        |
    32        | auxiliary1 | USD   | 1000000000000 |
    33        | auxiliary2 | USD   | 1000000000000 |
    34        | trader2    | USD   | 2000          |
    35        | trader3    | USD   | 162           |
    36        | lprov      | USD   | 1000000000000 |
    37        | closer     | USD   | 1000000000000 |
    38  
    39      When the parties submit the following liquidity provision:
    40        | id  | party | market id | commitment amount | fee   | lp type    |
    41        | lp1 | lprov | ETH/DEC19 | 100000            | 0.001 | submission |
    42        | lp1 | lprov | ETH/DEC19 | 100000            | 0.001 | amendment  |
    43      And the parties place the following pegged iceberg orders:
    44        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    45        | lprov | ETH/DEC19 | 100       | 10                   | sell | ASK              | 100        | 55     |
    46        | lprov | ETH/DEC19 | 100       | 10                   | buy  | BID              | 100        | 55     |
    47      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    48      # trading happens at the end of the open auction period
    49      Then the parties place the following orders:
    50        | party | market id | side | price | volume | resulting trades | type | tif | reference |
    51        | auxiliary2 | ETH/DEC19 | buy  | 5    | 5  | 0 | TYPE_LIMIT | TIF_GTC | aux-b-5    |
    52        | auxiliary1 | ETH/DEC19 | sell | 1000 | 10 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1000 |
    53        | auxiliary2 | ETH/DEC19 | buy  | 10   | 10 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-1    |
    54        | auxiliary1 | ETH/DEC19 | sell | 10   | 10 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1    |
    55      When the opening auction period ends for market "ETH/DEC19"
    56      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    57      And the mark price should be "10" for the market "ETH/DEC19"
    58  
    59      # trader2 posts and order that would take over position of trader3 if they have enough to support it at the new mark price
    60      When the parties place the following orders:
    61        | party   | market id | side | price | volume | resulting trades | type       | tif     | reference   |
    62        | trader2 | ETH/DEC19 | buy  | 50    | 40     | 0                | TYPE_LIMIT | TIF_GTC | buy-order-3 |
    63      Then the order book should have the following volumes for market "ETH/DEC19":
    64        | side | price | volume |
    65        | buy  | 5    | 5       |
    66        | buy  | 50   | 40      |
    67        | sell | 1000 | 10      |
    68        | sell | 1055 | 100     |
    69  
    70      And the parties should have the following account balances:
    71        | party      | asset | market id | margin     | general      |
    72        | trader2 | USD | ETH/DEC19 | 642  | 1358         |
    73        | lprov   | USD | ETH/DEC19 | 7114 | 999999892886 |
    74  
    75  # # margin level_trader2= OrderSize*MarkPrice*RF = 40*10*0.801225765=321
    76  # # margin level_Lprov= OrderSize*MarkPrice*RF = 100*10*3.55690359157934000=3557
    77  
    78      # trader3 posts a limit order
    79      When the parties place the following orders:
    80        | party   | market id | side | price | volume | resulting trades | type       | tif     | reference       |
    81        | trader3 | ETH/DEC19 | buy  | 100   | 10     | 0                | TYPE_LIMIT | TIF_GTC | buy-position-31 |
    82  
    83      Then the order book should have the following volumes for market "ETH/DEC19":
    84        | side | price | volume |
    85        | buy  | 5     | 5      |
    86        | buy  | 45    | 100    |
    87        | buy  | 50    | 40     |
    88        | buy  | 100   | 10     |
    89        | sell | 1000  | 10     |
    90        | sell | 1055  | 100    |
    91  
    92      And the parties should have the following margin levels:
    93        | party   | market id | maintenance | search | initial | release |
    94        | trader3 | ETH/DEC19 | 81          | 121    | 162     | 243     |
    95  # margin level_trader3= OrderSize*MarkPrice*RF = 100*10*0.801225765=81
    96  
    97      #setup for close out
    98      When the parties place the following orders:
    99        | party      | market id | side | price | volume | resulting trades | type       | tif     | reference       |
   100        | auxiliary2 | ETH/DEC19 | sell | 100   | 10     | 1                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   101      Then the network moves ahead "4" blocks
   102  
   103      And the mark price should be "100" for the market "ETH/DEC19"
   104  
   105      Then the following trades should be executed:
   106        | buyer   | price | size | seller     |
   107        | trader3 | 100   | 10   | auxiliary2 |
   108  
   109      When the network moves ahead "1" blocks
   110      Then the order book should have the following volumes for market "ETH/DEC19":
   111        | side | price | volume |
   112        | buy  | 5     | 0      |
   113        | buy  | 45    | 0      |
   114        | buy  | 50    | 0      |
   115        | buy  | 100   | 0      |
   116        | sell | 1000  | 10     |
   117        | sell | 1055  | 100    |
   118  
   119      #   #trader3 is closed out, trader2 has no more open orders as they got cancelled after becoming distressed
   120      And the parties should have the following margin levels:
   121        | party   | market id | maintenance | search | initial | release |
   122        | trader2 | ETH/DEC19 | 0           | 0      | 0       | 0       |
   123        | trader3 | ETH/DEC19 | 0           | 0      | 0       | 0       |
   124      # trader3 can not be closed-out because there is not enough vol on the order book
   125      And the parties should have the following account balances:
   126        | party   | asset | market id | margin | general |
   127        | trader2 | USD   | ETH/DEC19 | 0      | 2000    |
   128        | trader3 | USD   | ETH/DEC19 | 0      | 0       |
   129  
   130      Then the parties should have the following profit and loss:
   131        | party      | volume | unrealised pnl | realised pnl | status                        |
   132        | trader2    | 0      | 0              | 0            | POSITION_STATUS_ORDERS_CLOSED |
   133        | trader3    | 0      | 0              | -162         | POSITION_STATUS_CLOSED_OUT    |
   134        | auxiliary1 | -10    | -900           | 0            |                               |
   135        | auxiliary2 | 5      | 475            | 586          |                               |
   136      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   137      When the parties place the following orders:
   138        | party      | market id | side | price | volume | resulting trades | type       | tif     | reference       |
   139        | auxiliary2 | ETH/DEC19 | buy  | 1     | 10     | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   140  
   141      When the parties place the following orders:
   142        | party      | market id | side | price | volume | resulting trades | type       | tif     | reference       |
   143        | auxiliary2 | ETH/DEC19 | sell | 100   | 10     | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   144        | auxiliary1 | ETH/DEC19 | buy  | 100   | 10     | 1                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   145  
   146      Then the network moves ahead "4" blocks
   147      And the order book should have the following volumes for market "ETH/DEC19":
   148        | side | price | volume |
   149        | buy  | 1     | 5      |
   150        | buy  | 5     | 0      |
   151        | buy  | 45    | 0      |
   152        | buy  | 50    | 0      |
   153        | buy  | 100   | 0      |
   154        | sell | 1000  | 10     |
   155        | sell | 1055  | 100    |
   156  
   157      And the parties should have the following margin levels:
   158        | party   | market id | maintenance | search | initial | release |
   159        | trader2 | ETH/DEC19 | 0           | 0      | 0       | 0       |
   160        | trader3 | ETH/DEC19 | 0           | 0      | 0       | 0       |
   161      And the parties should have the following account balances:
   162        | party   | asset | market id | margin | general |
   163        | trader2 | USD   | ETH/DEC19 | 0      | 2000    |
   164        | trader3 | USD   | ETH/DEC19 | 0      | 0       |
   165  
   166  # 0007-POSN-015
   167      And the parties should have the following profit and loss:
   168        | party   | volume | unrealised pnl | realised pnl | status                        |
   169        | trader2 | 0      | 0              | 0            | POSITION_STATUS_ORDERS_CLOSED |
   170  
   171      And the insurance pool balance should be "3" for the market "ETH/DEC19"
   172      And the parties should have the following profit and loss:
   173        | party      | volume | unrealised pnl | realised pnl |
   174        | auxiliary1 | 0      | 0              | -900         |
   175        | auxiliary2 | 0      | 0              | 1061         |
   176        | trader2    | 0      | 0              | 0            |
   177        | trader3    | 0      | 0              | -162         |