code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/Negative-Position-Decimal-Places.feature (about)

     1  Feature: test negative PDP (position decimal places)
     2      Background:
     3          Given the following network parameters are set:
     4              | name                                    | value |
     5              | market.liquidity.bondPenaltyParameter   | 0.2   |
     6              | network.markPriceUpdateMaximumFrequency | 0s    |
     7              | limits.markets.maxPeggedOrders          | 4     |
     8          Given the liquidity monitoring parameters:
     9              | name       | triggering ratio | time window | scaling factor |
    10              | lqm-params | 0.10             | 24h         | 1.0            |
    11  
    12          And the following assets are registered:
    13              | id  | decimal places |
    14              | ETH | 5              |
    15              | USD | 2              |
    16          And the average block duration is "1"
    17          And the log normal risk model named "log-normal-risk-model-1":
    18              | risk aversion | tau | mu | r | sigma |
    19              | 0.000001      | 0.1 | 0  | 0 | 1.0   |
    20          #risk factor short: 3.5569036
    21          #risk factor long: 0.801225765
    22  
    23          And the fees configuration named "fees-config-1":
    24              | maker fee | infrastructure fee |
    25              | 0.004     | 0.001              |
    26          And the price monitoring named "price-monitoring-1":
    27              | horizon | probability | auction extension |
    28              | 360000  | 0.99        | 300               |
    29          And the liquidity sla params named "SLA-1":
    30              | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    31              | 0.99        | 0.5                          | 1                             | 1.0                    |
    32          And the liquidity sla params named "SLA-2":
    33              | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    34              | 0.000001    | 0.5                          | 1                             | 1.0                    |
    35          And the markets:
    36              | id        | quote name | asset | liquidity monitoring | risk model              | margin calculator         | auction duration | fees          | price monitoring   | data source config     | decimal places | position decimal places | linear slippage factor | quadratic slippage factor | sla params |
    37              | USD/DEC22 | USD        | ETH   | lqm-params           | log-normal-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 5              | -1                      | 0.25                   | 0                         | SLA-1      |
    38              | USD/DEC23 | USD        | ETH   | lqm-params           | log-normal-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 2              | -2                      | 0.25                   | 0                         | SLA-2      |
    39          And the parties deposit on asset's general account the following amount:
    40              | party  | asset | amount    |
    41              | party0 | ETH   | 5000000   |
    42              | party1 | ETH   | 100000000 |
    43              | party2 | ETH   | 100000000 |
    44              | party3 | ETH   | 100000000 |
    45              | lpprov | ETH   | 100000000 |
    46  
    47      @Now
    48      Scenario: 001, test negative PDP when trading mode is auction (0019-MCAL-010)
    49  
    50          When  the parties submit the following liquidity provision:
    51              | id  | party  | market id | commitment amount | fee   | lp type    |
    52              | lp7 | party0 | USD/DEC22 | 1000              | 0.001 | submission |
    53              | lp7 | party0 | USD/DEC22 | 1000              | 0.001 | amendment  |
    54              | lp6 | lpprov | USD/DEC22 | 4000              | 0.001 | submission |
    55              | lp6 | lpprov | USD/DEC22 | 4000              | 0.001 | amendment  |
    56          And the parties place the following pegged iceberg orders:
    57              | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
    58              | party0 | USD/DEC22 | 11        | 1                    | sell | ASK              | 11     | 20     |
    59              | party0 | USD/DEC22 | 11        | 1                    | buy  | BID              | 11     | 20     |
    60              | lpprov | USD/DEC22 | 4         | 1                    | sell | ASK              | 4      | 20     |
    61              | lpprov | USD/DEC22 | 4         | 1                    | buy  | BID              | 4      | 20     |
    62  
    63          And the parties place the following orders:
    64              | party  | market id | side | volume | price | resulting trades | type       | tif     | reference   |
    65              | party1 | USD/DEC22 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | buy-ref-2a  |
    66              | party2 | USD/DEC22 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | sell-ref-3a |
    67              | party0 | USD/DEC22 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC | buy-ref-1a  |
    68              | party0 | USD/DEC22 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC | sell-ref-4a |
    69  
    70          Then the market data for the market "USD/DEC22" should be:
    71              | target stake | supplied stake |
    72              | 35569        | 5000           |
    73          And the parties should have the following account balances:
    74              | party  | asset | market id | margin | general  | bond |
    75              | party0 | ETH   | USD/DEC22 | 46951  | 4952049  | 1000 |
    76              | party1 | ETH   | USD/DEC22 | 9609   | 99990391 |      |
    77              | party2 | ETH   | USD/DEC22 | 42684  | 99957316 |      |
    78  
    79          # target stake= vol * mark price * rf = 1*10*1000*3.5569036*10 = 35569
    80          When the opening auction period ends for market "USD/DEC22"
    81          And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "USD/DEC22"
    82          And the mark price should be "1000" for the market "USD/DEC22"
    83  
    84          Then the parties should have the following account balances:
    85              | party  | asset | market id | margin | general  | bond |
    86              | party0 | ETH   | USD/DEC22 | 512194 | 4486806  | 1000 |
    87              | party1 | ETH   | USD/DEC22 | 12609  | 99987391 |      |
    88              | party2 | ETH   | USD/DEC22 | 42684  | 99957316 |      |
    89  
    90          And the parties should have the following margin levels:
    91              | party  | market id | maintenance |
    92              | party0 | USD/DEC22 | 426829      |
    93              | party1 | USD/DEC22 | 10508       |
    94              | party2 | USD/DEC22 | 38070       |
    95  
    96      @Now
    97      Scenario: 002, test negative PDP when trading mode is continuous (0003-MTMK-014, 0019-MCAL-010, 0029-FEES-014)
    98          Given the parties submit the following liquidity provision:
    99              | id  | party  | market id | commitment amount | fee   | lp type    |
   100              | lp2 | party0 | USD/DEC22 | 35569             | 0.001 | submission |
   101  
   102          And the parties place the following pegged iceberg orders:
   103              | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   104              | party0 | USD/DEC22 | 2         | 1                    | sell | ASK              | 500    | 20     |
   105              | party0 | USD/DEC22 | 2         | 1                    | buy  | BID              | 500    | 20     |
   106  
   107          # LP places limit orders which oversupply liquidity
   108          And the parties place the following orders:
   109              | party  | market id | side | volume | price | type       | tif     |
   110              | party0 | USD/DEC22 | sell | 1481   | 13    | TYPE_LIMIT | TIF_GTC |
   111              | party0 | USD/DEC22 | buy  | 1206   | 8     | TYPE_LIMIT | TIF_GTC |
   112  
   113          And the parties place the following orders:
   114              | party  | market id | side | volume | price | resulting trades | type       | tif     | reference  |
   115              | party1 | USD/DEC22 | buy  | 5      | 8     | 0                | TYPE_LIMIT | TIF_GTC | buy-ref-1  |
   116              | party1 | USD/DEC22 | buy  | 1      | 9     | 0                | TYPE_LIMIT | TIF_GTC | buy-ref-1  |
   117              | party1 | USD/DEC22 | buy  | 10     | 10    | 0                | TYPE_LIMIT | TIF_GTC | buy-ref-2  |
   118              | party2 | USD/DEC22 | sell | 10     | 10    | 0                | TYPE_LIMIT | TIF_GTC | sell-ref-3 |
   119              | party2 | USD/DEC22 | sell | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | sell-ref-1 |
   120              | party2 | USD/DEC22 | sell | 5      | 11    | 0                | TYPE_LIMIT | TIF_GTC | sell-ref-2 |
   121  
   122          When the opening auction period ends for market "USD/DEC22"
   123          Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "USD/DEC22"
   124          And the auction ends with a traded volume of "10" at a price of "10"
   125  
   126          And the market data for the market "USD/DEC22" should be:
   127              | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   128              | 10         | TRADING_MODE_CONTINUOUS | 360000  | 8         | 13        | 3556         | 35569          | 10            |
   129          # target stake = 10*10*10*3.5569036=3556
   130  
   131  
   132  
   133          And the parties should have the following account balances:
   134              | party  | asset | market id | margin | general  | bond  |
   135              | party0 | ETH   | USD/DEC22 | 821773 | 4142658  | 35569 |
   136              | party1 | ETH   | USD/DEC22 | 1838   | 99998162 |       |
   137              | party2 | ETH   | USD/DEC22 | 7042   | 99992958 |       |
   138  
   139          And the parties should have the following margin levels:
   140              | party  | market id | maintenance |
   141              | party0 | USD/DEC22 | 704623      |
   142              | party1 | USD/DEC22 | 1532        |
   143              | party2 | USD/DEC22 | 5942        |
   144  
   145          #risk factor short: 3.5569036
   146          #risk factor long: 0.801225765
   147          # Margin_maintenance_party0 = max((1481+500)*10*3.5569036*10,1206*10*0.801225765*10)=704623
   148          And the following trades should be executed:
   149              | buyer  | price | size | seller |
   150              | party1 | 10    | 10   | party2 |
   151  
   152          Then the parties should have the following profit and loss:
   153              | party  | volume | unrealised pnl | realised pnl |
   154              | party1 | 10     | 0              | 0            |
   155              | party2 | -10    | 0              | 0            |
   156  
   157          Then the order book should have the following volumes for market "USD/DEC22":
   158              | side | price | volume |
   159              | sell | 13    | 1481   |
   160              | sell | 11    | 5      |
   161              | sell | 10    | 1      |
   162              | buy  | 9     | 1      |
   163              | buy  | 8     | 1211   |
   164  
   165          And the parties place the following orders with ticks:
   166              | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   167              | party3 | USD/DEC22 | sell | 1      | 9     | 1                | TYPE_LIMIT | TIF_GTC | buy-ref-3 |
   168  
   169          And the following trades should be executed:
   170              | seller | price | size | buyer  |
   171              | party3 | 9     | 1    | party1 |
   172  
   173          # trade_value_for_fee_purposes for party3: size_of_trade * price_of_trade = 1*10 * 9 = 90
   174          # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.001 * 90 = 0.09 =1 (rounded up to nearest whole value)
   175          # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.004 * 90 = 0.36 =1 (rounded up to nearest whole value)
   176          # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 90= 0.09 =1 (rounded up to nearest whole value)
   177  
   178          And the following transfers should happen:
   179              | from   | to     | from account            | to account                       | market id | amount | asset |
   180              | party3 | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | USD/DEC22 | 1      | ETH   |
   181              | party3 |        | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1      | ETH   |
   182              | market | party1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | USD/DEC22 | 1      | ETH   |
   183  
   184          Then the parties should have the following profit and loss:
   185              | party  | volume | unrealised pnl | realised pnl |
   186              | party1 | 11     | -100           | 0            |
   187              | party2 | -10    | 100            | 0            |
   188              | party3 | -1     | 0              | 0            |
   189              | party0 | 0      | 0              | 0            |
   190  
   191          #MTM with price change from 10 to 9, party1 has long position of volume 10, price 10 ->9, MTM -1*10*10*1=-100; party2 has short position of volume 10, price 10 ->9, MTM 10*10*1=100;
   192          And the parties should have the following account balances:
   193              | party  | asset | market id | margin | general  | bond  |
   194              | party0 | ETH   | USD/DEC22 | 821773 | 4142658  | 35569 |
   195              | party1 | ETH   | USD/DEC22 | 1738   | 99998163 |       |
   196              | party2 | ETH   | USD/DEC22 | 7142   | 99992958 |       |
   197          # Margin_maintenance_party0 = max(1481*10*3.5569036*9,1206*10*0.801225765*9)=474100
   198          And the parties should have the following margin levels:
   199              | party  | market id | maintenance |
   200              | party0 | USD/DEC22 | 634161      |
   201              | party1 | USD/DEC22 | 1401        |
   202              | party2 | USD/DEC22 | 5347        |
   203  
   204          #party3 place order at price 8 to change the mark price again
   205          And the parties place the following orders with ticks:
   206              | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   207              | party3 | USD/DEC22 | sell | 1      | 8     | 1                | TYPE_LIMIT | TIF_GTC | buy-ref-3 |
   208  
   209          And the following trades should be executed:
   210              | seller | price | size | buyer  |
   211              | party3 | 9     | 1    | party1 |
   212  
   213          And the market data for the market "USD/DEC22" should be:
   214              | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   215              | 8          | TRADING_MODE_CONTINUOUS | 360000  | 8         | 13        | 3414         | 35569          | 12            |
   216  
   217          Then the parties should have the following profit and loss:
   218              | party  | volume | unrealised pnl | realised pnl |
   219              | party1 | 11     | -210           | 0            |
   220              | party2 | -10    | 200            | 0            |
   221              | party3 | -2     | 10             | 0            |
   222              | party0 | 1      | 0              | 0            |
   223  
   224          #MTM with price change from 9 to 8, party1 has long position of volume 11, price 9 ->8, MTM -1*11*10*1=-110; party2 has short position of volume 10, price 10 ->9, MTM 10*10*1=100;
   225          And the parties should have the following account balances:
   226              | party  | asset | market id | margin | general  | bond  |
   227              | party0 | ETH   | USD/DEC22 | 676438 | 4287994  | 35569 |
   228              | party1 | ETH   | USD/DEC22 | 1628   | 99998163 |       |
   229              | party2 | ETH   | USD/DEC22 | 5703   | 99994497 |       |
   230          # Margin_maintenance_party0 = max(1981*10*3.5569036*8,1206*10*0.801225765*8)=563699
   231          And the parties should have the following margin levels:
   232              | party  | market id | maintenance |
   233              | party0 | USD/DEC22 | 563699      |
   234              | party1 | USD/DEC22 | 1245        |
   235              | party2 | USD/DEC22 | 4753        |
   236  
   237      Scenario: Assure LP orders never trade on entry, even with spread of 1 tick and extremely small LP price range
   238          Given the parties deposit on asset's general account the following amount:
   239              | party  | asset | amount     |
   240              | party0 | ETH   | 1000000000 |
   241              | party1 | ETH   | 1000000000 |
   242              | party2 | ETH   | 10000      |
   243          And the parties submit the following liquidity provision:
   244              | id  | party  | market id | commitment amount | fee   | lp type    |
   245              | lp1 | party0 | USD/DEC23 | 40000000          | 0.001 | submission |
   246  
   247          And the parties place the following pegged iceberg orders:
   248              | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   249              | party0 | USD/DEC23 | 39        | 1                    | sell | MID              | 39     | 1      |
   250              | party0 | USD/DEC23 | 45        | 1                    | buy  | MID              | 45     | 1      |
   251          And the parties place the following orders:
   252              | party  | market id | side | volume | price | resulting trades | type       | tif     |
   253              | party1 | USD/DEC23 | buy  | 5      | 8     | 0                | TYPE_LIMIT | TIF_GTC |
   254              | party1 | USD/DEC23 | buy  | 1      | 9     | 0                | TYPE_LIMIT | TIF_GTC |
   255              | party1 | USD/DEC23 | buy  | 10     | 10    | 0                | TYPE_LIMIT | TIF_GTC |
   256              | party2 | USD/DEC23 | sell | 10     | 10    | 0                | TYPE_LIMIT | TIF_GTC |
   257              | party2 | USD/DEC23 | sell | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC |
   258              | party2 | USD/DEC23 | sell | 5      | 11    | 0                | TYPE_LIMIT | TIF_GTC |
   259  
   260          When the opening auction period ends for market "USD/DEC23"
   261          Then the market data for the market "USD/DEC23" should be:
   262              | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   263              | 10         | TRADING_MODE_CONTINUOUS | 360000  | 8         | 13        | 35569000     | 40000000       | 10            |
   264  
   265          Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "USD/DEC23"
   266  
   267          And the order book should have the following volumes for market "USD/DEC23":
   268              | side | price | volume |
   269              | sell | 11    | 5      |
   270              | sell | 10    | 40     |
   271              | buy  | 9     | 46     |
   272              | buy  | 8     | 5      |
   273  
   274          When the parties place the following orders with ticks:
   275              | party  | market id | side | volume | price | resulting trades | type       | tif     |
   276              | party3 | USD/DEC23 | sell | 1      | 9     | 1                | TYPE_LIMIT | TIF_GTC |
   277          Then the order book should have the following volumes for market "USD/DEC23":
   278              | side | price | volume |
   279              | sell | 11    | 5      |
   280              | sell | 10    | 40     |
   281              | buy  | 9     | 0      |
   282              | buy  | 8     | 50     |
   283  
   284          When the parties place the following orders with ticks:
   285              | party  | market id | side | volume | price | resulting trades | type       | tif     |
   286              | party3 | USD/DEC23 | buy  | 1      | 10    | 1                | TYPE_LIMIT | TIF_GTC |
   287          Then the order book should have the following volumes for market "USD/DEC23":
   288              | side | price | volume |
   289              | sell | 11    | 5      |
   290              | sell | 10    | 39     |
   291              | buy  | 8     | 5      |
   292          And the market data for the market "USD/DEC23" should be:
   293              | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   294              | 10         | TRADING_MODE_CONTINUOUS | 360000  | 8         | 13        | 39125900     | 40000000       | 11            |