code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/614-margin-calculations-fixes.feature (about)

     1  Feature: test bugfix 614 for margin calculations
     2  
     3    Background:
     4      Given the markets:
     5        | id        | quote name | asset | risk model                | margin calculator                  | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
     6        | 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 |
     7      And the following network parameters are set:
     8        | name                                    | value |
     9        | network.markPriceUpdateMaximumFrequency | 0s    |
    10        | limits.markets.maxPeggedOrders          | 2     |
    11  
    12    @MTMDelta
    13    Scenario: CASE-1: Trader submits long order that will trade - new formula & high exit price
    14      Given the parties deposit on asset's general account the following amount:
    15        | party   | asset | amount  |
    16        | chris   | ETH   | 10000   |
    17        | edd     | ETH   | 10000   |
    18        | barney  | ETH   | 10000   |
    19        | rebecca | ETH   | 10000   |
    20        | tamlyn  | ETH   | 10000   |
    21        | party1  | ETH   | 1000000 |
    22        | party2  | ETH   | 1000000 |
    23        | aux     | ETH   | 1000    |
    24        | lpprov  | ETH   | 1000000 |
    25  
    26      When the parties submit the following liquidity provision:
    27        | id  | party  | market id | commitment amount | fee | lp type    |
    28        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.0 | submission |
    29        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.0 | submission |
    30      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    31      Then the parties place the following orders:
    32        | party | market id | side | volume | price | resulting trades | type       | tif     |
    33        | aux   | ETH/DEC19 | buy  | 1      | 87    | 0                | TYPE_LIMIT | TIF_GTC |
    34        | aux   | ETH/DEC19 | sell | 1      | 250   | 0                | TYPE_LIMIT | TIF_GTC |
    35  
    36      # Trigger an auction to set the mark price
    37      When the parties place the following orders:
    38        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    39        | party1 | ETH/DEC19 | buy  | 1      | 94    | 0                | TYPE_LIMIT | TIF_GFA | party1-2  |
    40        | party2 | ETH/DEC19 | sell | 1      | 94    | 0                | TYPE_LIMIT | TIF_GFA | party2-2  |
    41      Then the opening auction period ends for market "ETH/DEC19"
    42      And the mark price should be "94" for the market "ETH/DEC19"
    43  
    44      When the parties place the following orders with ticks:
    45        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference |
    46        | chris   | ETH/DEC19 | sell | 100    | 250   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    47        | edd     | ETH/DEC19 | sell | 11     | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    48        | barney  | ETH/DEC19 | sell | 2      | 112   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    49        | barney  | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    50        | edd     | ETH/DEC19 | buy  | 3      | 96    | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
    51        | chris   | ETH/DEC19 | buy  | 15     | 90    | 0                | TYPE_LIMIT | TIF_GTC | ref-6     |
    52        | rebecca | ETH/DEC19 | buy  | 50     | 87    | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
    53      # this is now the actual party that we are testing
    54      When the parties place the following orders with ticks:
    55        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    56        | tamlyn | ETH/DEC19 | buy  | 13     | 150   | 2                | TYPE_LIMIT | TIF_GTC | ref-1     |
    57      Then the parties should have the following margin levels:
    58        | party  | market id | maintenance |
    59        | tamlyn | ETH/DEC19 | 819         |
    60      Then the parties should have the following account balances:
    61        | party   | asset | market id | margin | general |
    62        | tamlyn  | ETH   | ETH/DEC19 | 3276   | 6780    |
    63        | chris   | ETH   | ETH/DEC19 | 5600   | 4400    |
    64        | edd     | ETH   | ETH/DEC19 | 2156   | 7844    |
    65        | barney  | ETH   | ETH/DEC19 | 392    | 9552    |
    66        | rebecca | ETH   | ETH/DEC19 | 5600   | 4400    |
    67      And the cumulated balance for all accounts should be worth "3051000"