code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-032.feature (about) 1 Feature: Test magin under isolated margin mode 2 Background: 3 # Set liquidity parameters to allow "zero" target-stake which is needed to construct the order-book defined in the ACs 4 Given the following network parameters are set: 5 | name | value | 6 | network.markPriceUpdateMaximumFrequency | 0s | 7 And the liquidity monitoring parameters: 8 | name | triggering ratio | time window | scaling factor | 9 | lqm-params | 0.00 | 24h | 1e-9 | 10 And the simple risk model named "simple-risk-model": 11 | long | short | max move up | min move down | probability of trading | 12 | 0.1 | 0.1 | 100 | -100 | 0.2 | 13 And the markets: 14 | 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 | 15 | 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 | 16 | ETH/MAR23 | ETH | USD | lqm-params | simple-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 100 | 0 | default-futures | 17 @SLABug 18 Scenario: Check margin update when switch between margin modes (0019-MCAL-031, 0019-MCAL-032) 19 Given the parties deposit on asset's general account the following amount: 20 | party | asset | amount | 21 | buySideProvider | USD | 100000000000 | 22 | sellSideProvider | USD | 100000000000 | 23 | party | USD | 100000000000 | 24 And the parties place the following orders: 25 | party | market id | side | volume | price | resulting trades | type | tif | 26 | buySideProvider | ETH/FEB23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | 27 | buySideProvider | ETH/FEB23 | buy | 1 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | 28 | buySideProvider | ETH/FEB23 | buy | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | 29 | party | ETH/FEB23 | sell | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | 30 | sellSideProvider | ETH/FEB23 | sell | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GTC | 31 | sellSideProvider | ETH/FEB23 | sell | 10 | 100100 | 0 | TYPE_LIMIT | TIF_GTC | 32 # TODO: No idea why this test adds a second market, there's absolutely no need for it. 33 And the parties place the following orders: 34 | party | market id | side | volume | price | resulting trades | type | tif | 35 | buySideProvider | ETH/MAR23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | 36 | buySideProvider | ETH/MAR23 | buy | 1 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | 37 | buySideProvider | ETH/MAR23 | buy | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | 38 | party | ETH/MAR23 | sell | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | 39 | sellSideProvider | ETH/MAR23 | sell | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GTC | 40 | sellSideProvider | ETH/MAR23 | sell | 10 | 100100 | 0 | TYPE_LIMIT | TIF_GTC | 41 # Checks for 0019-MCAL-031 42 When the network moves ahead "2" blocks 43 # Check mark-price matches the specification 44 Then the mark price should be "15900" for the market "ETH/FEB23" 45 # Check order book matches the specification 46 And the order book should have the following volumes for market "ETH/FEB23": 47 | side | price | volume | 48 | buy | 14900 | 10 | 49 | buy | 15000 | 1 | 50 | sell | 100000 | 1 | 51 | sell | 100100 | 10 | 52 # Check party margin levels match the specification 53 And the parties should have the following margin levels: 54 | party | market id | maintenance | search | initial | release | 55 | party | ETH/FEB23 | 5565 | 6121 | 6678 | 7791 | 56 #margin = min((100000-15900), 15900*(0.25))+0.1*15900=5565 57 58 Then the parties should have the following account balances: 59 | party | asset | market id | margin | general | 60 | party | USD | ETH/FEB23 | 6678 | 99998083414 | 61 62 #AC: 0019-MCAL-032, switch to isolated margin is rejected becuase selected margin factor is too small 63 And the parties submit update margin mode: 64 | party | market | margin_mode | margin_factor | error | 65 | party | ETH/FEB23 | isolated margin | 0.11 | margin factor (0.11) must be greater than max(riskFactorLong (0.1), riskFactorShort (0.1)) + linearSlippageFactor (0.25) | 66 67 And the parties should have the following margin levels: 68 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 69 | party | ETH/FEB23 | 5565 | 6121 | 6678 | 7791 | cross margin | 0 | 0 | 70 71 Then the parties should have the following account balances: 72 | party | asset | market id | margin | general | 73 | party | USD | ETH/FEB23 | 6678 | 99998083414 | 74 75 And the network moves ahead "1" blocks 76 #AC: 0019-MCAL-033, switch to isolated margin 77 And the parties submit update margin mode: 78 | party | market | margin_mode | margin_factor | 79 | party | ETH/FEB23 | isolated margin | 0.9 | 80 81 Then the parties should have the following account balances: 82 | party | asset | market id | margin | general | 83 | party | USD | ETH/FEB23 | 14310 | 99998075782 | 84 And the network moves ahead "2" blocks 85 86 And the parties should have the following margin levels: 87 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 88 | party | ETH/FEB23 | 5565 | 0 | 6678 | 0 | isolated margin | 0.9 | 0 | 89 90 #AC: 0019-MCAL-031, decrease margin factor 91 And the parties submit update margin mode: 92 | party | market | margin_mode | margin_factor | error | 93 | party | ETH/FEB23 | isolated margin | 0.7 | | 94 95 Then the parties should have the following account balances: 96 | party | asset | market id | margin | general | 97 | party | USD | ETH/FEB23 | 11130 | 99998078962 | 98 And the network moves ahead "2" blocks 99 100 And the parties should have the following margin levels: 101 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 102 | party | ETH/FEB23 | 5565 | 0 | 6678 | 0 | isolated margin | 0.7 | 0 | 103 104 #AC: 0019-MCAL-059, increase margin factor 105 And the parties submit update margin mode: 106 | party | market | margin_mode | margin_factor | 107 | party | ETH/FEB23 | isolated margin | 0.9 | 108 109 Then the parties should have the following account balances: 110 | party | asset | market id | margin | general | 111 | party | USD | ETH/FEB23 | 14310 | 99998075782 | 112 And the network moves ahead "2" blocks 113 114 And the parties should have the following margin levels: 115 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 116 | party | ETH/FEB23 | 5565 | 0 | 6678 | 0 | isolated margin | 0.9 | 0 | 117 118 #AC: 0019-MCAL-065, switch margin mode from isolated margin to cross margin when party holds position only 119 And the parties submit update margin mode: 120 | party | market | margin_mode | margin_factor | 121 | party | ETH/FEB23 | cross margin | | 122 And the network moves ahead "1" blocks 123 And the parties should have the following margin levels: 124 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 125 | party | ETH/FEB23 | 5565 | 6121 | 6678 | 7791 | cross margin | 0 | 0 | 126 Then the parties should have the following account balances: 127 | party | asset | market id | margin | general | 128 | party | USD | ETH/FEB23 | 14310 | 99998075782 | 129 130 And the parties submit update margin mode: 131 | party | market | margin_mode | margin_factor | 132 | party | ETH/FEB23 | isolated margin | 0.9 | 133 And the network moves ahead "1" blocks 134 Then the parties should have the following account balances: 135 | party | asset | market id | margin | general | 136 | party | USD | ETH/FEB23 | 14310 | 99998075782 | 137 138 #trigger MTM 139 And the parties place the following orders: 140 | party | market id | side | volume | price | resulting trades | type | tif | 141 | buySideProvider | ETH/FEB23 | buy | 1 | 15910 | 0 | TYPE_LIMIT | TIF_GTC | 142 | sellSideProvider | ETH/FEB23 | sell | 1 | 15910 | 1 | TYPE_LIMIT | TIF_GTC | 143 144 Then the parties should have the following account balances: 145 | party | asset | market id | margin | general | 146 | party | USD | ETH/FEB23 | 14310 | 99998075782 | 147 148 And the network moves ahead "1" blocks 149 Then the parties should have the following account balances: 150 | party | asset | market id | margin | general | 151 | party | USD | ETH/FEB23 | 14300 | 99998075782 | 152 153 #AC: 0019-MCAL-034, party places a new order which can not offset their position 154 #addional margin should be: limit price x current position x new margin factor = 15910 x 10 x 0.9 = 143190 155 And the parties place the following orders: 156 | party | market id | side | volume | price | resulting trades | type | tif | reference | 157 | party | ETH/FEB23 | sell | 10 | 15912 | 0 | TYPE_LIMIT | TIF_GTC | sell-10 | 158 Then the parties should have the following account balances: 159 | party | asset | market id | margin | general | order margin | 160 | party | USD | ETH/FEB23 | 14300 | 99997932574 | 143208 | 161 162 #AC 0019-MCAL-060, Amend order,check the updated order margin 163 When the parties amend the following orders: 164 | party | reference | price | size delta | tif | 165 | party | sell-10 | 15912 | -5 | TIF_GTC | 166 # And the network moves ahead "1" blocks 167 168 Then the parties should have the following account balances: 169 | party | asset | market id | margin | general | order margin | 170 | party | USD | ETH/FEB23 | 14300 | 99998004178 | 71604 | 171 172 #AC 0019-MCAL-061, party's order get partially filled, check the updated margin account and order account 173 And the parties place the following orders: 174 | party | market id | side | volume | price | resulting trades | type | tif | 175 | buySideProvider | ETH/FEB23 | buy | 3 | 15912 | 1 | TYPE_LIMIT | TIF_GTC | 176 177 Then the parties should have the following account balances: 178 | party | asset | market id | margin | general | order margin | 179 | party | USD | ETH/FEB23 | 57262 | 99998004178 | 28642 | 180 181 Then the order book should have the following volumes for market "ETH/FEB23": 182 | side | price | volume | 183 | sell | 15912 | 2 | 184 185 #AC: 0019-MCAL-063, switch margin mode from isolated margin to cross margin when party holds both position and orders 186 And the parties submit update margin mode: 187 | party | market | margin_mode | 188 | party | ETH/FEB23 | cross margin | 189 190 And the network moves ahead "1" blocks 191 And the parties should have the following margin levels: 192 | party | market id | maintenance | search | initial | release | margin mode | order | margin factor | 193 | party | ETH/FEB23 | 25460 | 28006 | 30552 | 35644 | cross margin | 0 | 0 | 194 195 Then the parties should have the following account balances: 196 | party | asset | market id | margin | general | order margin | 197 | party | USD | ETH/FEB23 | 30552 | 99998059528 | 0 | 198 199 #AC: 0019-MCAL-064, switch margin mode from cross margin to isolated margin when party holds both position and orders 200 And the parties submit update margin mode: 201 | party | market | margin_mode | margin_factor | 202 | party | ETH/FEB23 | isolated margin | 0.9 | 203 And the network moves ahead "1" blocks 204 And the parties should have the following margin levels: 205 | party | market id | maintenance | search | initial | release | margin mode | order | margin factor | 206 | party | ETH/FEB23 | 22277 | 0 | 26732 | 0 | isolated margin | 28641 | 0.9 | 207 208 Then the parties should have the following account balances: 209 | party | asset | market id | margin | general | order margin | 210 | party | USD | ETH/FEB23 | 57272 | 99998004167 | 28641 | 211 212 And the parties place the following orders: 213 | party | market id | side | volume | price | resulting trades | type | tif | 214 | buySideProvider | ETH/FEB23 | buy | 1 | 15912 | 1 | TYPE_LIMIT | TIF_GTC | 215 216 Then the parties should have the following account balances: 217 | party | asset | market id | margin | general | order margin | 218 | party | USD | ETH/FEB23 | 71592 | 99998004167 | 14321 | 219 220 #AC 0019-MCAL-062, when party has no orders, the order margin account shoule be 0 221 And the parties place the following orders: 222 | party | market id | side | volume | price | resulting trades | type | tif | 223 | buySideProvider | ETH/FEB23 | buy | 1 | 15912 | 1 | TYPE_LIMIT | TIF_GTC | 224 225 Then the parties should have the following account balances: 226 | party | asset | market id | margin | general | order margin | 227 | party | USD | ETH/FEB23 | 85912 | 99998004168 | 0 | 228 229 #AC: 0019-MCAL-038,when party places a new order which can offset the party's position, no additional margin will be needed 230 And the parties place the following orders: 231 | party | market id | side | volume | price | resulting trades | type | tif | 232 | party | ETH/FEB23 | buy | 3 | 15912 | 0 | TYPE_LIMIT | TIF_GTC | 233 And the network moves ahead "1" blocks 234 Then the parties should have the following account balances: 235 | party | asset | market id | margin | general | order margin | 236 | party | USD | ETH/FEB23 | 85912 | 99998004168 | 0 | 237 238 #AC: 0019-MCAL-039,when party places a large order which can offset all of the party's position and then add new orders, additional margin will be needed 239 And the parties place the following orders: 240 | party | market id | side | volume | price | resulting trades | type | tif | 241 | party | ETH/FEB23 | buy | 10 | 15912 | 0 | TYPE_LIMIT | TIF_GTC | 242 And the network moves ahead "1" blocks 243 Then the parties should have the following account balances: 244 | party | asset | market id | margin | general | order margin | 245 | party | USD | ETH/FEB23 | 85912 | 99997903923 | 100245 | 246 247 248 249