code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0006-POSI-AC-008.feature (about)

     1  Feature: test AC 0006-POSI-008
     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 | ETH        | ETH   | default-simple-risk-model-3 | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 4                      | 0                         | default-futures |
     7      And the following network parameters are set:
     8        | name                                    | value |
     9        | market.auction.minimumDuration          | 1     |
    10        | network.markPriceUpdateMaximumFrequency | 0s    |
    11        | limits.markets.maxPeggedOrders          | 2     |
    12  
    13    Scenario:  Open long position, trades occur closing the long position and opening a short position (0006-POSI-008)
    14      Given the parties deposit on asset's general account the following amount:
    15        | party  | asset | amount   |
    16        | party1 | ETH   | 10000    |
    17        | party2 | ETH   | 10000    |
    18        | party3 | ETH   | 10000    |
    19        | aux    | ETH   | 100000   |
    20        | aux2   | ETH   | 100000   |
    21        | aux3   | ETH   | 100000   |
    22        | lpprov | ETH   | 10000000 |
    23  
    24      When the parties submit the following liquidity provision:
    25        | id  | party  | market id | commitment amount | fee | lp type    |
    26        | lp1 | lpprov | ETH/DEC19 | 9000              | 0.1 | submission |
    27        | lp1 | lpprov | ETH/DEC19 | 9000              | 0.1 | submission |
    28      And the parties place the following pegged iceberg orders:
    29        | party  | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    30        | lpprov | ETH/DEC19 | 231       | 1                    | buy  | BID              | 231        | 10     |
    31        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 231        | 10     |
    32   
    33      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    34      And the parties place the following orders:
    35        | party | market id | side | volume | price | resulting trades | type       | tif     |
    36        | aux   | ETH/DEC19 | buy  | 5      | 49    | 0                | TYPE_LIMIT | TIF_GTC |
    37        | aux   | ETH/DEC19 | sell | 5      | 5001  | 0                | TYPE_LIMIT | TIF_GTC |
    38        | aux2  | ETH/DEC19 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    39        | aux   | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    40  
    41      Then the opening auction period ends for market "ETH/DEC19"
    42      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    43      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
    44  
    45      And the market data for the market "ETH/DEC19" should be:
    46        | mark price | trading mode            | target stake | supplied stake | open interest |
    47        | 1000       | TRADING_MODE_CONTINUOUS | 1100         | 9000           | 1             |
    48  
    49      When the parties place the following orders with ticks:
    50        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    51        | party1 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    52        | party2 | ETH/DEC19 | buy  | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    53      Then the parties should have the following margin levels:
    54        | party  | market id | maintenance |
    55        | party1 | ETH/DEC19 | 4100        |
    56        | party2 | ETH/DEC19 | 4110        |
    57        | lpprov | ETH/DEC19 | 25410       |
    58  
    59      Then the parties should have the following account balances:
    60        | party  | asset | market id | margin | general |
    61        | party1 | ETH   | ETH/DEC19 | 4920   | 5080    |
    62        | party2 | ETH   | ETH/DEC19 | 4932   | 4968    |
    63  
    64      # maintenance margin for party1: 4*1000+1*0.1*1000 = 4100
    65  
    66      Then the order book should have the following volumes for market "ETH/DEC19":
    67        | side | price | volume |
    68        | sell | 5011  | 2      |
    69        | sell | 5001  | 5      |
    70        | buy  | 49    | 5      |
    71        | buy  | 39    | 231    |
    72  
    73      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
    74  
    75      When the parties place the following orders with ticks:
    76        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    77        | party1 | ETH/DEC19 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    78      Then the parties should have the following account balances:
    79        | party  | asset | market id | margin | general |
    80        | party1 | ETH   | ETH/DEC19 | 5040   | 4960    |
    81  
    82      # update linear slippage factor more in line with what book-based slippage used to be
    83      And the markets are updated:
    84          | id          | linear slippage factor |
    85          | ETH/DEC19   | 1.5                    |
    86  
    87      When the parties place the following orders with ticks:
    88        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    89        | party3 | ETH/DEC19 | buy  | 1      | 2000  | 1                | TYPE_LIMIT | TIF_GTC |
    90  
    91      Then the parties should have the following margin levels:
    92        | party  | market id | maintenance |
    93        | party1 | ETH/DEC19 | 6400        |
    94  
    95      Then the parties should have the following account balances:
    96        | party  | asset | market id | margin | general |
    97        | party1 | ETH   | ETH/DEC19 | 7680   | 1320    |
    98        | party2 | ETH   | ETH/DEC19 | 3864   | 7036    |
    99        | party3 | ETH   | ETH/DEC19 | 3864   | 5936    |
   100      # maintenance margin for party1: 2*1.5*2000+2*0.1*2000 = 6400
   101  
   102      Then the following transfers should happen:
   103        | from   | to     | from account        | to account              | market id | amount | asset |
   104        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1000   | ETH   |
   105        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 1000   | ETH   |
   106      And the cumulated balance for all accounts should be worth "10330000"
   107      And the settlement account should have a balance of "0" for the market "ETH/DEC19"
   108  
   109      Then the parties should have the following profit and loss:
   110        | party  | volume | unrealised pnl | realised pnl |
   111        | aux    | -1     | -1000          | 0            |
   112        | aux2   | 1      | 1000           | 0            |
   113        | party1 | -2     | -1000          | 0            |
   114        | party2 | 1      | 1000           | 0            |
   115        | party3 | 1      | 0              | 0            |
   116  
   117      When the parties place the following orders with ticks:
   118        | party | market id | side | volume | price | resulting trades | type       | tif     |
   119        | aux   | ETH/DEC19 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   120        | aux3  | ETH/DEC19 | sell | 1      | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   121  
   122      Then the parties should have the following profit and loss:
   123        | party  | volume | unrealised pnl | realised pnl |
   124        #aux closed short position: AC 0006-POSI-008
   125        | aux    | 0      | 0              | 0            |
   126        | aux2   | 1      | 0              | 0            |
   127        #aux3 opened long position
   128        | aux3   | -1     | 0              | 0            |
   129        | party1 | -2     | 1000           | 0            |
   130        | party2 | 1      | 0              | 0            |
   131        | party3 | 1      | -1000          | 0            |
   132  
   133      And the market data for the market "ETH/DEC19" should be:
   134        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   135        | 1000       | TRADING_MODE_CONTINUOUS |         |           |           | 3300         | 9000           | 3             |
   136  
   137