code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/0053-PERP-028_twap_calculation_with_auction.feature (about) 1 Feature: Test internal and external twap calculation 2 3 Background: 4 # epoch time is 1602806400 5 Given time is updated to "2020-10-16T00:00:00Z" 6 And the following assets are registered: 7 | id | decimal places | quantum | 8 | USD.3.1000 | 3 | 1000 | 9 And the perpetual oracles from "0xCAFECAFE1": 10 | name | asset | settlement property | settlement type | schedule property | schedule type | margin funding factor | interest rate | clamp lower bound | clamp upper bound | quote name | settlement decimals | 11 | perp-oracle | USD.3.1000 | perp.ETH.value | TYPE_INTEGER | perp.funding.cue | TYPE_TIMESTAMP | 0.5 | 0.00 | 0.0 | 0.0 | ETH | 18 | 12 And the liquidity sla params named "SLA": 13 | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor | 14 | 100.0 | 0.5 | 1 | 1.0 | 15 And the price monitoring named "my-price-monitoring": 16 | horizon | probability | auction extension | 17 | 43200 | 0.9999999 | 120 | 18 And the log normal risk model named "my-log-normal-risk-model": 19 | risk aversion | tau | mu | r | sigma | 20 | 0.000001 | 0.00011407711613050422 | 0 | 0.016 | 0.8 | 21 And the markets: 22 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | market type | sla params | 23 | ETH/DEC19 | ETH | USD.3.1000 | my-log-normal-risk-model | default-margin-calculator | 120 | default-none | my-price-monitoring | perp-oracle | 0.25 | 0 | -3 | perp | SLA | 24 And the following network parameters are set: 25 | name | value | 26 | network.markPriceUpdateMaximumFrequency | 0s | 27 And the average block duration is "1" 28 When the parties deposit on asset's general account the following amount: 29 | party | asset | amount | 30 | party1 | USD.3.1000 | 100000000000000 | 31 | party2 | USD.3.1000 | 100000000000000 | 32 | party3 | USD.3.1000 | 100000000000000 | 33 | aux | USD.3.1000 | 100000000000000 | 34 | aux2 | USD.3.1000 | 100000000000000 | 35 | lpprov | USD.3.1000 | 100000000000000 | 36 Then the parties submit the following liquidity provision: 37 | id | party | market id | commitment amount | fee | lp type | 38 | lp1 | lpprov | ETH/DEC19 | 100000000 | 0.001 | submission | 39 # move market to continuous 40 And the parties place the following orders: 41 | party | market id | side | volume | price | resulting trades | type | tif | 42 | aux2 | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 43 | lpprov | ETH/DEC19 | buy | 100000 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 44 | aux2 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 45 | aux | ETH/DEC19 | sell | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 46 | aux | ETH/DEC19 | sell | 1 | 35 | 0 | TYPE_LIMIT | TIF_GTC | 47 | lpprov | ETH/DEC19 | sell | 100000 | 35 | 0 | TYPE_LIMIT | TIF_GTC | 48 And the market data for the market "ETH/DEC19" should be: 49 | target stake | supplied stake | 50 | 4315000 | 100000000 | 51 And the opening auction period ends for market "ETH/DEC19" 52 53 @Perpetual @twap 54 Scenario: 0053-PERP-028 Internal and External TWAP calculation, auction in funding period 55 Given the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 56 And time is updated to "2020-10-16T00:05:00Z" 57 When the parties place the following orders: 58 | party | market id | side | volume | price | resulting trades | type | tif | 59 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 60 | party2 | ETH/DEC19 | sell | 1 | 10 | 1 | TYPE_LIMIT | TIF_GTC | 61 Then time is updated to "2020-10-16T00:10:00Z" 62 63 # 0 min in to the next funding period 64 Given the oracles broadcast data with block time signed with "0xCAFECAFE1": 65 | name | value | time offset | 66 | perp.ETH.value | 11000000000000000000 | -1s | 67 | perp.funding.cue | 1602807000 | 0s | 68 And the mark price should be "10" for the market "ETH/DEC19" 69 70 # 1 min in to the next funding period 71 Given the network moves ahead "60" blocks 72 Then the product data for the market "ETH/DEC19" should be: 73 | internal twap | external twap | funding payment | 74 | 10000 | 11000 | -1000 | 75 Given the parties place the following orders: 76 | party | market id | side | volume | price | resulting trades | type | tif | 77 | party1 | ETH/DEC19 | buy | 1 | 11 | 0 | TYPE_LIMIT | TIF_GTC | 78 | party2 | ETH/DEC19 | sell | 1 | 11 | 1 | TYPE_LIMIT | TIF_GTC | 79 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 80 | name | value | time offset | 81 | perp.ETH.value | 9000000000000000000 | 0s | 82 83 # 2 min in to the next funding period 84 Given the network moves ahead "60" blocks 85 Then the product data for the market "ETH/DEC19" should be: 86 | internal twap | external twap | funding payment | 87 | 10500 | 10000 | 500 | 88 89 # 3 min in to the next funding period 90 Given the network moves ahead "60" blocks 91 Then the product data for the market "ETH/DEC19" should be: 92 | internal twap | external twap | funding payment | 93 | 10666 | 9666 | 1000 | 94 Given the oracles broadcast data with block time signed with "0xCAFECAFE1": 95 | name | value | time offset | 96 | perp.ETH.value | 10000000000000000000 | 0s | 97 98 # 4 min in to the next funding period 99 Given the network moves ahead "60" blocks 100 Then the product data for the market "ETH/DEC19" should be: 101 | internal twap | external twap | funding payment | 102 | 10750 | 9750 | 1000 | 103 104 # 5 min in to the next funding period, the auction period will start 105 Given the network moves ahead "60" blocks 106 Then the product data for the market "ETH/DEC19" should be: 107 | internal twap | external twap | funding payment | 108 | 10800 | 9800 | 1000 | 109 Given the parties place the following orders: 110 | party | market id | side | volume | price | resulting trades | type | tif | reference | 111 | aux2 | ETH/DEC19 | buy | 1 | 15 | 0 | TYPE_LIMIT | TIF_GTC | trigger-auction2 | 112 | aux | ETH/DEC19 | sell | 1 | 15 | 0 | TYPE_LIMIT | TIF_GTC | trigger-auction1 | 113 | party1 | ETH/DEC19 | buy | 10 | 9 | 0 | TYPE_LIMIT | TIF_GTC | | 114 | party2 | ETH/DEC19 | sell | 10 | 9 | 0 | TYPE_LIMIT | TIF_GTC | | 115 And the parties cancel the following orders: 116 | party | reference | 117 | aux | trigger-auction1 | 118 | aux2 | trigger-auction2 | 119 Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19" 120 Given the oracles broadcast data with block time signed with "0xCAFECAFE1": 121 | name | value | time offset | 122 | perp.ETH.value | 30000000000000000000 | 0s | 123 124 ### 6 mins in, still in monitoring auction (fraction outside auction is 5/6, hence the funding payment ends up being 5/6*1000=~833) 125 Given the network moves ahead "60" blocks 126 Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19" 127 Then the product data for the market "ETH/DEC19" should be: 128 | internal twap | external twap | funding payment | 129 | 10800 | 9800 | 833 | 130 Given the oracles broadcast data with block time signed with "0xCAFECAFE1": 131 | name | value | time offset | 132 | perp.ETH.value | 11000000000000000000 | 0s | 133 134 # 7 mins in, the auction period will end (fraction outside auction is 5/7, hence the funding payment ends up being 5/7*1000=~714) 135 Given the network moves ahead "60" blocks 136 Then the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC19" 137 Then the product data for the market "ETH/DEC19" should be: 138 | internal twap | external twap | funding payment | 139 | 10800 | 9800 | 714 | 140 Then the network moves ahead "1" blocks 141 142 # 8 mins in, still in continuous trading (fraction outside auction is ~6/8, hence the funding payment ends up being 6/8*500=~374) 143 Given the network moves ahead "60" blocks 144 Then the product data for the market "ETH/DEC19" should be: 145 | internal twap | external twap | funding payment | 146 | 10500 | 10000 | 374 | 147 Given the parties place the following orders: 148 | party | market id | side | volume | price | resulting trades | type | tif | 149 | party1 | ETH/DEC19 | buy | 1 | 8 | 0 | TYPE_LIMIT | TIF_GTC | 150 | party2 | ETH/DEC19 | sell | 1 | 8 | 1 | TYPE_LIMIT | TIF_GTC | 151 And the oracles broadcast data with block time signed with "0xCAFECAFE1": 152 | name | value | time offset | 153 | perp.ETH.value | 8000000000000000000 | 0s | 154 155 # 9 mins in, still in continuous trading (fraction outside auction is ~7/9, hence the funding payment ends up being 7/9*500=~332) 156 Given the network moves ahead "60" blocks 157 Then the product data for the market "ETH/DEC19" should be: 158 | internal twap | external twap | funding payment | 159 | 10142 | 9714 | 332 | 160 Given the oracles broadcast data with block time signed with "0xCAFECAFE1": 161 | name | value | time offset | 162 | perp.ETH.value | 14000000000000000000 | 0s | 163 164 # 10 mins in, still in continuous trading (fraction outside auction is ~8/10, hence the funding payment ends up being 8/10*375=~299) 165 Given the network moves ahead "60" blocks 166 Then the markets are updated: 167 | id | price monitoring | linear slippage factor | quadratic slippage factor | 168 | ETH/DEC19 | default-none | 0.25 | 0 | 169 When the parties place the following orders: 170 | party | market id | side | volume | price | resulting trades | type | tif | 171 | party1 | ETH/DEC19 | buy | 1 | 30 | 0 | TYPE_LIMIT | TIF_GTC | 172 | party2 | ETH/DEC19 | sell | 1 | 30 | 1 | TYPE_LIMIT | TIF_GTC | 173 Then the product data for the market "ETH/DEC19" should be: 174 | internal twap | external twap | funding payment | 175 | 9875 | 10250 | -299 |