code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0019-MCAL-margin_calculator-verified_margins_case2.feature (about)

     1  Feature: CASE-2: Trader submits long order that will trade - new formula & low exit price (0019-MCAL-001, 0019-MCAL-002, 0019-MCAL-003)
     2  
     3    Background:
     4      Given the following network parameters are set:
     5        | name                                    | value |
     6        | network.markPriceUpdateMaximumFrequency | 0s    |
     7        | limits.markets.maxPeggedOrders          | 2     |
     8      And the markets:
     9        | id        | quote name | asset | risk model                | margin calculator                  | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    10        | ETH/DEC19 | ETH        | ETH   | default-simple-risk-model | default-overkill-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
    11      And the parties deposit on asset's general account the following amount:
    12        | party      | asset | amount     |
    13        | party1     | ETH   | 1000000000 |
    14        | sellSideMM | ETH   | 2000000000 |
    15        | buySideMM  | ETH   | 2000000000 |
    16        | aux        | ETH   | 1000000000 |
    17        | aux2       | ETH   | 1000000000 |
    18        | lpprov     | ETH   | 1000000000 |
    19  
    20      When the parties submit the following liquidity provision:
    21        | id  | party  | market id | commitment amount | fee | lp type    |
    22        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    23        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    24      And the parties place the following pegged iceberg orders:
    25        | party  | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    26        | lpprov | ETH/DEC19 | 500 | 1 | buy  | BID | 500 | 10 |
    27        | lpprov | ETH/DEC19 | 500 | 1 | sell | ASK | 500 | 10 |
    28      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    29      Then the parties place the following orders:
    30        | party | market id | side | volume | price    | resulting trades | type       | tif     |
    31        | aux   | ETH/DEC19 | buy  | 1      | 1        | 0                | TYPE_LIMIT | TIF_GTC |
    32        | aux   | ETH/DEC19 | sell | 1      | 20000000 | 0                | TYPE_LIMIT | TIF_GTC |
    33        | aux   | ETH/DEC19 | buy  | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC |
    34        | aux2  | ETH/DEC19 | sell | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC |
    35      Then the opening auction period ends for market "ETH/DEC19"
    36      And the mark price should be "10300000" for the market "ETH/DEC19"
    37      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    38  
    39      # setting mark price
    40      And the parties place the following orders:
    41        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    42        | sellSideMM | ETH/DEC19 | sell | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    43        | buySideMM  | ETH/DEC19 | buy  | 1      | 10300000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    44  
    45  
    46      # setting order book
    47      And the parties place the following orders:
    48        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    49        | sellSideMM | ETH/DEC19 | sell | 100    | 25000000 | 0                | TYPE_LIMIT | TIF_GTC | _sell1    |
    50        | sellSideMM | ETH/DEC19 | sell | 11     | 14000000 | 0                | TYPE_LIMIT | TIF_GTC | _sell2    |
    51        | sellSideMM | ETH/DEC19 | sell | 2      | 11200000 | 0                | TYPE_LIMIT | TIF_GTC | _sell3    |
    52        | buySideMM  | ETH/DEC19 | buy  | 1      | 10000000 | 0                | TYPE_LIMIT | TIF_GTC | buy1      |
    53        | buySideMM  | ETH/DEC19 | buy  | 3      | 9600000  | 0                | TYPE_LIMIT | TIF_GTC | buy2      |
    54        | buySideMM  | ETH/DEC19 | buy  | 15     | 8000000  | 0                | TYPE_LIMIT | TIF_GTC | _buy3     |
    55        | buySideMM  | ETH/DEC19 | buy  | 50     | 7700000  | 0                | TYPE_LIMIT | TIF_GTC | _buy4     |
    56  
    57  
    58    Scenario:
    59      # MAKE TRADES
    60      # no margin account created for party1, just general account
    61      Given "party1" should have one account per asset
    62      # placing test order
    63      When the parties place the following orders with ticks:
    64        | party  | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    65        | party1 | ETH/DEC19 | buy  | 13     | 15000000 | 2                | TYPE_LIMIT | TIF_GTC | ref-1     |
    66      And "party1" should have general account balance of "737919784" for asset "ETH"
    67      And the following trades should be executed:
    68        | buyer  | price    | size | seller     |
    69        | party1 | 11200000 | 2    | sellSideMM |
    70        | party1 | 11200010 | 11   | lpprov     |
    71  
    72      Then the following transfers should happen:
    73        | from   | to     | from account            | to account          | market id | amount  | asset |
    74        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 20 | ETH |
    75  
    76      Then the parties should have the following account balances:
    77        | party  | asset | market id | margin    | general   |
    78        | party1 | ETH   | ETH/DEC19 | 262080236 | 737919784 |
    79      And the parties should have the following margin levels:
    80        | party  | market id | maintenance |
    81        | party1 | ETH/DEC19 | 65520059    |
    82      And the parties should have the following profit and loss:
    83        | party  | volume | unrealised pnl | realised pnl |
    84        | party1 | 13     | 20             | 0            |
    85  
    86      # NEW ORDERS ADDED WITHOUT ANOTHER TRADE HAPPENING
    87      Then the parties cancel the following orders:
    88        | party     | reference |
    89        | buySideMM | buy1      |
    90        | buySideMM | buy2      |
    91  
    92      Then the parties should have the following account balances:
    93        | party  | asset | market id | margin    | general   |
    94        | party1 | ETH   | ETH/DEC19 | 262080236 | 737919784 |
    95      And the parties should have the following margin levels:
    96        | party  | market id | maintenance |
    97        | party1 | ETH/DEC19 | 65520059    |
    98      And the parties should have the following profit and loss:
    99        | party  | volume | unrealised pnl | realised pnl |
   100        | party1 | 13     | 20             | 0            |
   101  
   102      # ANOTHER TRADE HAPPENING (BY A DIFFERENT PARTY)
   103      # updating mark price to 100
   104      When the parties place the following orders with ticks:
   105        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
   106        | sellSideMM | ETH/DEC19 | sell | 1      | 10000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   107        | buySideMM  | ETH/DEC19 | buy  | 1      | 10000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   108  
   109      And the following transfers should happen:
   110        | from   | to     | from account        | to account              | market id | amount   | asset |
   111        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 15600130 | ETH |
   112  
   113      Then the parties should have the following account balances:
   114        | party  | asset | market id | margin    | general   |
   115        | party1 | ETH | ETH/DEC19   | 246480106 | 737919784 |
   116      And the parties should have the following margin levels:
   117        | party  | market id | maintenance | 
   118        | party1 | ETH/DEC19 | 58500000    | 
   119      And the parties should have the following profit and loss:
   120        | party  | volume | unrealised pnl | realised pnl |
   121        | party1 | 13     | -15600110      | 0            |
   122  
   123      # PARTIAL CLOSEOUT BY TRADER
   124      When the parties place the following orders with ticks:
   125        | party  | market id | side | volume | price   | resulting trades | type       | tif     | reference |
   126        | party1 | ETH/DEC19 | sell | 10     | 8000000 | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   127      Then the parties should have the following account balances:
   128        | party  | asset | market id | margin   | general   |
   129        | party1 | ETH | ETH/DEC19   | 43200000 | 915199890 |
   130      And the parties should have the following margin levels:
   131        | party  | market id | maintenance |
   132        | party1 | ETH/DEC19 | 10800000    |
   133      And the parties should have the following profit and loss:
   134        | party  | volume | unrealised pnl | realised pnl |
   135        | party1 | 3      | -9600025       | -32000085    |
   136  
   137      # FULL CLOSEOUT BY TRADER
   138      When the parties place the following orders with ticks:
   139        | party  | market id | side | volume | price   | resulting trades | type       | tif     |
   140        | party1 | ETH/DEC19 | sell | 3      | 7000000 | 1                | TYPE_LIMIT | TIF_GTC |
   141      Then the parties should have the following account balances:
   142        | party  | asset | market id | margin | general   |
   143        | party1 | ETH | ETH/DEC19 | 0 | 958399890 |
   144      And 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      And the parties should have the following profit and loss:
   148        | party  | volume | unrealised pnl | realised pnl |
   149        | party1 | 0 | 0 | -41600110 |
   150