code.vegaprotocol.io/vega@v0.79.0/core/integration/features/parties-margin-with-0-pos-cleared-on-cancel.feature (about)

     1  Feature: Close potential positions
     2  
     3    Scenario: Cancel all order from party with only potential position release all margins
     4    Background:
     5  
     6      Given the log normal risk model named "lognormal-risk-model-fish":
     7        | risk aversion | tau  | mu | r   | sigma |
     8        | 0.001         | 0.01 | 0  | 0.0 | 1.2   |
     9      #calculated risk factor long: 0.336895684; risk factor short: 0.4878731
    10  
    11      And the price monitoring named "price-monitoring-1":
    12        | horizon | probability | auction extension |
    13        | 1       | 0.99999999  | 300               |
    14  
    15      And the margin calculator named "margin-calculator-1":
    16        | search factor | initial factor | release factor |
    17        | 1.2           | 1.5            | 2              |
    18  
    19      And the markets:
    20        | id        | quote name | asset | risk model                | margin calculator   | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    21        | ETH/DEC19 | ETH        | USD   | lognormal-risk-model-fish | margin-calculator-1 | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
    22  
    23      And the following network parameters are set:
    24        | name                                    | value |
    25        | market.auction.minimumDuration          | 1     |
    26        | network.markPriceUpdateMaximumFrequency | 0s    |
    27  
    28      Given the parties deposit on asset's general account the following amount:
    29        | party            | asset | amount     |
    30        | sellSideProvider | USD   | 1000000000 |
    31        | buySideProvider  | USD   | 1000000000 |
    32        | party1           | USD   | 30000      |
    33        | party2           | USD   | 50000000   |
    34        | party3           | USD   | 30000      |
    35        | aux1             | USD   | 1000000000 |
    36        | aux2             | USD   | 1000000000 |
    37        | lpprov           | USD   | 1000000000 |
    38  
    39      When the parties submit the following liquidity provision:
    40        | id  | party  | market id | commitment amount | fee | lp type    |
    41        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
    42        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
    43      #And the cumulated balance for all accounts should be worth "4050075000"
    44      # setup order book
    45      When the parties place the following orders:
    46        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    47        | sellSideProvider | ETH/DEC19 | sell | 1000   | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    48        | aux1             | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-2         |
    49        | aux2             | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-2         |
    50        | party2           | ETH/DEC19 | buy  | 100    | 80    | 0                | TYPE_LIMIT | TIF_GTC | party2-b-1      |
    51        | buySideProvider  | ETH/DEC19 | buy  | 1000   | 70    | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    52  
    53      Then the opening auction period ends for market "ETH/DEC19"
    54      And the mark price should be "100" for the market "ETH/DEC19"
    55      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    56  
    57      # party1 maintenance margin: position*(mark_price*risk_factor_short+slippage_per_unit) + OrderVolume x Order_price x risk_factor_short  = 100 x 100 x 0.4878731  is about 4879
    58  
    59      When the parties place the following orders with ticks:
    60        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference  |
    61        | party1 | ETH/DEC19 | sell | 100    | 120   | 0                | TYPE_LIMIT | TIF_GTC | party1-s-1 |
    62  
    63      # party1 margin account: MarginInitialFactor x MaintenanceMarginLevel = 4879*1.5
    64      Then the parties should have the following account balances:
    65        | party  | asset | market id | margin | general |
    66        | party1 | USD   | ETH/DEC19 | 7318   | 22682   |
    67  
    68      # party1 maintenance margin level: position*(mark_price*risk_factor_short+slippage_per_unit) + OrderVolume x Mark_price x risk_factor_short  = 100 x 100 x 0.4878731  is about 4879
    69      Then the parties should have the following margin levels:
    70        | party  | market id | maintenance | search | initial | release |
    71        | party1 | ETH/DEC19 | 4879        | 5854   | 7318    | 9758    |
    72  
    73      # party1 place more order volume 300
    74      When the parties place the following orders with ticks:
    75        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference  |
    76        | party1 | ETH/DEC19 | sell | 300    | 120   | 0                | TYPE_LIMIT | TIF_GTC | party1-s-2 |
    77  
    78      Then the parties should have the following account balances:
    79        | party  | asset | market id | margin | general |
    80        | party1 | USD   | ETH/DEC19 | 29272  | 728     |
    81  
    82      Then the parties should have the following margin levels:
    83        | party  | market id | maintenance | search | initial | release |
    84        | party1 | ETH/DEC19 | 19515       | 23418  | 29272   | 39030   |
    85  
    86      And the order book should have the following volumes for market "ETH/DEC19":
    87        | side | price | volume |
    88        | sell | 150   | 1000   |
    89        | sell | 120   | 400    |
    90        | buy  | 80    | 100    |
    91        | buy  | 70    | 1000   |
    92  
    93      And the mark price should be "100" for the market "ETH/DEC19"
    94      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    95  
    96      When the parties place the following orders with ticks:
    97        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    98        | aux1  | ETH/DEC19 | sell | 1      | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    99        | aux2  | ETH/DEC19 | buy  | 1      | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-5     |
   100  
   101      Then the parties should have the following margin levels:
   102        | party  | market id | maintenance | search | initial | release |
   103        | party1 | ETH/DEC19 | 21467       | 25760  | 32200   | 42934   |
   104  
   105      Then the parties should have the following account balances:
   106        | party  | asset | market id | margin | general |
   107        | party1 | USD   | ETH/DEC19 | 29272  | 728     |
   108  
   109      ### At this point party1 have not traded and should have a position of 0
   110      Then the parties should have the following profit and loss:
   111        | party  | volume | unrealised pnl | realised pnl |
   112        | party1 | 0      | 0              | 0            |
   113  
   114      And the mark price should be "110" for the market "ETH/DEC19"
   115      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   116  
   117      ### Now we cancel the party1 orders
   118      Then the parties cancel the following orders:
   119        | party  | reference  |
   120        | party1 | party1-s-1 |
   121  
   122      ### balances are reduced (not)
   123      Then the parties should have the following account balances:
   124        | party  | asset | market id | margin | general |
   125        | party1 | USD   | ETH/DEC19 | 29272  | 728     |
   126  
   127      Then the parties should have the following margin levels:
   128        | party  | market id | maintenance | search | initial | release |
   129        | party1 | ETH/DEC19 | 21467       | 25760  | 32200   | 42934   |
   130  
   131      ### cancel the last order
   132      Then the parties cancel the following orders:
   133        | party  | reference  |
   134        | party1 | party1-s-2 |
   135  
   136      And the network moves ahead "1" blocks
   137  
   138      ### balance are 0 out
   139      Then the parties should have the following account balances:
   140        | party  | asset | market id | margin | general |
   141        | party1 | USD   | ETH/DEC19 | 0      | 30000   |
   142  
   143      ### Margin levels are now zero, all margin was released
   144      Then the parties should have the following margin levels:
   145        | party  | market id | maintenance | search | initial | release |
   146        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       |
   147  
   148      ### then we place new orders and get a trade
   149      When the parties place the following orders with ticks:
   150        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   151        | aux1  | ETH/DEC19 | sell | 1      | 130   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   152        | aux2  | ETH/DEC19 | buy  | 1      | 130   | 1                | TYPE_LIMIT | TIF_GTC | ref-5     |
   153  
   154      ### balance are still 0
   155      Then the parties should have the following account balances:
   156        | party  | asset | market id | margin | general |
   157        | party1 | USD   | ETH/DEC19 | 0      | 30000   |