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

     1  Feature: 0012-POSR-013 Gradual release of position.
     2  
     3    Background:
     4      Given the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
     5        | property         | type         | binding         |
     6        | prices.BTC.value | TYPE_INTEGER | settlement data |
     7      And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
     8        | property           | type         | binding             |
     9        | trading.terminated | TYPE_BOOLEAN | trading termination |
    10      And the markets:
    11        | 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 |
    12        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-2 | default-overkill-margin-calculator | 1                | default-none | default-none     | ethDec21Oracle     | 0.9145                 | 0                         | default-futures | AC-013-strat         |
    13      And the following network parameters are set:
    14        | name                                    | value |
    15        | market.auction.minimumDuration          | 1     |
    16        | network.markPriceUpdateMaximumFrequency | 0s    |
    17  
    18  
    19    @LiquidationAC
    20    Scenario: 0012-POSR-013 based on verified-positions-resolution-1.feature
    21      # setup accounts
    22      Given the parties deposit on asset's general account the following amount:
    23        | party            | asset | amount        |
    24        | sellSideProvider | BTC   | 1000000000000 |
    25        | buySideProvider  | BTC   | 1000000000000 |
    26        | desginatedLoser  | BTC   | 11600         |
    27        | aux              | BTC   | 1000000000000 |
    28        | aux2             | BTC   | 1000000000000 |
    29        | bulkSeller       | BTC   | 9999999999999 |
    30        | bulkBuyer        | BTC   | 9999999999999 |
    31  
    32      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    33      Then the parties place the following orders:
    34        | party | market id | side | volume | price | resulting trades | type       | tif     |
    35        | aux   | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    36        | aux   | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    37        | aux   | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    38        | aux2  | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    39      Then the opening auction period ends for market "ETH/DEC19"
    40      And the mark price should be "150" for the market "ETH/DEC19"
    41      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    42  
    43      # insurance pool generation - setup orderbook
    44      When the parties place the following orders with ticks:
    45        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    46        | sellSideProvider | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    47        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    48  
    49      # insurance pool generation - trade
    50      When the parties place the following orders with ticks:
    51        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference |
    52        | desginatedLoser | ETH/DEC19 | buy  | 280    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
    53      And the network moves ahead "1" blocks
    54  
    55      Then the parties should have the following account balances:
    56        | party           | asset | market id | margin | general |
    57        | desginatedLoser | BTC   | ETH/DEC19 | 0      | 0       |
    58  
    59      And the parties should have the following margin levels:
    60        | party           | market id | maintenance | search | initial | release |
    61        | desginatedLoser | ETH/DEC19 | 0           | 0      | 0       | 0       |
    62  
    63      Then the parties should have the following profit and loss:
    64        | party            | volume | unrealised pnl | realised pnl |
    65        | aux              | 1      | 0              | 0            |
    66        | aux2             | -1     | 0              | 0            |
    67        | sellSideProvider | -280   | 0              | 0            |
    68        | buySideProvider  | 0      | 0              | 0            |
    69        | desginatedLoser  | 0      | 0              | -11600       |
    70        | network          | 280    | 0              | 0            |
    71      # Now that the network has the position as per AC (280 long), ensure the volume on the book is correct
    72      # The buy volume should always be 10,000. Place sell orders to match to avoid increased margin requirement
    73      # as a result of an unknown exit price.
    74      # Current book:
    75      # SELL orders:
    76      # 	| Party            | Volume | Remaining | Price |
    77  	#   | sellSideProvider | 290    | 10        | 150   |
    78  	#   | aux              | 10     | 10        | 2000  |
    79      # BUY orders:
    80      #    | Party           | Volume | Remaining | Price |
    81  	#    | buySideProvider | 1      | 1         | 140   |
    82  	#    | aux             | 10     | 10        | 1     |
    83      # First bring both sides to 100, then increase gradually to avoid margin issues, both sides will have 10k volume on the book after this step
    84      When the parties place the following orders with ticks:
    85        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    86        | sellSideProvider | ETH/DEC19 | sell | 80     | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-2 |
    87        | buySideProvider  | ETH/DEC19 | buy  | 89     | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2  |
    88        | bulkBuyer        | ETH/DEC19 | buy  | 200    | 145   | 0                | TYPE_LIMIT | TIF_GTC | bbuy-1          |
    89        | bulkSeller       | ETH/DEC19 | sell | 200    | 150   | 0                | TYPE_LIMIT | TIF_GTC | bsell-1         |
    90        | bulkBuyer        | ETH/DEC19 | buy  | 400    | 145   | 0                | TYPE_LIMIT | TIF_GTC | bbuy-2          |
    91        | bulkSeller       | ETH/DEC19 | sell | 400    | 150   | 0                | TYPE_LIMIT | TIF_GTC | bsell-2         |
    92        | bulkBuyer        | ETH/DEC19 | buy  | 800    | 145   | 0                | TYPE_LIMIT | TIF_GTC | bbuy-3          |
    93        | bulkSeller       | ETH/DEC19 | sell | 800    | 150   | 0                | TYPE_LIMIT | TIF_GTC | bsell-3         |
    94        | bulkBuyer        | ETH/DEC19 | buy  | 1500   | 145   | 0                | TYPE_LIMIT | TIF_GTC | bbuy-4          |
    95        | bulkSeller       | ETH/DEC19 | sell | 1500   | 150   | 0                | TYPE_LIMIT | TIF_GTC | bsell-4         |
    96        | bulkBuyer        | ETH/DEC19 | buy  | 7000   | 145   | 0                | TYPE_LIMIT | TIF_GTC | bbuy-5          |
    97        | bulkSeller       | ETH/DEC19 | sell | 7000   | 150   | 0                | TYPE_LIMIT | TIF_GTC | bsell-5         |
    98      # Move network forwards 10 blocks to have the network reduce its position
    99      And the network moves ahead "10" blocks
   100      Then the following trades should be executed:
   101        | buyer     | price | size | seller  |
   102        | bulkBuyer | 145   | 100  | network |
   103      Then the parties should have the following profit and loss:
   104        | party            | volume | unrealised pnl | realised pnl |
   105        | aux              | 1      | 0              | 0            |
   106        | aux2             | -1     | 0              | 0            |
   107        | sellSideProvider | -280   | 0              | 0            |
   108        | buySideProvider  | 0      | 0              | 0            |
   109        | desginatedLoser  | 0      | 0              | -11600       |
   110        | network          | 180    | 0              | -500         |
   111        | bulkBuyer        | 100    | 500            | 0            |
   112      # Restore the volume on the book, use a different party just because
   113      When the parties place the following orders with ticks:
   114        | party | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   115        | aux   | ETH/DEC19 | buy  | 100    | 140   | 0                | TYPE_LIMIT | TIF_GTC | aux-provider-2 |
   116      # Next release of position
   117      And the network moves ahead "10" blocks
   118      Then the following trades should be executed:
   119        | buyer     | price | size | seller  |
   120        | bulkBuyer | 145   | 90   | network |
   121      Then the parties should have the following profit and loss:
   122        | party            | volume | unrealised pnl | realised pnl |
   123        | aux              | 1      | 0              | 0            |
   124        | aux2             | -1     | 0              | 0            |
   125        | sellSideProvider | -280   | 0              | 0            |
   126        | buySideProvider  | 0      | 0              | 0            |
   127        | desginatedLoser  | 0      | 0              | -11600       |
   128        | network          | 90     | 0              | -950         |
   129        | bulkBuyer        | 190    | 950            | 0            |
   130      # Restore the volume on the book, use a different party just because
   131      When the parties place the following orders with ticks:
   132        | party | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   133        | aux2  | ETH/DEC19 | buy  | 90     | 140   | 0                | TYPE_LIMIT | TIF_GTC | aux-provider-3 |
   134  
   135      # Next release of position
   136      And the network moves ahead "10" blocks
   137      ## We provided the volume on the book in separate orders, the trades will reflect this
   138      ## so in this case, the trade for 45 is split across 2 orders. This does show that this batch/trade
   139      ## is different to the next, making all network trades unique in this scenario.
   140      Then the following trades should be executed:
   141        | buyer     | price | size | seller  |
   142        | bulkBuyer | 145   | 10   | network |
   143        | bulkBuyer | 145   | 35   | network |
   144      Then the parties should have the following profit and loss:
   145        | party            | volume | unrealised pnl | realised pnl |
   146        | aux              | 1      | 0              | 0            |
   147        | aux2             | -1     | 0              | 0            |
   148        | sellSideProvider | -280   | 0              | 0            |
   149        | buySideProvider  | 0      | 0              | 0            |
   150        | desginatedLoser  | 0      | 0              | -11600       |
   151        | network          | 45     | 0              | -1175        |
   152        | bulkBuyer        | 235    | 1175           | 0            |
   153      # Restore the volume on the book, use a different party just because
   154      When the parties place the following orders with ticks:
   155        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   156        | buySideProvider | ETH/DEC19 | buy  | 45     | 140   | 0                | TYPE_LIMIT | TIF_GTC | aux-provider-3 |
   157      # Last release of position
   158      And the network moves ahead "10" blocks
   159      Then the following trades should be executed:
   160        | buyer     | price | size | seller  |
   161        | bulkBuyer | 145   | 45   | network |
   162      Then the parties should have the following profit and loss:
   163        | party            | volume | unrealised pnl | realised pnl |
   164        | aux              | 1      | 0              | 0            |
   165        | aux2             | -1     | 0              | 0            |
   166        | sellSideProvider | -280   | 0              | 0            |
   167        | buySideProvider  | 0      | 0              | 0            |
   168        | desginatedLoser  | 0      | 0              | -11600       |
   169        | network          | 0      | 0              | -1400        |
   170        | bulkBuyer        | 280    | 1400           | 0            |