code.vegaprotocol.io/vega@v0.79.0/core/integration/features/mark-price/0009-MRKP-018.feature (about)

     1  Feature: Test It is possible to configure a cash settled futures market to use a weighted average of 1. weighted average of trades over network.markPriceUpdateMaximumFrequency and 2. impact of leveraged notional on the order book with the value of USDT 100 and 3. an oracle source and if last trade is last updated more than 1 minute ago then it is removed and the remaining re-weighted and if the oracle is last updated more than 5 minutes ago then it is removed and the remaining re-weighted (0009-MRKP-018) and a perps market (with the oracle source different to that used for the external price in the perps market) (0009-MRKP-019).
     2    Background:
     3      Given the following network parameters are set:
     4        | name                                    | value |
     5        | network.markPriceUpdateMaximumFrequency | 1s    |
     6      And the liquidity monitoring parameters:
     7        | name       | triggering ratio | time window | scaling factor |
     8        | lqm-params | 0.00             | 24h         | 1e-9           |
     9      And the simple risk model named "simple-risk-model":
    10        | long | short | max move up | min move down | probability of trading |
    11        | 0.1  | 0.1   | 100         | -100          | 0.2                    |
    12  
    13      And the composite price oracles from "0xCAFECAFE1":
    14        | name    | price property   | price type   | price decimals |
    15        | oracle1 | price1.USD.value | TYPE_INTEGER | 0              |
    16  
    17      And the markets:
    18        | 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      | price type | decay weight | decay power | cash amount | source weights | source staleness tolerance | oracle1 |
    19        | ETH/FEB23 | ETH        | USD   | lqm-params           | simple-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures | weight     | 0            | 1           | 100         | 1,4,5,0        | 1s,5s,20s,1h25m0s          | oracle1 |
    20  
    21    Scenario: 001 check mark price using weight average
    22      Given the parties deposit on asset's general account the following amount:
    23        | party            | asset | amount       |
    24        | buySideProvider  | USD   | 100000000000 |
    25        | sellSideProvider | USD   | 100000000000 |
    26        | party            | USD   | 48050        |
    27      And the parties place the following orders:
    28        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    29        | buySideProvider  | ETH/FEB23 | buy  | 3      | 15900 | 0                | TYPE_LIMIT | TIF_GTC |           |
    30        | party            | ETH/FEB23 | sell | 3      | 15900 | 0                | TYPE_LIMIT | TIF_GTC |           |
    31        | sellSideProvider | ETH/FEB23 | sell | 1      | 15920 | 0                | TYPE_LIMIT | TIF_GTC |           |
    32        | sellSideProvider | ETH/FEB23 | sell | 1      | 15940 | 0                | TYPE_LIMIT | TIF_GTC |           |
    33  
    34      When the network moves ahead "2" blocks
    35      # leaving opening auction
    36      # mark price calcualted from the trade price
    37      Then the mark price should be "15900" for the market "ETH/FEB23"
    38  
    39      And the parties place the following orders:
    40        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference |
    41        | buySideProvider | ETH/FEB23 | buy  | 2      | 15920 | 1                | TYPE_LIMIT | TIF_GTC |           |
    42  
    43      And the parties place the following orders:
    44        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference |
    45        | buySideProvider | ETH/FEB23 | buy  | 1      | 15940 | 1                | TYPE_LIMIT | TIF_GTC |           |
    46  
    47      Then the oracles broadcast data with block time signed with "0xCAFECAFE1":
    48        | name             | value | time offset |
    49        | price1.USD.value | 16000 | -1s         |
    50  
    51      When the network moves ahead "2" blocks
    52      # we have:
    53      # price from trades = 15930 - 2 trades in scope
    54      # price from book = 15900 - since the opening auction there are no orders on the sell side so not updating but still not stale
    55      # price from oracle = 16000
    56      # markprice = 0.1*15930 + 0.4*15900 + 0.5*16000
    57      Then the mark price should be "15953" for the market "ETH/FEB23"
    58  
    59      # now place and order and let trades go out of scope
    60      And the parties place the following orders:
    61        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    62        | sellSideProvider | ETH/FEB23 | sell | 1      | 15940 | 0                | TYPE_LIMIT | TIF_GTC |           |
    63  
    64      When the network moves ahead "2" blocks
    65      # we have:
    66      # price from trades = 0 - no trades, price is already stale
    67      # price from book = 15930 fresh
    68      # price from oracle = 16000 still not stale
    69      # markprice = 4/9*15930 + 5/9*16000 = 15968
    70      Then the mark price should be "15968" for the market "ETH/FEB23"
    71  
    72      # trade the buy side to get rid of the book mid
    73      And the parties place the following orders:
    74        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
    75        | sellSideProvider | ETH/FEB23 | sell | 1      | 15920 | 1                | TYPE_LIMIT | TIF_GTC |           |
    76  
    77      # now we have no orders on the buy side
    78      When the network moves ahead "10" blocks
    79      # we have:
    80      # price from trades = 0 - no trades, price is already stale
    81      # price from book = 0 stale
    82      # price from oracle = 16000 still not stale
    83      # markprice = 16000 
    84      Then the mark price should be "16000" for the market "ETH/FEB23"
    85  
    86      # get the oracle price to stale and submit a fresh order
    87      When the network moves ahead "10" blocks
    88      And the parties place the following orders:
    89        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference |
    90        | buySideProvider | ETH/FEB23 | buy  | 1      | 15920 | 0                | TYPE_LIMIT | TIF_GTC |           |
    91  
    92      # now we only have a book price of 15930 (trade and oracle are stale) so it gets a weight of 1
    93      When the network moves ahead "2" blocks
    94      Then the mark price should be "15930" for the market "ETH/FEB23"