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

     1  Feature: Position resolution case 1
     2  
     3    Background:
     4  
     5      Given the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
     6        | property         | type         | binding         |
     7        | prices.BTC.value | TYPE_INTEGER | settlement data |
     8      And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec21Oracle":
     9        | property           | type         | binding             |
    10        | trading.terminated | TYPE_BOOLEAN | trading termination |
    11      And the markets:
    12        | id        | quote name | asset | risk model                  | margin calculator                  | auction duration | fees         | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params      |
    13        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-2 | default-overkill-margin-calculator | 1                | default-none | default-none     | ethDec21Oracle     | 0.9145                 | 0                         | default-futures |
    14      And the following network parameters are set:
    15        | name                                    | value |
    16        | market.auction.minimumDuration          | 1     |
    17        | network.markPriceUpdateMaximumFrequency | 0s    |
    18  
    19    @Liquidation @LiquidationCurrent
    20    Scenario: close out when there is not enough orders on the orderbook to cover the position (0007-POSN-009, 0008-TRAD-001, 0008-TRAD-002, 0008-TRAD-005)
    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        | designatedLooser | BTC   | 11600         |
    27        | aux              | BTC   | 1000000000000 |
    28        | aux2             | BTC   | 1000000000000 |
    29  
    30      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    31      Then the parties place the following orders:
    32        | party | market id | side | volume | price | resulting trades | type       | tif     |
    33        | aux   | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    34        | aux   | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    35        | aux   | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    36        | aux2  | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    37      Then the opening auction period ends for market "ETH/DEC19"
    38      And the mark price should be "150" for the market "ETH/DEC19"
    39      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    40  
    41      # insurance pool generation - setup orderbook
    42      When the parties place the following orders with ticks:
    43        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    44        | sellSideProvider | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    45        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    46  
    47      # insurance pool generation - trade
    48      When the parties place the following orders with ticks:
    49        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    50        | designatedLooser | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
    51      And the network moves ahead "1" blocks
    52  
    53      # margin level: vol* slippage = vol * (MarkPrice-ExitPrice) =290 * (150-(1*10+140*1)/11) = 290*137 = 39700
    54  
    55      Then the parties should have the following account balances:
    56        | party            | asset | market id | margin | general |
    57        | designatedLooser | 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        | designatedLooser | 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        | designatedLooser | 0      | 0              | -11600       |
    66        | sellSideProvider | -290   | 0              | 0            |
    67        | buySideProvider  | 1      | 10             | 0            |
    68        | aux              | 11     | 1490           | 0            |
    69        | aux2             | -1     | 0              | 0            |
    70  
    71      When the parties place the following orders with ticks:
    72        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference      |
    73        | buySideProvider | ETH/DEC19 | buy  | 1      | 40    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2 |
    74  
    75      # insurance pool generation - set new mark price (and trigger closeout)
    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 | 1      | 120   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    79        | buySideProvider  | ETH/DEC19 | buy  | 1      | 120   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    80  
    81      # MTM (designatedLooser): 11600-(290*(150-120))=11600-8700=2900
    82      Then the parties should have the following account balances:
    83        | party            | asset | market id | margin | general      |
    84        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0            |
    85        | sellSideProvider | BTC   | ETH/DEC19 | 127740 | 999999880960 |
    86        | buySideProvider  | BTC   | ETH/DEC19 | 1320   | 999999998740 |
    87        | aux              | BTC   | ETH/DEC19 | 5706   | 999999995454 |
    88        | aux2             | BTC   | ETH/DEC19 | 440    | 999999999590 |
    89  
    90      # margin level: vol* slippage = vol * (MarkPrice-ExitPrice) =290 * (120-(1*10+40*1)/11) = 290*116 = 33640
    91      And the parties should have the following margin levels:
    92        | party            | market id | maintenance | search | initial | release |
    93        | designatedLooser | ETH/DEC19 | 0           | 0      | 0       | 0       |
    94  
    95      # check positions
    96      Then the parties should have the following profit and loss:
    97        | party            | volume | unrealised pnl | realised pnl |
    98        | designatedLooser | 0      | 0              | -11600       |
    99        | sellSideProvider | -291   | 8700           | 0            |
   100        | buySideProvider  | 3      | 60             | 0            |
   101        | aux              | 11     | 1160           | 0            |
   102        | aux2             | -1     | 30             | 0            |
   103  
   104      # checking margins
   105      Then the parties should have the following account balances:
   106        | party            | asset | market id | margin | general |
   107        | designatedLooser | BTC   | ETH/DEC19 | 0      | 0       |
   108  
   109      And the insurance pool balance should be "1650" for the market "ETH/DEC19"
   110  
   111      When the oracles broadcast data signed with "0xCAFECAFE1":
   112        | name               | value |
   113        | trading.terminated | true  |
   114  
   115      And time is updated to "2021-03-01T01:01:01Z"
   116      Then the market state should be "STATE_TRADING_TERMINATED" for the market "ETH/DEC19"
   117  
   118      When the oracles broadcast data signed with "0xCAFECAFE1":
   119        | name             | value |
   120        | prices.BTC.value | 120   |
   121  
   122      And then the network moves ahead "10" blocks
   123  
   124      #Then debug all events as JSON file "all_evts.json"
   125      Then the parties should have the following profit and loss:
   126        | party            | volume | realised pnl | unrealised pnl |
   127        | designatedLooser | 0      | -11600       | 0              |
   128        | sellSideProvider | -291   | 8700         | 0              |
   129        | buySideProvider  | 3      | 60           | 0              |
   130        | aux              | 11     | 1160         | 0              |
   131        | aux2             | -1     | 30           | 0              |
   132        | network          | 278    | -9950        | 0              |