code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/margin-for-pegged-orders.feature (about)

     1  Feature: Test pegged order amend under isolated margin mode
     2      Background:
     3          Given the following network parameters are set:
     4              | name                                    | value |
     5              | network.markPriceUpdateMaximumFrequency | 0s    |
     6              | limits.markets.maxPeggedOrders          | 6     |
     7          And the liquidity monitoring parameters:
     8              | name       | triggering ratio | time window | scaling factor |
     9              | lqm-params | 0.00             | 24h         | 1e-9           |
    10          And the simple risk model named "simple-risk-model":
    11              | long | short | max move up | min move down | probability of trading |
    12              | 0.1  | 0.1   | 100         | -100          | 0.2                    |
    13          And the markets:
    14              | id        | quote name | asset | liquidity monitoring | risk model        | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    15              | ETH/FEB23 | ETH        | USD   | lqm-params           | simple-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
    16          And the parties deposit on asset's general account the following amount:
    17              | party       | asset | amount       |
    18              | lpprov      | USD   | 100000000000 |
    19              | aux_buys    | USD   | 100000000000 |
    20              | aux_sells   | USD   | 100000000000 |
    21              | test_party  | USD   | 100000       |
    22              | test_party2 | USD   | 100000       |
    23  
    24          When the parties place the following orders:
    25              | party     | market id | side | volume | price | resulting trades | type       | tif     | reference |
    26              | aux_buys  | ETH/FEB23 | buy  | 10     | 995   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    27              | aux_buys  | ETH/FEB23 | buy  | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    28              | aux_sells | ETH/FEB23 | sell | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    29              | aux_sells | ETH/FEB23 | sell | 10     | 1005  | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    30              | lpprov    | ETH/FEB23 | buy  | 10     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    31              | lpprov    | ETH/FEB23 | sell | 10     | 10000 | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    32          And the parties submit the following liquidity provision:
    33              | id  | party  | market id | commitment amount | fee | lp type    |
    34              | lp1 | lpprov | ETH/FEB23 | 900000            | 0.1 | submission |
    35              | lp1 | lpprov | ETH/FEB23 | 900000            | 0.1 | submission |
    36  
    37          Then the opening auction period ends for market "ETH/FEB23"
    38          And the mark price should be "1000" for the market "ETH/FEB23"
    39          And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/FEB23"
    40  
    41      Scenario: Party cannot enter a pegged order when in isolated margin mode (0019-MCAL-049)
    42          # pegged order
    43          Given the parties submit update margin mode:
    44              | party      | market    | margin_mode     | margin_factor | error |
    45              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
    46          When the parties place the following pegged orders:
    47              | party      | market id | side | volume | pegged reference | offset | reference | error                                                         |
    48              | test_party | ETH/FEB23 | sell | 10     | ASK              | 9      | sell_peg  | OrderError: pegged orders not allowed in isolated margin mode |
    49              | test_party | ETH/FEB23 | buy  | 5      | BID              | 9      | buy_peg   | OrderError: pegged orders not allowed in isolated margin mode |
    50          Then the parties should have the following margin levels:
    51              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    52              | test_party | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.91          | 0     |
    53          And the parties should have the following account balances:
    54              | party      | asset | market id | margin | general | order margin |
    55              | test_party | USD   | ETH/FEB23 | 0      | 100000  | 0            |
    56  
    57      Scenario: Party cannot enter a pegged order when in isolated margin mode (0019-MCAL-052)
    58          # pegged iceberg order
    59          Given the parties submit update margin mode:
    60              | party      | market    | margin_mode     | margin_factor | error |
    61              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
    62          When the parties place the following pegged iceberg orders:
    63              | party      | market id | peak size | minimum visible size | side | reference    | pegged reference | volume | offset | error                                                         |
    64              | test_party | ETH/FEB23 | 100       | 10                   | buy  | buy_ice_peg  | BID              | 100    | 9      | OrderError: pegged orders not allowed in isolated margin mode |
    65              | test_party | ETH/FEB23 | 100       | 10                   | sell | sell_ice_peg | ASK              | 100    | 9      | OrderError: pegged orders not allowed in isolated margin mode |
    66          Then the parties should have the following margin levels:
    67              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    68              | test_party | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.91          | 0     |
    69          And the parties should have the following account balances:
    70              | party      | asset | market id | margin | general | order margin |
    71              | test_party | USD   | ETH/FEB23 | 0      | 100000  | 0            |
    72  
    73      Scenario: When the party has a pegged order in cross margin mode switches to isolated margin mode the pegged order is cancelled (0019-MCAL-050)
    74          # pegged order
    75          Given the parties submit update margin mode:
    76              | party      | market    | margin_mode  | margin_factor | error |
    77              | test_party | ETH/FEB23 | cross margin |               |       |
    78          When the parties place the following pegged orders:
    79              | party      | market id | side | volume | pegged reference | offset | reference |
    80              | test_party | ETH/FEB23 | buy  | 5      | BID              | 9      | buy_peg   |
    81              | test_party | ETH/FEB23 | sell | 10     | ASK              | 9      | sell_peg  |
    82  
    83          Then the parties should have the following margin levels:
    84              | party      | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
    85              | test_party | ETH/FEB23 | 1000        | 1100   | 1200    | 1400    | cross margin |               |       |
    86  
    87          Given the parties should have the following account balances:
    88              | party      | asset | market id | margin | general |
    89              | test_party | USD   | ETH/FEB23 | 1200   | 98800   |
    90          When the parties submit update margin mode:
    91              | party      | market    | margin_mode     | margin_factor | error |
    92              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
    93          Then the orders should have the following status:
    94              | party      | reference | status           |
    95              | test_party | buy_peg   | STATUS_CANCELLED |
    96              | test_party | sell_peg  | STATUS_CANCELLED |
    97          And the parties should have the following margin levels:
    98              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    99              | test_party | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.91          | 0     |
   100          And the parties should have the following account balances:
   101              | party      | asset | market id | margin | general | order margin |
   102              | test_party | USD   | ETH/FEB23 | 0      | 100000  | 0            |
   103  
   104      Scenario: When the party has a pegged order in cross margin mode switches to isolated margin mode the pegged order is cancelled (0019-MCAL-051)
   105          # pegged iceberg
   106          Given the parties submit update margin mode:
   107              | party      | market    | margin_mode  | margin_factor | error |
   108              | test_party | ETH/FEB23 | cross margin |               |       |
   109          When the parties place the following pegged iceberg orders:
   110              | party      | market id | peak size | minimum visible size | side | reference    | pegged reference | volume | offset |
   111              | test_party | ETH/FEB23 | 100       | 10                   | buy  | buy_ice_peg  | BID              | 100    | 9      |
   112              | test_party | ETH/FEB23 | 100       | 10                   | sell | sell_ice_peg | ASK              | 100    | 9      |
   113          Then the parties should have the following margin levels:
   114              | party      | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   115              | test_party | ETH/FEB23 | 10000       | 11000  | 12000   | 14000   | cross margin |               | 0     |
   116  
   117          Given the parties should have the following account balances:
   118              | party      | asset | market id | margin | general |
   119              | test_party | USD   | ETH/FEB23 | 12000  | 88000   |
   120          When the parties submit update margin mode:
   121              | party      | market    | margin_mode     | margin_factor | error |
   122              | test_party | ETH/FEB23 | isolated margin | 0.5           |       |
   123          Then the orders should have the following status:
   124              | party      | reference    | status           |
   125              | test_party | buy_ice_peg  | STATUS_CANCELLED |
   126              | test_party | sell_ice_peg | STATUS_CANCELLED |
   127          And the parties should have the following margin levels:
   128              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   129              | test_party | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.5           | 0     |
   130          And the parties should have the following account balances:
   131              | party      | asset | market id | margin | general | order margin |
   132              | test_party | USD   | ETH/FEB23 | 0      | 100000  | 0            |
   133  
   134      Scenario: When in cross margin mode and multiple parties enter multiple types of orders, when one party switches to isolated margin mode only their pegged orders are cancelled. (0019-MCAL-057)
   135          # pegged order
   136          Given the parties submit update margin mode:
   137              | party       | market    | margin_mode  | margin_factor | error |
   138              | test_party  | ETH/FEB23 | cross margin |               |       |
   139              | test_party2 | ETH/FEB23 | cross margin |               |       |
   140          When the parties place the following pegged orders:
   141              | party       | market id | side | volume | pegged reference | offset | reference |
   142              | test_party  | ETH/FEB23 | buy  | 5      | BID              | 1      | buy_peg   |
   143              | test_party  | ETH/FEB23 | sell | 5      | ASK              | 1      | sell_peg  |
   144              | test_party2 | ETH/FEB23 | buy  | 5      | BID              | 1      | buy_peg2  |
   145              | test_party2 | ETH/FEB23 | sell | 5      | MID              | 1      | sell_peg2 |
   146          And the parties place the following pegged iceberg orders:
   147              | party      | market id | peak size | minimum visible size | side | reference    | pegged reference | volume | offset |
   148              | test_party | ETH/FEB23 | 10        | 5                    | buy  | buy_ice_peg  | BID              | 10     | 9      |
   149              | test_party | ETH/FEB23 | 10        | 5                    | sell | sell_ice_peg | ASK              | 10     | 9      |
   150          And the parties place the following orders:
   151              | party       | market id | side | volume | price | resulting trades | type       | tif     | reference |
   152              | test_party  | ETH/FEB23 | buy  | 10     | 995   | 0                | TYPE_LIMIT | TIF_GTC | buy_lim   |
   153              | test_party2 | ETH/FEB23 | buy  | 10     | 996   | 0                | TYPE_LIMIT | TIF_GTC | buy_lim2  |
   154              | test_party  | ETH/FEB23 | sell | 10     | 1005  | 0                | TYPE_LIMIT | TIF_GTC | sell_lim  |
   155              | test_party2 | ETH/FEB23 | sell | 10     | 1006  | 0                | TYPE_LIMIT | TIF_GTC | sell_lim2 |
   156          Then the parties should have the following margin levels:
   157              | party       | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   158              | test_party  | ETH/FEB23 | 2500        | 2750   | 3000    | 3500    | cross margin |               | 0     |
   159              | test_party2 | ETH/FEB23 | 1500        | 1650   | 1800    | 2100    | cross margin |               | 0     |
   160  
   161          Given the parties should have the following account balances:
   162              | party       | asset | market id | margin | general |
   163              | test_party  | USD   | ETH/FEB23 | 3000   | 97000   |
   164              | test_party2 | USD   | ETH/FEB23 | 1800   | 98200   |
   165          When the parties submit update margin mode:
   166              | party      | market    | margin_mode     | margin_factor | error |
   167              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
   168          Then the orders should have the following status:
   169              | party       | reference | status           |
   170              | test_party  | buy_peg   | STATUS_CANCELLED |
   171              | test_party  | sell_peg  | STATUS_CANCELLED |
   172              | test_party  | buy_lim   | STATUS_ACTIVE    |
   173              | test_party  | sell_lim  | STATUS_ACTIVE    |
   174              | test_party2 | buy_peg2  | STATUS_ACTIVE    |
   175              | test_party2 | sell_peg2 | STATUS_ACTIVE    |
   176              | test_party2 | buy_lim2  | STATUS_ACTIVE    |
   177              | test_party2 | sell_lim2 | STATUS_ACTIVE    |
   178          And the parties should have the following margin levels:
   179              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   180              | test_party | ETH/FEB23 | 0           | 0      | 0       | 0       | isolated margin | 0.91          | 9145  |
   181          And the parties should have the following account balances:
   182              | party      | asset | market id | margin | general | order margin |
   183              | test_party | USD   | ETH/FEB23 | 0      | 90855   | 9145         |
   184  
   185      Scenario: A party in cross maring mode has a partially filled pegged order, when the party switches to isolated margin mode the pegged order is cancelled (0019-MCAL-075)
   186          Given the parties submit update margin mode:
   187              | party      | market    | margin_mode  | margin_factor | error |
   188              | test_party | ETH/FEB23 | cross margin |               |       |
   189          When the parties place the following pegged orders:
   190              | party      | market id | side | volume | pegged reference | offset | reference |
   191              | test_party | ETH/FEB23 | sell | 20     | ASK              | -5     | sell_peg  |
   192          And the parties place the following orders:
   193              | party    | market id | side | volume | price | resulting trades | type       | tif     | reference   |
   194              | aux_buys | ETH/FEB23 | buy  | 10     | 1000  | 1                | TYPE_LIMIT | TIF_GTC | auc-trade-1 |
   195  
   196          Then the parties should have the following margin levels:
   197              | party      | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   198              | test_party | ETH/FEB23 | 2000        | 2200   | 2400    | 2800    | cross margin |               | 0     |
   199  
   200          And the average fill price is:
   201              | market     | volume | side | ref price | mark price | equivalent linear slippage factor |
   202              | ETH/FEB23  | 20     | sell | 1000      | 1000       | 0.002                             |
   203          # update linear slippage factor in line with what book-based slippage used to be
   204          And the markets are updated:
   205              | id          | linear slippage factor |
   206              | ETH/FEB23   | 0.002                  |
   207  
   208          Given the parties should have the following account balances:
   209              | party      | asset | market id | margin | general |
   210              | test_party | USD   | ETH/FEB23 | 2400   | 97600   |
   211          When the parties submit update margin mode:
   212              | party      | market    | margin_mode     | margin_factor | error |
   213              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
   214          Then the orders should have the following status:
   215              | party      | reference | status           |
   216              | test_party | sell_peg  | STATUS_CANCELLED |
   217          And the parties should have the following margin levels:
   218              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   219              | test_party | ETH/FEB23 | 1020        | 0      | 1224    | 0       | isolated margin | 0.91          | 0     |
   220          
   221          And the parties should have the following account balances:
   222              | party      | asset | market id | margin | general | order margin |
   223              | test_party | USD   | ETH/FEB23 | 9100   | 90900   | 0            |
   224  
   225      Scenario: A party in cross maring mode has a partially filled pegged order, when the party switches to isolated margin mode the pegged order is cancelled (0019-MCAL-078)
   226          # iceberg pegged
   227          Given the parties submit update margin mode:
   228              | party      | market    | margin_mode  | margin_factor | error |
   229              | test_party | ETH/FEB23 | cross margin |               |       |
   230          When the parties place the following pegged iceberg orders:
   231              | party      | market id | peak size | minimum visible size | side | reference    | pegged reference | volume | offset |
   232              | test_party | ETH/FEB23 | 20        | 10                   | sell | sell_ice_peg | ASK              | 20     | -5     |
   233          And the parties place the following orders:
   234              | party    | market id | side | volume | price | resulting trades | type       | tif     | reference   |
   235              | aux_buys | ETH/FEB23 | buy  | 10     | 1000  | 1                | TYPE_LIMIT | TIF_GTC | auc-trade-1 |
   236  
   237          Then the parties should have the following margin levels:
   238              | party      | market id | maintenance | search | initial | release | margin mode  | margin factor | order |
   239              | test_party | ETH/FEB23 | 2000        | 2200   | 2400    | 2800    | cross margin |               | 0     |
   240  
   241          Given the parties should have the following account balances:
   242              | party      | asset | market id | margin | general |
   243              | test_party | USD   | ETH/FEB23 | 2400   | 97600   |
   244          When the parties submit update margin mode:
   245              | party      | market    | margin_mode     | margin_factor | error |
   246              | test_party | ETH/FEB23 | isolated margin | 0.91          |       |
   247          Then the orders should have the following status:
   248              | party      | reference    | status           |
   249              | test_party | sell_ice_peg | STATUS_CANCELLED |
   250          And the parties should have the following margin levels:
   251              | party      | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   252              | test_party | ETH/FEB23 | 3500        | 0      | 4200    | 0       | isolated margin | 0.91          | 0     |
   253          And the parties should have the following account balances:
   254              | party      | asset | market id | margin | general | order margin |
   255              | test_party | USD   | ETH/FEB23 | 9100   | 90900   | 0            |