code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-109.feature (about) 1 Feature: switch to isolated margin without position and with orders during auction 2 Background: 3 # switch between cross margin and isolated margin mode during auction 4 Given the following network parameters are set: 5 | name | value | 6 | network.markPriceUpdateMaximumFrequency | 0s | 7 And the price monitoring named "my-price-monitoring": 8 | horizon | probability | auction extension | 9 | 5 | 0.95 | 6 | 10 | 10 | 0.99 | 8 | 11 And the liquidity monitoring parameters: 12 | name | triggering ratio | time window | scaling factor | 13 | lqm-params | 0.00 | 24h | 1e-9 | 14 And the simple risk model named "simple-risk-model": 15 | long | short | max move up | min move down | probability of trading | 16 | 0.1 | 0.1 | 100 | -100 | 0.2 | 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 | 19 | ETH/FEB23 | ETH | USD | lqm-params | simple-risk-model | default-margin-calculator | 1 | default-none | my-price-monitoring | default-eth-for-future | 0.000125 | 0 | default-futures | 20 21 And the following network parameters are set: 22 | name | value | 23 | market.auction.minimumDuration | 1 | 24 Given the average block duration is "1" 25 26 Scenario: 001 switch to isolated margin during auction 27 Given the parties deposit on asset's general account the following amount: 28 | party | asset | amount | 29 | buySideProvider | USD | 100000000000 | 30 | sellSideProvider | USD | 100000000000 | 31 | party1 | USD | 28550 | 32 | party2 | USD | 84110 | 33 | party3 | USD | 84110 | 34 | party4 | USD | 84110 | 35 | party5 | USD | 84110 | 36 37 When the parties submit the following liquidity provision: 38 | id | party | market id | commitment amount | fee | lp type | 39 | lp1 | party1 | ETH/FEB23 | 1000 | 0.1 | submission | 40 41 And the parties place the following orders: 42 | party | market id | side | volume | price | resulting trades | type | tif | reference | 43 | buySideProvider | ETH/FEB23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 44 | buySideProvider | ETH/FEB23 | buy | 3 | 15600 | 0 | TYPE_LIMIT | TIF_GTC | | 45 | buySideProvider | ETH/FEB23 | buy | 1 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 46 | buySideProvider | ETH/FEB23 | buy | 1 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 47 | party4 | ETH/FEB23 | sell | 1 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 48 | party1 | ETH/FEB23 | sell | 1 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | p1-sell | 49 | party2 | ETH/FEB23 | sell | 1 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | p1-sell | 50 | party1 | ETH/FEB23 | sell | 2 | 15804 | 0 | TYPE_LIMIT | TIF_GTC | p1-sell | 51 | sellSideProvider | ETH/FEB23 | sell | 3 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 52 | sellSideProvider | ETH/FEB23 | sell | 10 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 53 54 When the network moves ahead "2" blocks 55 And the market data for the market "ETH/FEB23" should be: 56 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 57 | 15800 | TRADING_MODE_CONTINUOUS | 5 | 15701 | 15899 | 0 | 1000 | 2 | 58 59 Then the parties should have the following account balances: 60 | party | asset | market id | margin | general | bond | 61 | party1 | USD | ETH/FEB23 | 5689 | 21861 | 1000 | 62 63 #maintenance margin: min((15802-15800),15800*0.1)+0.1*15800+2*0.1*15800=4742 64 And the parties should have the following margin levels: 65 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 66 | party1 | ETH/FEB23 | 4742 | 5216 | 5690 | 6638 | cross margin | 0 | 0 | 67 68 #AC0019-MCAL-134:switch to cross margin without position and no orders successful in continuous mode 69 And the parties submit update margin mode: 70 | party | market | margin_mode | margin_factor | error | 71 | party5 | ETH/FEB23 | isolated margin | 0.4 | | 72 And the parties should have the following margin levels: 73 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 74 | party5 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 75 And the parties submit update margin mode: 76 | party | market | margin_mode | margin_factor | error | 77 | party5 | ETH/FEB23 | cross margin | 0.4 | | 78 And the parties should have the following margin levels: 79 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 80 | party5 | ETH/FEB23 | 0 | 0 | 0 | 0 | cross margin | 0 | 0 | 81 82 And the parties place the following orders: 83 | party | market id | side | volume | price | resulting trades | type | tif | reference | 84 | party5 | ETH/FEB23 | buy | 1 | 14800 | 0 | TYPE_LIMIT | TIF_GTC | | 85 86 #AC0019-MCAL-130: increase margin factor in isolated margin without position and with orders successful in continuous mode 87 And the parties submit update margin mode: 88 | party | market | margin_mode | margin_factor | error | 89 | party5 | ETH/FEB23 | isolated margin | 0.4 | | 90 And the parties should have the following margin levels: 91 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 92 | party5 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 5920 | 93 And the parties submit update margin mode: 94 | party | market | margin_mode | margin_factor | error | 95 | party5 | ETH/FEB23 | isolated margin | 0.5 | | 96 And the parties should have the following margin levels: 97 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 98 | party5 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.5 | 7400 | 99 100 #now trigger price monitoring auction 101 And the parties place the following orders: 102 | party | market id | side | volume | price | resulting trades | type | tif | reference | 103 | sellSideProvider | ETH/FEB23 | sell | 1 | 15600 | 0 | TYPE_LIMIT | TIF_GTC | | 104 And the market data for the market "ETH/FEB23" should be: 105 | mark price | trading mode | 106 | 15800 | TRADING_MODE_MONITORING_AUCTION | 107 108 #AC0019-MCAL-109: switch to isolated margin with position and with orders with margin factor such that position margin is < initial should fail in auction 109 And the markets are updated: 110 | id | linear slippage factor | 111 | ETH/FEB23 | 0.25 | 112 And the parties submit update margin mode: 113 | party | market | margin_mode | margin_factor | error | 114 | party1 | ETH/FEB23 | isolated margin | 0.36 | required position margin must be greater than initial margin | 115 Then the parties should have the following account balances: 116 | party | asset | market id | margin | general | bond | 117 | party1 | USD | ETH/FEB23 | 5689 | 21861 | 1000 | 118 119 #AC0019-MCAL-122: switch to isolated margin without position and with orders successful in continuous mode 120 And the parties submit update margin mode: 121 | party | market | margin_mode | margin_factor | error | 122 | party2 | ETH/FEB23 | isolated margin | 0.4 | | 123 124 And the parties should have the following margin levels: 125 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 126 | party2 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 6320 | 127 128 #AC0019-MCAL-138: switch to cross margin without position and with orders successful in continuous mode 129 And the parties submit update margin mode: 130 | party | market | margin_mode | margin_factor | error | 131 | party2 | ETH/FEB23 | cross margin | | | 132 133 And the parties should have the following margin levels: 134 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 135 | party2 | ETH/FEB23 | 1581 | 1739 | 1897 | 2213 | cross margin | 0 | 0 | 136 137 And the parties should have the following margin levels: 138 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 139 | party1 | ETH/FEB23 | 4742 | 5216 | 5690 | 6638 | cross margin | 0 | 0 | 140 141 When the network moves ahead "1" blocks 142 #AC0019-MCAL-142:switch to isolated margin with position and with orders with margin factor such that there is insufficient balance in the general account in continuous mode 143 And the parties submit update margin mode: 144 | party | market | margin_mode | margin_factor | error | 145 | party1 | ETH/FEB23 | isolated margin | 0.9 | insufficient balance in general account to cover for required order margin | 146 Then the parties should have the following account balances: 147 | party | asset | market id | margin | general | bond | 148 | party1 | USD | ETH/FEB23 | 5689 | 21861 | 1000 | 149 150 And the parties should have the following margin levels: 151 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 152 | party1 | ETH/FEB23 | 4742 | 5216 | 5690 | 6638 | cross margin | 0 | 0 | 153 154 #AC0019-MCAL-123:switch to isolated margin with position and with orders successful in auction 155 #required position margin: 15800*0.6=9480 156 #maintenance margin for position: 15800*0.25+0.1*15800=5530 157 #initial margin for position: 5530*1.2=6636 158 # @jiajia there's insufficient in the general account here: 159 # for this switch to work they need 22755 in their general account, they only have 21861 160 # requiredPositionMargin 9480 161 # requireOrderMargin 18964.8 162 # total required: 9480 + 18964 - 5689 = 22,755 163 And the parties submit update margin mode: 164 | party | market | margin_mode | margin_factor | error | 165 | party1 | ETH/FEB23 | isolated margin | 0.6 | insufficient balance in general account to cover for required order margin | 166 167 #AC0019-MCAL-124:switch to isolated margin with position and with orders successful in continuous mode 168 And the parties submit update margin mode: 169 | party | market | margin_mode | margin_factor | error | 170 | party1 | ETH/FEB23 | isolated margin | 0.55 | | 171 172 Then the parties should have the following account balances: 173 | party | asset | market id | margin | general | bond | 174 | party1 | USD | ETH/FEB23 | 8690 | 1476 | 1000 | 175 176 And the parties should have the following margin levels: 177 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 178 | party1 | ETH/FEB23 | 5530 | 0 | 6636 | 0 | isolated margin | 0.55 | 17384 | 179 180 #AC0019-MCAL-141:switch to cross margin with position and with orders successful in auction 181 And the parties submit update margin mode: 182 | party | market | margin_mode | margin_factor | error | 183 | party1 | ETH/FEB23 | cross margin | | | 184 185 #AC0019-MCAL-036: When the party switches to cross margin mode, the margin accounts will not be updated until the next MTM 186 When the network moves ahead "1" blocks 187 Then the parties should have the following account balances: 188 | party | asset | market id | margin | general | bond | 189 | party1 | USD | ETH/FEB23 | 26074 | 1476 | 1000 | 190 191 And the parties should have the following margin levels: 192 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 193 | party1 | ETH/FEB23 | 8691 | 9560 | 10429 | 12167 | cross margin | 0 | 0 | 194 195 And the market data for the market "ETH/FEB23" should be: 196 | mark price | trading mode | 197 | 15800 | TRADING_MODE_MONITORING_AUCTION | 198 199 #AC0019-MCAL-119:switch to isolated margin without position and no orders successful in auction 200 And the parties submit update margin mode: 201 | party | market | margin_mode | margin_factor | error | 202 | party3 | ETH/FEB23 | isolated margin | 0.4 | | 203 And the parties should have the following margin levels: 204 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 205 | party3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 206 207 #AC0019-MCAL-126:increase margin factor without position and no orders successful in auction 208 And the parties submit update margin mode: 209 | party | market | margin_mode | margin_factor | error | 210 | party3 | ETH/FEB23 | isolated margin | 0.6 | | 211 And the parties should have the following margin levels: 212 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 213 | party3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.6 | 0 | 214 215 #AC0019-MCAL-127:increase margin factor without position and no orders successful in auction 216 And the parties submit update margin mode: 217 | party | market | margin_mode | margin_factor | error | 218 | party3 | ETH/FEB23 | isolated margin | 0.65 | | 219 And the parties should have the following margin levels: 220 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 221 | party3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.65 | 0 | 222 223 #AC0019-MCAL-135:switch to cross margin without position and no orders successful in auction 224 And the parties submit update margin mode: 225 | party | market | margin_mode | margin_factor | error | 226 | party3 | ETH/FEB23 | cross margin | 0.4 | | 227 And the parties should have the following margin levels: 228 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 229 | party3 | ETH/FEB23 | 0 | 0 | 0 | 0 | cross margin | 0 | 0 | 230 231 #AC0019-MCAL-125:switch to isolated margin with position and orders successful in auction 232 And the parties submit update margin mode: 233 | party | market | margin_mode | margin_factor | error | 234 | party1 | ETH/FEB23 | isolated margin | 0.55 | | 235 And the parties should have the following margin levels: 236 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 237 | party1 | ETH/FEB23 | 5530 | 0 | 6636 | 0 | isolated margin | 0.55 | 17384 | 238 239 #AC0019-MCAL-133:increase margin factor in isolated margin with position and with orders successful in auction 240 And the parties submit update margin mode: 241 | party | market | margin_mode | margin_factor | error | 242 | party1 | ETH/FEB23 | isolated margin | 0.56 | | 243 And the parties should have the following margin levels: 244 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 245 | party1 | ETH/FEB23 | 5530 | 0 | 6636 | 0 | isolated margin | 0.56 | 17700 | 246 247 #AC0019-MCAL-129:increase margin factor in isolated margin with position and no orders successful in auction 248 And the parties submit update margin mode: 249 | party | market | margin_mode | margin_factor | error | 250 | party4 | ETH/FEB23 | isolated margin | 0.5 | | 251 And the parties should have the following margin levels: 252 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 253 | party4 | ETH/FEB23 | 5530 | 0 | 6636 | 0 | isolated margin | 0.5 | 0 | 254 And the parties submit update margin mode: 255 | party | market | margin_mode | margin_factor | error | 256 | party4 | ETH/FEB23 | isolated margin | 0.6 | | 257 And the parties should have the following margin levels: 258 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 259 | party4 | ETH/FEB23 | 5530 | 0 | 6636 | 0 | isolated margin | 0.6 | 0 | 260 261 #AC0019-MCAL-140:switch to cross margin with position and orders successful in auction 262 And the parties submit update margin mode: 263 | party | market | margin_mode | margin_factor | error | 264 | party1 | ETH/FEB23 | cross margin | 0.4 | | 265 And the parties should have the following margin levels: 266 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 267 | party1 | ETH/FEB23 | 8691 | 9560 | 10429 | 12167 | cross margin | 0 | 0 | 268 269 #AC0019-MCAL-139:switch to cross margin without position and with orders successful in auction 270 And the parties submit update margin mode: 271 | party | market | margin_mode | margin_factor | error | 272 | party5 | ETH/FEB23 | cross margin | | | 273 And the parties should have the following margin levels: 274 | party | market id | maintenance | margin mode | margin factor | order | 275 | party5 | ETH/FEB23 | 1580 | cross margin | 0 | 0 | 276