code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-172.feature (about)

     1  Feature: when party holds both orders and positions, amend order so order is filled\partially filled while party does have enough collateral to cover
     2    Background:
     3      # Set liquidity parameters to allow "zero" target-stake which is needed to construct the order-book defined in the ACs
     4      Given the following network parameters are set:
     5        | name                                    | value |
     6        | network.markPriceUpdateMaximumFrequency | 1s    |
     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.000125               | 0                         | default-futures |
    16  
    17    Scenario: 001 party and party1 both orders and positions
    18      Given the parties deposit on asset's general account the following amount:
    19        | party            | asset | amount       |
    20        | buySideProvider  | USD   | 100000000000 |
    21        | sellSideProvider | USD   | 100000000000 |
    22        | party            | USD   | 12644000     |
    23        | party1           | USD   | 12644000     |
    24      And the parties place the following orders:
    25        | party            | market id | side | volume | price  | resulting trades | type       | tif     | reference   |
    26        | buySideProvider  | ETH/FEB23 | buy  | 10     | 14900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    27        | buySideProvider  | ETH/FEB23 | buy  | 2      | 15300  | 0                | TYPE_LIMIT | TIF_GTC |             |
    28        | buySideProvider  | ETH/FEB23 | buy  | 5      | 15500  | 0                | TYPE_LIMIT | TIF_GTC |             |
    29        | buySideProvider  | ETH/FEB23 | buy  | 6      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    30        | party            | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    31        | party1           | ETH/FEB23 | sell | 3      | 15900  | 0                | TYPE_LIMIT | TIF_GTC |             |
    32        | party            | ETH/FEB23 | sell | 5      | 16900  | 0                | TYPE_LIMIT | TIF_GTC | party-sell  |
    33        | party1           | ETH/FEB23 | sell | 5      | 16900  | 0                | TYPE_LIMIT | TIF_GTC | party1-sell |
    34        | sellSideProvider | ETH/FEB23 | sell | 1      | 100000 | 0                | TYPE_LIMIT | TIF_GTC |             |
    35        | sellSideProvider | ETH/FEB23 | sell | 10     | 100100 | 0                | TYPE_LIMIT | TIF_GTC |             |
    36      # update linear slippage factor more in line with what book-based slippage used to be
    37      And the markets are updated:
    38        | id          | linear slippage factor |
    39        | ETH/FEB23   | 0.0628930817610063     |
    40      When the network moves ahead "2" blocks
    41      Then the mark price should be "15900" for the market "ETH/FEB23"
    42  
    43          And the order book should have the following volumes for market "ETH/FEB23":
    44        | side | price | volume |
    45        | sell | 15900 | 0      |
    46        | sell | 16900 | 10     |
    47      And the parties submit update margin mode:
    48        | party  | market    | margin_mode     | margin_factor | error |
    49        | party  | ETH/FEB23 | isolated margin | 0.2           |       |
    50        | party1 | ETH/FEB23 | isolated margin | 0.2           |       |
    51      And the average fill price is:
    52        | market     | volume | side | ref price | mark price | equivalent linear slippage factor |
    53        | ETH/FEB23  | 5      | sell | 15900      | 15900     | 0.0628930817610063                |
    54  
    55      And the parties should have the following margin levels:
    56        | party  | market id | maintenance | margin mode     | margin factor | order |
    57        | party  | ETH/FEB23 | 7771        | isolated margin | 0.2           | 16900 |
    58        | party1 | ETH/FEB23 | 7771        | isolated margin | 0.2           | 16900 |
    59  
    60      Then the parties should have the following account balances:
    61        | party  | asset | market id | margin | general  | order margin |
    62        | party  | USD   | ETH/FEB23 | 9540   | 12617560 | 16900        |
    63        | party1 | USD   | ETH/FEB23 | 9540   | 12617560 | 16900        |
    64  
    65      #add additional order to reduce exit_price, hence slippage
    66      And the parties place the following orders:
    67        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    68        | sellSideProvider | ETH/FEB23 | sell | 10     | 16000 | 0                | TYPE_LIMIT | TIF_GTC | s-liq     |
    69  
    70      #AC: 0019-MCAL-172, 0019-MCAL-173, amend order price so order get filled/partially filled
    71      When the parties amend the following orders:
    72        | party  | reference   | price | size delta | tif     | error |
    73        | party  | party-sell  | 15500 | 0          | TIF_GTC |       |
    74        | party1 | party1-sell | 15300 | 0          | TIF_GTC |       |
    75  
    76      And the orders should have the following status:
    77        | party  | reference   | status        |
    78        | party  | party-sell  | STATUS_FILLED |
    79        | party1 | party1-sell | STATUS_ACTIVE |
    80  
    81      And the markets are updated:
    82        | id          | linear slippage factor |
    83        | ETH/FEB23   | 0.05                   |
    84     
    85      When the network moves ahead "2" blocks
    86  
    87      And the parties should have the following margin levels:
    88        | party  | market id | maintenance | margin mode     | margin factor | order |
    89        | party  | ETH/FEB23 | 18360       | isolated margin | 0.2           | 0     |
    90        | party1 | ETH/FEB23 | 11475       | isolated margin | 0.2           | 9180  |
    91  
    92      And the markets are updated:
    93        | id          | linear slippage factor |
    94        | ETH/FEB23   | 0.35                   |
    95  
    96      And the parties place the following orders:
    97        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference    |
    98        | buySideProvider | ETH/FEB23 | buy  | 5      | 15300 | 1                | TYPE_LIMIT | TIF_GTC |              |
    99        | buySideProvider | ETH/FEB23 | buy  | 5      | 15500 | 0                | TYPE_LIMIT | TIF_GTC |              |
   100        | party           | ETH/FEB23 | sell | 5      | 16900 | 0                | TYPE_LIMIT | TIF_GTC | party-sell2  |
   101        | party1          | ETH/FEB23 | sell | 3      | 16900 | 0                | TYPE_LIMIT | TIF_GTC | party1-sell2 |
   102  
   103      And the parties should have the following margin levels:
   104        | party  | market id | maintenance | margin mode     | margin factor | order |
   105        | party  | ETH/FEB23 | 55080       | isolated margin | 0.2           | 16900 |
   106        | party1 | ETH/FEB23 | 55080       | isolated margin | 0.2           | 10140 |
   107  
   108      And the order book should have the following volumes for market "ETH/FEB23":
   109        | side | price | volume |
   110        | sell | 15900 | 0      |
   111        | sell | 16900 | 8      |
   112  
   113      #AC: 0019-MCAL-174, 0019-MCAL-175, amend order price so order get filled/partially filled
   114      #however, after trade, their margin balance will be less than the margin maintenance level, so order will be stopped 
   115      When the parties amend the following orders:
   116        | party  | reference    | price | size delta | tif     | error               |
   117        | party  | party-sell2  | 15500 | 0          | TIF_GTC | margin check failed |
   118        | party1 | party1-sell2 | 15300 | 0          | TIF_GTC | margin check failed |
   119  
   120      And the orders should have the following status:
   121        | party  | reference    | status        |
   122        | party  | party-sell2  | STATUS_STOPPED |
   123        | party1 | party1-sell2 | STATUS_STOPPED |
   124  
   125  
   126  
   127  
   128