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

     1  Feature: Replicate a scenario from Lewis with Elias' implementation on Exit_price when there is insufficient orders, check the newly added slippage factor, linear and quadratic
     2    # Replicate a scenario from Lewis
     3    Background:
     4  
     5      Given the log normal risk model named "log-normal-risk-model-1":
     6        | risk aversion | tau | mu | r | sigma |
     7        | 0.000001      | 0.1 | 0  | 0 | 1.0   |
     8      #risk factor short = 3.5569036
     9      #risk factor long = 0.800728208
    10      And the price monitoring named "price-monitoring-1":
    11        | horizon  | probability | auction extension |
    12        | 72000000 | 0.99        | 3                 |
    13      And the margin calculator named "margin-calculator-1":
    14        | search factor | initial factor | release factor |
    15        | 1.5           | 2              | 3              |
    16      And the following assets are registered:
    17        | id  | decimal places |
    18        | USD | 3              |
    19      And the markets:
    20        | id        | quote name | asset | 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      |
    21        | ETH/DEC20 | ETH        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | price-monitoring-1 | default-eth-for-future | 3              | 0                       | 0.25                   | 0                         | default-futures |
    22        | ETH/DEC21 | ETH        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | price-monitoring-1 | default-eth-for-future | 3              | 0                       | 1e0                    | 1e2                       | default-futures |
    23        | ETH/DEC22 | ETH        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | price-monitoring-1 | default-eth-for-future | 3              | 0                       | 1e1                    | 1e3                       | default-futures |
    24        | ETH/DEC23 | ETH        | USD   | log-normal-risk-model-1 | margin-calculator-1 | 1                | default-none | price-monitoring-1 | default-eth-for-future | 3              | 0                       | 1e2                    | 1e0                       | default-futures |
    25      And the following network parameters are set:
    26        | name                                    | value |
    27        | market.auction.minimumDuration          | 1     |
    28        | network.markPriceUpdateMaximumFrequency | 0s    |
    29        | market.liquidity.stakeToCcyVolume       | 1     |
    30        | limits.markets.maxPeggedOrders          | 2     |
    31      And the average block duration is "1"
    32  
    33    @Liquidation
    34    Scenario: 001 Replicate a scenario from Lewis with Elias' implementation on Exit_price when there is insufficient orders, linear slippage factor = 1e6, quadratic slippage factor = 1e6, 0019-MCAL-001, 0019-MCAL-002
    35      # 1. trader B made LP commitment 150,000
    36      # 2. trader C and A cross at 0.5 with size of 111, and this opens continuous trading (trade B is short)
    37      # 3. trader C comes with an order with crazy price
    38      # 4. trader B’s margin has increased sharply because of the order (from step2),
    39      # 5. trader A and C and trigger MTM
    40      # 6. trader B got closeout out, and the closeout trade was between trader B - network - trader C
    41  
    42      Given the parties deposit on asset's general account the following amount:
    43        | party   | asset | amount         |
    44        | traderA | USD   | 10000000000000 |
    45        | traderB | USD | 3100000 |
    46        | traderC | USD   | 10000000000000 |
    47  
    48      When the parties submit the following liquidity provision:
    49        | id  | party   | market id | commitment amount | fee   | lp type    |
    50        | lp1 | traderB | ETH/DEC20 | 150000            | 0.001 | submission |
    51        | lp1 | traderB | ETH/DEC20 | 150000            | 0.001 | amendmend  |
    52  
    53      When the parties place the following orders with ticks:
    54        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    55        | traderB | ETH/DEC20 | sell | 75     | 2020  | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    56        | traderB | ETH/DEC20 | buy  | 5173   | 29    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    57  
    58      And the market data for the market "ETH/DEC20" should be:
    59        | trading mode                 | auction trigger         | target stake | supplied stake | open interest |
    60        | TRADING_MODE_OPENING_AUCTION | AUCTION_TRIGGER_OPENING | 0            | 150000         | 0             |
    61  
    62      And the parties should have the following account balances:
    63        | party   | asset | market id | margin  | general | bond   |
    64        | traderB | USD   | ETH/DEC20 | 1077742 | 1872258 | 150000 |
    65  
    66      Then the parties place the following orders:
    67        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference  |
    68        | traderA | ETH/DEC20 | buy  | 1      | 49    | 0                | TYPE_LIMIT | TIF_GTC | aux-b-5    |
    69        | traderB | ETH/DEC20 | sell | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1000 |
    70        | traderA | ETH/DEC20 | buy  | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1    |
    71        | traderC | ETH/DEC20 | sell | 2 | 2000 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1 |
    72        | traderB | ETH/DEC20 | sell | 1      | 3000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
    73  
    74      When the opening auction period ends for market "ETH/DEC20"
    75      And the market data for the market "ETH/DEC20" should be:
    76        | trading mode            | target stake | supplied stake | open interest |
    77        | TRADING_MODE_CONTINUOUS | 12449        | 150000         | 1             |
    78  
    79      And the parties should have the following account balances:
    80        | party   | asset | market id | margin  | general | bond   |
    81        | traderB | USD | ETH/DEC20 | 2899518 | 50482 | 150000 |
    82      Then the parties should have the following margin levels:
    83        | party   | market id | maintenance | search  | initial | release |
    84        | traderB | ETH/DEC20 | 1449759 | 2174638 | 2899518 | 4349277 |
    85      And the markets are updated:
    86        | id          | linear slippage factor |
    87        | ETH/DEC20   | 1e3                    |
    88      And the network moves ahead "1" blocks
    89  
    90  #margin for traderB: 1*(2000-350)+1*350*3.5569036+2*350*3.5569036=5385
    91      And the following trades should be executed:
    92        | buyer   | price | size | seller  |
    93        | traderA | 350   | 1    | traderB |
    94  
    95      And the insurance pool balance should be "0" for the market "ETH/DEC20"
    96  
    97      Then the order book should have the following volumes for market "ETH/DEC20":
    98        | side | price | volume |
    99        | buy  | 29    | 5173   |
   100        | buy  | 49    | 1      |
   101        | sell | 2000  | 2      |
   102        | sell | 2020  | 75     |
   103        | sell | 3000  | 1      |
   104  
   105      When the parties place the following orders with ticks:
   106        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   107        | traderA | ETH/DEC20 | buy  | 111    | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   108        | traderB | ETH/DEC20 | sell | 111    | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   109  
   110      Then the order book should have the following volumes for market "ETH/DEC20":
   111        | side | price | volume |
   112        | buy  | 49    | 1      |
   113        | sell | 2000  | 0      |
   114  
   115  # traderB has both LP pegged orders, limit order, and positions
   116  # margin for pegged orders long: 5173*0.801225765*50=207237.0441
   117  # margin for pegged+limit orders short:76*3.5569036*50=13516.23368
   118  # margin for short positions: min(112*9000000000000000, 50*(112*1e6+112^2*1e6))+112*50*3.55690359157934000 = 632,800,019,918.66
   119  # margin_long = 207237.0441
   120  # margin_short= 632,800,019,918.66
   121  
   122      And the parties should have the following account balances:
   123        | party   | asset | market id | margin | general | bond |
   124        | traderB | USD   | ETH/DEC20 | 0      | 0       | 0    |
   125      Then the network moves ahead "1" blocks
   126  
   127      Then the parties should have the following margin levels:
   128        | party   | market id | maintenance | search | initial | release |
   129        | traderB | ETH/DEC20 | 0           | 0      | 0       | 0       |
   130  
   131      And the market data for the market "ETH/DEC20" should be:
   132        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   133        | 50         | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 199186       | 150000         | 112           |
   134  
   135      And the insurance pool balance should be "3096390" for the market "ETH/DEC20"
   136  
   137    @SLABug @Liquidation
   138    Scenario: 002 Replicate a scenario from Lewis, linear slippage factor = 1e0, quadratic slippage factor = 1e2
   139      Given the parties deposit on asset's general account the following amount:
   140        | party   | asset | amount         |
   141        | traderA | USD   | 10000000000000 |
   142        | traderB | USD   | 3100000        |
   143        | traderC | USD   | 10000000000000 |
   144  
   145      When the parties submit the following liquidity provision:
   146        | id  | party   | market id | commitment amount | fee   | lp type    |
   147        | lp1 | traderB | ETH/DEC21 | 150000            | 0.001 | submission |
   148        | lp1 | traderB | ETH/DEC21 | 150000            | 0.001 | amendmend  |
   149  
   150      When the parties place the following orders with ticks:
   151        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   152        | traderB | ETH/DEC21 | sell | 74     | 2020  | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   153        | traderB | ETH/DEC21 | buy  | 5173   | 29    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   154  
   155      Then the parties place the following orders:
   156        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference  |
   157        | traderA | ETH/DEC21 | buy  | 1      | 49    | 0                | TYPE_LIMIT | TIF_GTC | aux-b-5    |
   158        | traderB | ETH/DEC21 | sell | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1000 |
   159        | traderA | ETH/DEC21 | buy  | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1    |
   160        | traderB | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   161        | traderB | ETH/DEC21 | sell | 1      | 3000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   162      When the opening auction period ends for market "ETH/DEC21"
   163  
   164      And the parties should have the following account balances:
   165        | party   | asset | market id | margin  | general | bond   |
   166        | traderB | USD   | ETH/DEC21 | 2899518 | 50482   | 150000 |
   167  
   168      And the following trades should be executed:
   169        | buyer   | price | size | seller  |
   170        | traderA | 350   | 1    | traderB |
   171  
   172      And the market data for the market "ETH/DEC21" should be:
   173        | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   174        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 12449        | 150000         | 1             |
   175  
   176      Then the order book should have the following volumes for market "ETH/DEC21":
   177        | side | price | volume |
   178        | buy  | 29    | 5173   |
   179        | buy  | 49    | 1      |
   180        | sell | 2000  | 1      |
   181        | sell | 2020  | 74     |
   182  
   183      When the parties place the following orders with ticks:
   184        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   185        | traderA | ETH/DEC21 | buy  | 111    | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   186        | traderB | ETH/DEC21 | sell | 111    | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   187  
   188      And the parties should have the following account balances:
   189        | party   | asset | market id | margin | general | bond |
   190        | traderB | USD   | ETH/DEC21 | 0      | 0       | 0    |
   191  
   192      And the market data for the market "ETH/DEC21" should be:
   193        | mark price | trading mode            | target stake | supplied stake | open interest |
   194        | 50         | TRADING_MODE_CONTINUOUS | 199186       | 150000         | 112           |
   195  
   196      # traderB has both LP pegged orders, limit order, and positions
   197      # margin for pegged orders long: 5173*0.801225765*50=207237.0441
   198      # margin for pegged+limit orders short:76*3.5569036*50=13516.23368
   199      # margin for short positions: min(112*9000000000000000, 50*(112*1e1+112^2*1e2))+112*50*3.55690359157934000 = 62745518.66
   200      # margin_long = 207237.0441
   201      # margin_short= 62745518.66
   202      And the parties should have the following account balances:
   203        | party   | asset | market id | margin    | general       |
   204        | traderA | USD   | ETH/DEC21 | 125460250 | 9999874539450 |
   205  
   206      Then the parties should have the following margin levels:
   207        | party   | market id | maintenance | search | initial | release |
   208        | traderB | ETH/DEC21 | 0           | 0      | 0       | 0       |
   209  
   210      And the market data for the market "ETH/DEC21" should be:
   211        | mark price | trading mode            | target stake | supplied stake | open interest |
   212        | 50         | TRADING_MODE_CONTINUOUS | 199186       | 150000         | 112           |
   213  #supplied stake is only updated with bond account at the end of epoch
   214  
   215      And the insurance pool balance should be "3100294" for the market "ETH/DEC21"
   216  
   217    @Liquidation
   218    Scenario: 003 Replicate a scenario from Lewis, linear slippage factor = 1e1, quadratic slippage factor = 1e3
   219      Given the parties deposit on asset's general account the following amount:
   220        | party   | asset | amount         |
   221        | traderA | USD   | 10000000000000 |
   222        | traderB | USD   | 3100000        |
   223        | traderC | USD   | 10000000000000 |
   224  
   225      When the parties submit the following liquidity provision:
   226        | id  | party   | market id | commitment amount | fee   | lp type    |
   227        | lp1 | traderB | ETH/DEC22 | 150000            | 0.001 | submission |
   228        | lp1 | traderB | ETH/DEC22 | 150000            | 0.001 | amendmend  |
   229      When the parties place the following orders with ticks:
   230        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   231        | traderB | ETH/DEC22 | sell | 74     | 2020  | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   232        | traderB | ETH/DEC22 | buy  | 5173   | 29    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   233  
   234      Then the parties place the following orders:
   235        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference  |
   236        | traderA | ETH/DEC22 | buy  | 1      | 49    | 0                | TYPE_LIMIT | TIF_GTC | aux-b-5    |
   237        | traderB | ETH/DEC22 | sell | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1000 |
   238        | traderA | ETH/DEC22 | buy  | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1    |
   239        | traderB | ETH/DEC22 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   240        | traderB | ETH/DEC22 | sell | 1      | 3000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   241      When the opening auction period ends for market "ETH/DEC22"
   242  
   243      And the parties should have the following account balances:
   244        | party   | asset | market id | margin  | general | bond   |
   245        | traderB | USD   | ETH/DEC22 | 2899518 | 50482   | 150000 |
   246  
   247      Then the parties should have the following margin levels:
   248        | party   | market id | maintenance | search  | initial | release |
   249        | traderB | ETH/DEC22 | 1449759     | 2174638 | 2899518 | 4349277 |
   250  
   251      And the following trades should be executed:
   252        | buyer   | price | size | seller  |
   253        | traderA | 350   | 1    | traderB |
   254  
   255      And the market data for the market "ETH/DEC22" should be:
   256        | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   257        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 12449        | 150000         | 1             |
   258  
   259      Then the order book should have the following volumes for market "ETH/DEC22":
   260        | side | price | volume |
   261        | buy  | 29    | 5173   |
   262        | buy  | 49    | 1      |
   263        | sell | 2000  | 1      |
   264        | sell | 2020  | 74     |
   265  
   266      When the parties place the following orders with ticks:
   267        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   268        | traderA | ETH/DEC22 | buy  | 111    | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   269        | traderB | ETH/DEC22 | sell | 111    | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   270  
   271  # traderB has both LP pegged orders, limit order, and positions
   272  # margin for pegged orders long: 5173*0.801225765*50=207237.0441
   273  # margin for pegged orders long and short: max(76*3.5569036,5173*0.800728208)*350=1449758.457
   274  # margin for short position: min(112*9000000000000000, 50*(112*1e1+112^2*1e3))+112*50*3.55690359157934000 =627275918.7
   275  
   276      And the parties should have the following account balances:
   277        | party   | asset | market id | margin | general | bond |
   278        | traderB | USD   | ETH/DEC22 | 0      | 0       | 0    |
   279  
   280      Then the parties should have the following margin levels:
   281        | party   | market id | maintenance | search | initial | release |
   282        | traderB | ETH/DEC22 | 0           | 0      | 0       | 0       |
   283  
   284      And the insurance pool balance should be "3100294" for the market "ETH/DEC22"
   285  
   286    Scenario: 004 Replicate a scenario from Lewis, linear slippage factor = 1e2, quadratic slippage factor = 1e0, 0019-MCAL-003
   287      Given the parties deposit on asset's general account the following amount:
   288        | party   | asset | amount         |
   289        | traderA | USD   | 10000000000000 |
   290        | traderB | USD   | 21700000       |
   291        | traderC | USD   | 10000000000000 |
   292        | traderD | USD   | 10000          |
   293        | traderE | USD   | 10000          |
   294      When the parties submit the following liquidity provision:
   295        | id  | party   | market id | commitment amount | fee   | lp type    |
   296        | lp1 | traderB | ETH/DEC23 | 150000            | 0.001 | submission |
   297        | lp1 | traderB | ETH/DEC23 | 150000            | 0.001 | amendmend  |
   298      When the parties place the following orders with ticks:
   299        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference       |
   300        | traderB | ETH/DEC23 | sell | 74     | 2020  | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
   301        | traderB | ETH/DEC23 | buy  | 5173   | 29    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
   302   
   303      Then the parties place the following orders:
   304        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference  |
   305        | traderA | ETH/DEC23 | buy  | 1      | 49    | 0                | TYPE_LIMIT | TIF_GTC | aux-b-5    |
   306        | traderB | ETH/DEC23 | sell | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1000 |
   307        | traderA | ETH/DEC23 | buy  | 1      | 350   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1    |
   308        | traderB | ETH/DEC23 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   309        | traderB | ETH/DEC23 | sell | 1      | 3000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1    |
   310      When the opening auction period ends for market "ETH/DEC23"
   311  
   312      Then the order book should have the following volumes for market "ETH/DEC23":
   313        | side | price | volume |
   314        | buy  | 29    | 5173   |
   315        | buy  | 49    | 1      |
   316        | sell | 2000  | 1      |
   317        | sell | 2020  | 74     |
   318        | sell | 3000  | 1      |
   319  
   320  # traderB has both LP pegged orders, limit order, and positions
   321  # margin for pegged orders long and short: max(76*3.5569036,5173*0.800728208)*350=1449758.457
   322  # margin for short position: min(1*(2000-350)*1/1, 350*(1*1e2+1^2*1e0))+1*350*3.55690359157934000 =2894.916257
   323  # margin for the long position/orders is larger than the short size, so we take the margin for long side which is 1449759
   324  
   325      And the parties should have the following account balances:
   326        | party   | asset | market id | margin  | general  | bond   |
   327        | traderB | USD   | ETH/DEC23 | 2899518 | 18650482 | 150000 |
   328  
   329      Then the parties should have the following margin levels:
   330        | party   | market id | maintenance | search  | initial | release |
   331        | traderB | ETH/DEC23 | 1449759     | 2174638 | 2899518 | 4349277 |
   332  
   333      And the following trades should be executed:
   334        | buyer   | price | size | seller  |
   335        | traderA | 350   | 1    | traderB |
   336  
   337      And the market data for the market "ETH/DEC23" should be:
   338        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   339        | 350        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 12449        | 150000         | 1             |
   340  
   341      Then the order book should have the following volumes for market "ETH/DEC23":
   342        | side | price | volume |
   343        | buy  | 29    | 5173   |
   344        | buy  | 49    | 1      |
   345        | sell | 2000  | 1      |
   346        | sell | 2020  | 74     |
   347        | sell | 3000  | 1      |
   348  
   349      When the parties place the following orders with ticks:
   350        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   351        | traderA | ETH/DEC23 | buy  | 111    | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   352        | traderB | ETH/DEC23 | sell | 111    | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   353  
   354  # traderB has both LP pegged orders, limit order, and positions
   355  # margin for pegged orders long: 5173*0.801225765*50=207237.0441
   356  # margin for pegged+limit orders short:76*3.5569036*50=13516.23368
   357  # margin for short positions: min(112*900000000000, 50*(112*1e2+112^2*1e0))+112*50*3.55690359157934000 =1207118.66
   358  # margin_long = 207237.0441
   359  # margin_short= 13516.23368+1207118.66=1220634.894
   360  
   361      And the parties should have the following account balances:
   362        | party   | asset | market id | margin   | general       |
   363        | traderA | USD   | ETH/DEC23 | 2383450  | 9999997616250 |
   364        | traderB | USD   | ETH/DEC23 | 2899818  | 18650476      |
   365  
   366      Then the parties should have the following margin levels:
   367        | party   | market id | maintenance | search  | initial | release |
   368        | traderB | ETH/DEC23 | 1220635     | 1830952 | 2441270 | 3661905 |
   369  
   370      Then the parties should have the following profit and loss:
   371        | party   | volume | unrealised pnl | realised pnl |
   372        | traderA | 112    | -300           | 0            |
   373        | traderB | -112   | 300            | 0            |
   374  
   375      And the market data for the market "ETH/DEC23" should be:
   376        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   377        | 50         | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 199186       | 150000         | 112           |
   378  
   379      When the parties place the following orders with ticks:
   380        | party   | market id | side | volume | price       | resulting trades | type       | tif     |
   381        | traderC | ETH/DEC23 | sell | 120    | 45000000000 | 0                | TYPE_LIMIT | TIF_GTC |
   382  
   383      Then the order book should have the following volumes for market "ETH/DEC23":
   384        | side | price       | volume |
   385        | buy  | 29          | 5173   |
   386        | buy  | 49          | 1      |
   387        | sell | 2000        | 1      |
   388        | sell | 2020        | 74     |
   389        | sell | 3000        | 1      |
   390        | sell | 45000000000 | 120    |
   391  
   392      Then the parties should have the following profit and loss:
   393        | party   | volume | unrealised pnl | realised pnl |
   394        | traderA | 112    | -300           | 0            |
   395        | traderB | -112   | 300            | 0            |
   396  
   397  # traderB has both LP pegged orders, limit order, and positions
   398  # margin for pegged orders long: 5173*0.801225765*50=207237.0441
   399  # margin for pegged orders short:76*3.5569036*50=13516.23368
   400  # margin for short positions: min(112*((2000-50)*1/112+(2020-50)*74/112+(3000-50)*1/112+(45000000000-50)*36/112), 50*(112*1e2+112^2*1e0))+112*50*3.55690359157934000 =1207118.66
   401  # margin_long = 207237.0441
   402  # margin_short= 13516.23368+1207118.66=1220634.894
   403  
   404      And the parties should have the following account balances:
   405        | party   | asset | market id | margin   | general       |
   406        | traderA | USD   | ETH/DEC23 | 2383450  | 9999997616250 |
   407        | traderB | USD   | ETH/DEC23 | 2899818  | 18650476      |
   408        | traderC | USD   | ETH/DEC23 | 42684    | 9999999957316 |
   409  
   410      Then the parties should have the following margin levels:
   411        | party   | market id | maintenance | search  | initial | release |
   412        | traderB | ETH/DEC23 | 1220635     | 1830952 | 2441270 | 3661905 |
   413  
   414      And the market data for the market "ETH/DEC23" should be:
   415        | mark price | trading mode            | auction trigger             | target stake | supplied stake | open interest |
   416        | 50         | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 199186       | 150000         | 112           |
   417  
   418      Then the parties should have the following profit and loss:
   419        | party   | volume | unrealised pnl | realised pnl |
   420        | traderA | 112    | -300           | 0            |
   421        | traderB | -112   | 300            | 0            |
   422  
   423      And the insurance pool balance should be "0" for the market "ETH/DEC23"
   424  
   425      When the parties place the following orders with ticks:
   426        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   427        | traderD | ETH/DEC23 | buy  | 1      | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   428        | traderE | ETH/DEC23 | sell | 1      | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   429  
   430      And the parties should have the following account balances:
   431        | party   | asset | market id | margin | general |
   432        | traderD | USD   | ETH/DEC23 | 10000  | 0       |
   433        | traderE | USD   | ETH/DEC23 | 9999   | 0       |
   434  
   435      When the parties place the following orders with ticks:
   436        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   437        | traderE | ETH/DEC23 | buy  | 1      | 50    | 0                | TYPE_LIMIT | TIF_GTC |
   438        | traderD | ETH/DEC23 | sell | 1      | 50    | 1                | TYPE_LIMIT | TIF_GTC |
   439  
   440      #for traderD and E, zero position and zero orders results in all zero margin levels
   441      And the parties should have the following account balances:
   442        | party   | asset | market id | margin | general |
   443        | traderD | USD   | ETH/DEC23 | 0      | 9999    |
   444        | traderE | USD   | ETH/DEC23 | 0      | 9999    |
   445  
   446      Then the parties should have the following profit and loss:
   447        | party   | volume | unrealised pnl | realised pnl |
   448        | traderD | 0      | 0              | 0            |
   449        | traderE | 0      | 0              | 0            |
   450  
   451  
   452  
   453  
   454  
   455