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

     1  Feature: CASE-5: Trader submits short order that will trade - new formula & low exit price (0019-MCAL-001, 0019-MCAL-002, 0019-MCAL-003, 0019-MCAL-016)
     2    # https://drive.google.com/drive/folders/1BCOKaEb7LZYAKoiPfXfaqwM4BNicPpF-
     3  
     4    Background:
     5      Given the following network parameters are set:
     6        | name                                    | value |
     7        | market.auction.minimumDuration          | 1     |
     8        | network.markPriceUpdateMaximumFrequency | 0s    |
     9        | limits.markets.maxPeggedOrders          | 2     |
    10      And the markets:
    11        | id        | quote name | asset | risk model                | margin calculator                  | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    12        | ETH/DEC19 | ETH        | ETH   | default-simple-risk-model | default-overkill-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.1                    | 0                         | default-futures |
    13      And the parties deposit on asset's general account the following amount:
    14        | party      | asset | amount       |
    15        | party1 | ETH | 310000000 |
    16        | sellSideMM | ETH   | 100000000000 |
    17        | buySideMM  | ETH   | 100000000000 |
    18        | aux        | ETH   | 1000000000   |
    19        | aux2       | ETH   | 1000000000   |
    20        | lpprov     | ETH   | 1000000000   |
    21  
    22      When the parties submit the following liquidity provision:
    23        | id  | party  | market id | commitment amount | fee | lp type    |
    24        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    25        | lp1 | lpprov | ETH/DEC19 | 900000000         | 0.1 | submission |
    26      And the parties place the following pegged iceberg orders:
    27        | party  | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    28        | lpprov | ETH/DEC19 | 16 | 1 | buy  | BID | 16 | 10 |
    29        | lpprov | ETH/DEC19 | 15 | 1 | sell | ASK | 15 | 10 |
    30   
    31      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    32      Then the parties place the following orders:
    33        | party | market id | side | volume | price    | resulting trades | type       | tif     |
    34        | aux   | ETH/DEC19 | buy  | 1      | 6999999  | 0                | TYPE_LIMIT | TIF_GTC |
    35        | aux   | ETH/DEC19 | sell | 1      | 50000001 | 0                | TYPE_LIMIT | TIF_GTC |
    36        | aux   | ETH/DEC19 | buy  | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC |
    37        | aux2  | ETH/DEC19 | sell | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC |
    38      Then the opening auction period ends for market "ETH/DEC19"
    39      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    40      And the mark price should be "10300000" for the market "ETH/DEC19"
    41  
    42      # setting mark price
    43      And the parties place the following orders:
    44        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    45        | sellSideMM | ETH/DEC19 | sell | 1      | 10300000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    46        | buySideMM  | ETH/DEC19 | buy  | 1      | 10300000 | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    47  
    48      # setting order book
    49      And the parties place the following orders:
    50        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    51        | sellSideMM | ETH/DEC19 | sell | 10     | 15000000 | 0                | TYPE_LIMIT | TIF_GTC | sell1     |
    52        | sellSideMM | ETH/DEC19 | sell | 14     | 14000000 | 0                | TYPE_LIMIT | TIF_GTC | sell2     |
    53        | sellSideMM | ETH/DEC19 | sell | 2      | 11200000 | 0                | TYPE_LIMIT | TIF_GTC | sell3     |
    54        | buySideMM  | ETH/DEC19 | buy  | 1      | 10000000 | 0                | TYPE_LIMIT | TIF_GTC | buy1      |
    55        | buySideMM  | ETH/DEC19 | buy  | 3      | 9600000  | 0                | TYPE_LIMIT | TIF_GTC | buy2      |
    56        | buySideMM  | ETH/DEC19 | buy  | 9      | 9000000  | 0                | TYPE_LIMIT | TIF_GTC | buy3      |
    57        | buySideMM  | ETH/DEC19 | buy  | 50     | 8700000  | 0                | TYPE_LIMIT | TIF_GTC | buy4      |
    58  
    59    Scenario:
    60      # no margin account created for party1, just general account
    61      And "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 | sell | 13 | 9000000 | 2 | TYPE_LIMIT | TIF_GTC | ref-1 |
    66      And "party1" should have general account balance of "193000126" for asset "ETH"
    67  
    68  
    69      And the following trades should be executed:
    70        | buyer     | price    | size | seller |
    71        | buySideMM | 10000000 | 1    | party1 |
    72        | lpprov    | 9999990  | 12   | party1 |
    73  
    74      Then the following transfers should happen:
    75        | from      | to        | from account         | to account          | market id | amount    | asset |
    76        | party1    | party1    | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 53560000  | ETH   |
    77        | buySideMM | buySideMM | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 412000000 | ETH   |
    78  
    79      Then the parties should have the following account balances:
    80        | party  | asset | market id | margin    | general   |
    81        | party1 | ETH   | ETH/DEC19 | 103999896 | 193000126 |
    82      And the parties should have the following profit and loss:
    83        | party  | volume | unrealised pnl | realised pnl |
    84        | party1 | -13    | 10             | 0            |
    85  
    86      # NEW ORDERS ADDED WITHOUT ANOTHER TRADE HAPPENING
    87      Then the parties cancel the following orders:
    88        | party      | reference |
    89        | buySideMM  | buy4      |
    90        | sellSideMM | sell2     |
    91        | sellSideMM | sell3     |
    92      And the parties place the following orders with ticks:
    93        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
    94        | buySideMM  | ETH/DEC19 | buy  | 45     | 7000000  | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    95        | buySideMM  | ETH/DEC19 | buy  | 50     | 7500000  | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    96        | sellSideMM | ETH/DEC19 | sell | 14     | 10000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    97        | sellSideMM | ETH/DEC19 | sell | 2 | 11000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-4 |
    98  # no MTM yet, so accounts are not changing
    99      Then the parties should have the following account balances:
   100        | party  | asset | market id | margin    | general   |
   101        | party1 | ETH   | ETH/DEC19 | 103999896 | 193000126 |
   102  
   103      And the parties should have the following profit and loss:
   104        | party  | volume | unrealised pnl | realised pnl |
   105        | party1 | -13    | 10             | 0            |
   106  
   107      # ANOTHER TRADE HAPPENING (BY A DIFFERENT PARTY)
   108      # updating mark price to 300
   109      When the parties place the following orders with ticks:
   110        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
   111        | sellSideMM | ETH/DEC19 | sell | 50     | 30000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   112        | buySideMM | ETH/DEC19 | buy | 27 | 30000000 | 2 | TYPE_LIMIT | TIF_GTC | ref-2 |
   113  # MTM
   114      Then the following transfers should happen:
   115        | from       | to         | from account            | to account          | market id | amount    | asset |
   116        | sellSideMM | sellSideMM | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 196339678 | ETH   |
   117        | market     | buySideMM  | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 180       | ETH   |
   118  
   119      Then the parties should have the following account balances:
   120        | party  | asset | market id | margin    | general   |
   121        | party1 | ETH   | ETH/DEC19 | 103999636 | 193000126 |
   122  
   123      And the parties should have the following profit and loss:
   124        | party  | volume | unrealised pnl | realised pnl |
   125        | party1 | -13    | -250           | 0            |
   126       
   127      When the parties place the following orders with ticks:
   128        | party      | market id | side | volume | price    | resulting trades | type       | tif     | reference |
   129        | sellSideMM | ETH/DEC19 | sell | 11     | 50000000 | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   130        | buySideMM | ETH/DEC19 | buy | 50 | 50000000 | 4 | TYPE_LIMIT | TIF_GTC | ref-2 |
   131      Then the parties should have the following account balances:
   132        | party  | asset | market id | margin | general |
   133        | party1 | ETH   | ETH/DEC19 | 0      | 0       |
   134  
   135      And the parties should have the following profit and loss:
   136        | party  | volume | unrealised pnl | realised pnl |
   137        | party1 | 0 | 0 | -297000012 |