code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-205.feature (about) 1 Feature: Submitting an order that with isolated margin when the party doesn't have sufficient balance to cover the new order 2 Background: 3 Given the average block duration is "1" 4 And the following network parameters are set: 5 | name | value | 6 | network.markPriceUpdateMaximumFrequency | 0s | 7 | limits.markets.maxPeggedOrders | 6 | 8 | market.auction.minimumDuration | 1 | 9 And the price monitoring named "my-price-monitoring-1": 10 | horizon | probability | auction extension | 11 | 5 | 0.99 | 6 | 12 13 And the liquidity monitoring parameters: 14 | name | triggering ratio | time window | scaling factor | 15 | lqm-params | 0.00 | 24h | 1e-9 | 16 And the simple risk model named "simple-risk-model": 17 | long | short | max move up | min move down | probability of trading | 18 | 0.1 | 0.2 | 100 | -100 | 0.2 | 19 And the markets: 20 | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | sla params | 21 | ETH/FEB23 | ETH | USD | lqm-params | simple-risk-model | default-margin-calculator | 1 | default-none | my-price-monitoring-1 | default-eth-for-future | 0.000125 | 0 | 2 | default-futures | 22 23 @MCAL205 24 Scenario: The new order would result in trades does not change the state of the book 25 Given the parties deposit on asset's general account the following amount: 26 | party | asset | amount | 27 | trader1 | USD | 100000000000 | 28 | trader2 | USD | 100000000000 | 29 | trader3 | USD | 5000 | 30 | trader4 | USD | 100000000000 | 31 | trader5 | USD | 100000000000 | 32 | lprov1 | USD | 100000000000 | 33 34 And the parties submit the following liquidity provision: 35 | id | party | market id | commitment amount | fee | lp type | 36 | lp1 | lprov1 | ETH/FEB23 | 1000 | 0.1 | submission | 37 38 And the parties place the following orders with ticks: 39 | party | market id | side | volume | price | resulting trades | type | tif | reference | 40 | trader1 | ETH/FEB23 | buy | 1000 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 41 | trader1 | ETH/FEB23 | buy | 300 | 15600 | 0 | TYPE_LIMIT | TIF_GTC | | 42 | lprov1 | ETH/FEB23 | buy | 100 | 15700 | 0 | TYPE_LIMIT | TIF_GTC | lp-buy-1 | 43 | trader4 | ETH/FEB23 | buy | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 44 | lprov1 | ETH/FEB23 | sell | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | lp-sell-1 | 45 | trader2 | ETH/FEB23 | sell | 600 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | t2-sell-1 | 46 | trader2 | ETH/FEB23 | sell | 300 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 47 | trader2 | ETH/FEB23 | sell | 1000 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 48 49 When the network moves ahead "2" blocks 50 Then the market data for the market "ETH/FEB23" should be: 51 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 52 | 15800 | TRADING_MODE_CONTINUOUS | 5 | 15701 | 15899 | 0 | 1000 | 300 | 53 54 When the parties place the following pegged orders: 55 | party | market id | side | volume | pegged reference | offset | reference | 56 | lprov1 | ETH/FEB23 | buy | 100 | BID | 10 | buy_peg_1 | 57 | lprov1 | ETH/FEB23 | buy | 200 | BID | 20 | buy_peg_2 | 58 59 Then the parties should have the following margin levels: 60 | party | market id | maintenance | margin mode | margin factor | order | 61 | lprov1 | ETH/FEB23 | 9486 | cross margin | 0 | 0 | 62 | trader1 | ETH/FEB23 | 20540 | cross margin | 0 | 0 | 63 | trader4 | ETH/FEB23 | 4746 | cross margin | 0 | 0 | 64 And the parties should have the following account balances: 65 | party | asset | market id | margin | general | bond | 66 | lprov1 | USD | ETH/FEB23 | 11383 | 99999987617 | 1000 | 67 | trader1 | USD | ETH/FEB23 | 23496 | 99999976504 | | 68 | trader4 | USD | ETH/FEB23 | 5688 | 99999994312 | | 69 70 When the parties submit update margin mode: 71 | party | market | margin_mode | margin_factor | error | 72 | trader3 | ETH/FEB23 | isolated margin | 0.3 | | 73 Then the parties should have the following margin levels: 74 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 75 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 0 | 76 77 # trader3 to place first order in isolated margin mode, check balance and margin levels 78 When the parties place the following orders with ticks: 79 | party | market id | side | volume | price | resulting trades | type | tif | reference | 80 | trader3 | ETH/FEB23 | buy | 100 | 15500 | 0 | TYPE_LIMIT | TIF_GTC | t3-first | 81 Then the parties should have the following margin levels: 82 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 83 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 84 And the order book should have the following volumes for market "ETH/FEB23": 85 | volume | price | side | 86 | 1000 | 200100 | sell | 87 | 300 | 200000 | sell | 88 | 600 | 15802 | sell | 89 | 100 | 15700 | buy | 90 | 100 | 15690 | buy | 91 | 200 | 15680 | buy | 92 | 300 | 15600 | buy | 93 | 100 | 15500 | buy | 94 | 1000 | 14900 | buy | 95 And the parties should have the following account balances: 96 | party | asset | market id | margin | general | order margin | 97 | trader3 | USD | ETH/FEB23 | 0 | 350 | 4650 | 98 99 # trader3 submits an order that would result in a trade, but they don't have enough margin 100 # Make sure the book is in the correct state, and the order gets rejected. 101 When the parties place the following orders with ticks: 102 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 103 | trader3 | ETH/FEB23 | buy | 50 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | t3-second | margin check failed | 104 Then the parties should have the following margin levels: 105 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 106 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 107 And the parties should have the following account balances: 108 | party | asset | market id | margin | general | order margin | 109 | trader3 | USD | ETH/FEB23 | 0 | 350 | 4650 | 110 And the order book should have the following volumes for market "ETH/FEB23": 111 | volume | price | side | 112 | 1000 | 200100 | sell | 113 | 300 | 200000 | sell | 114 | 600 | 15802 | sell | 115 | 100 | 15700 | buy | 116 | 100 | 15690 | buy | 117 | 200 | 15680 | buy | 118 | 300 | 15600 | buy | 119 | 100 | 15500 | buy | 120 | 1000 | 14900 | buy | 121 # Now ensure the order is still on the book, and we can trade 122 When the parties place the following orders with ticks: 123 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 124 | trader5 | ETH/FEB23 | buy | 50 | 15802 | 1 | TYPE_LIMIT | TIF_GTC | t5-first | | 125 Then the order book should have the following volumes for market "ETH/FEB23": 126 | volume | price | side | 127 | 1000 | 200100 | sell | 128 | 300 | 200000 | sell | 129 | 550 | 15802 | sell | 130 | 100 | 15700 | buy | 131 | 100 | 15690 | buy | 132 | 200 | 15680 | buy | 133 | 300 | 15600 | buy | 134 | 100 | 15500 | buy | 135 | 1000 | 14900 | buy | 136 137 @MCAL205 138 Scenario: The new order doesn't result in trades still does not change the state of the book 139 Given the parties deposit on asset's general account the following amount: 140 | party | asset | amount | 141 | trader1 | USD | 100000000000 | 142 | trader2 | USD | 100000000000 | 143 | trader3 | USD | 5000 | 144 | trader4 | USD | 100000000000 | 145 | trader5 | USD | 100000000000 | 146 | lprov1 | USD | 100000000000 | 147 148 And the parties submit the following liquidity provision: 149 | id | party | market id | commitment amount | fee | lp type | 150 | lp1 | lprov1 | ETH/FEB23 | 1000 | 0.1 | submission | 151 152 And the parties place the following orders with ticks: 153 | party | market id | side | volume | price | resulting trades | type | tif | reference | 154 | trader1 | ETH/FEB23 | buy | 1000 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 155 | trader1 | ETH/FEB23 | buy | 300 | 15600 | 0 | TYPE_LIMIT | TIF_GTC | | 156 | lprov1 | ETH/FEB23 | buy | 100 | 15700 | 0 | TYPE_LIMIT | TIF_GTC | lp-buy-1 | 157 | trader4 | ETH/FEB23 | buy | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 158 | lprov1 | ETH/FEB23 | sell | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | lp-sell-1 | 159 | trader2 | ETH/FEB23 | sell | 600 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | t2-sell-1 | 160 | trader2 | ETH/FEB23 | sell | 300 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 161 | trader2 | ETH/FEB23 | sell | 1000 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 162 163 When the network moves ahead "2" blocks 164 Then the market data for the market "ETH/FEB23" should be: 165 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 166 | 15800 | TRADING_MODE_CONTINUOUS | 5 | 15701 | 15899 | 0 | 1000 | 300 | 167 168 When the parties place the following pegged orders: 169 | party | market id | side | volume | pegged reference | offset | reference | 170 | lprov1 | ETH/FEB23 | buy | 100 | BID | 10 | buy_peg_1 | 171 | lprov1 | ETH/FEB23 | buy | 200 | BID | 20 | buy_peg_2 | 172 173 Then the parties should have the following margin levels: 174 | party | market id | maintenance | margin mode | margin factor | order | 175 | lprov1 | ETH/FEB23 | 9486 | cross margin | 0 | 0 | 176 | trader1 | ETH/FEB23 | 20540 | cross margin | 0 | 0 | 177 | trader4 | ETH/FEB23 | 4746 | cross margin | 0 | 0 | 178 And the parties should have the following account balances: 179 | party | asset | market id | margin | general | bond | 180 | lprov1 | USD | ETH/FEB23 | 11383 | 99999987617 | 1000 | 181 | trader1 | USD | ETH/FEB23 | 23496 | 99999976504 | | 182 | trader4 | USD | ETH/FEB23 | 5688 | 99999994312 | | 183 184 When the parties submit update margin mode: 185 | party | market | margin_mode | margin_factor | error | 186 | trader3 | ETH/FEB23 | isolated margin | 0.3 | | 187 Then the parties should have the following margin levels: 188 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 189 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 0 | 190 191 # trader3 to place first order in isolated margin mode, check balance and margin levels 192 When the parties place the following orders with ticks: 193 | party | market id | side | volume | price | resulting trades | type | tif | reference | 194 | trader3 | ETH/FEB23 | buy | 100 | 15500 | 0 | TYPE_LIMIT | TIF_GTC | t3-first | 195 Then the parties should have the following margin levels: 196 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 197 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 198 And the order book should have the following volumes for market "ETH/FEB23": 199 | volume | price | side | 200 | 1000 | 200100 | sell | 201 | 300 | 200000 | sell | 202 | 600 | 15802 | sell | 203 | 100 | 15700 | buy | 204 | 100 | 15690 | buy | 205 | 200 | 15680 | buy | 206 | 300 | 15600 | buy | 207 | 100 | 15500 | buy | 208 | 1000 | 14900 | buy | 209 And the parties should have the following account balances: 210 | party | asset | market id | margin | general | order margin | 211 | trader3 | USD | ETH/FEB23 | 0 | 350 | 4650 | 212 213 # trader3 submits an order that would result in a trade, but they don't have enough margin 214 # Make sure the book is in the correct state, and the order gets rejected. 215 When the parties place the following orders with ticks: 216 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 217 | trader3 | ETH/FEB23 | buy | 50 | 15801 | 0 | TYPE_LIMIT | TIF_GTC | t3-second | margin check failed | 218 Then the parties should have the following margin levels: 219 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 220 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 221 And the parties should have the following account balances: 222 | party | asset | market id | margin | general | order margin | 223 | trader3 | USD | ETH/FEB23 | 0 | 350 | 4650 | 224 And the order book should have the following volumes for market "ETH/FEB23": 225 | volume | price | side | 226 | 1000 | 200100 | sell | 227 | 300 | 200000 | sell | 228 | 600 | 15802 | sell | 229 | 100 | 15700 | buy | 230 | 100 | 15690 | buy | 231 | 200 | 15680 | buy | 232 | 300 | 15600 | buy | 233 | 100 | 15500 | buy | 234 | 1000 | 14900 | buy | 235 # Now ensure the order is still on the book, and we can trade 236 When the parties place the following orders with ticks: 237 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 238 | trader5 | ETH/FEB23 | buy | 50 | 15802 | 1 | TYPE_LIMIT | TIF_GTC | t5-first | | 239 | trader5 | ETH/FEB23 | buy | 549 | 15802 | 1 | TYPE_LIMIT | TIF_GTC | t5-first | | 240 Then the order book should have the following volumes for market "ETH/FEB23": 241 | volume | price | side | 242 | 1000 | 200100 | sell | 243 | 300 | 200000 | sell | 244 | 1 | 15802 | sell | 245 | 100 | 15700 | buy | 246 | 100 | 15690 | buy | 247 | 200 | 15680 | buy | 248 | 300 | 15600 | buy | 249 | 100 | 15500 | buy | 250 | 1000 | 14900 | buy | 251 252 @MCAL205 253 Scenario: The new order would result in trades, enough margin for both orders, not for orders and trades. does not change the state of the book 254 Given the parties deposit on asset's general account the following amount: 255 | party | asset | amount | 256 | trader1 | USD | 100000000000 | 257 | trader2 | USD | 100000000000 | 258 | trader3 | USD | 4750 | 259 | trader4 | USD | 100000000000 | 260 | trader5 | USD | 100000000000 | 261 | lprov1 | USD | 100000000000 | 262 263 And the parties submit the following liquidity provision: 264 | id | party | market id | commitment amount | fee | lp type | 265 | lp1 | lprov1 | ETH/FEB23 | 1000 | 0.1 | submission | 266 267 And the parties place the following orders with ticks: 268 | party | market id | side | volume | price | resulting trades | type | tif | reference | 269 | trader1 | ETH/FEB23 | buy | 1000 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 270 | trader1 | ETH/FEB23 | buy | 300 | 15600 | 0 | TYPE_LIMIT | TIF_GTC | | 271 | lprov1 | ETH/FEB23 | buy | 100 | 15700 | 0 | TYPE_LIMIT | TIF_GTC | lp-buy-1 | 272 | trader4 | ETH/FEB23 | buy | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 273 | lprov1 | ETH/FEB23 | sell | 300 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | lp-sell-1 | 274 | trader2 | ETH/FEB23 | sell | 6 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | t2-sell-1 | 275 | trader2 | ETH/FEB23 | sell | 300 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 276 | trader2 | ETH/FEB23 | sell | 1000 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 277 278 When the network moves ahead "2" blocks 279 Then the market data for the market "ETH/FEB23" should be: 280 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 281 | 15800 | TRADING_MODE_CONTINUOUS | 5 | 15701 | 15899 | 0 | 1000 | 300 | 282 283 When the parties place the following pegged orders: 284 | party | market id | side | volume | pegged reference | offset | reference | 285 | lprov1 | ETH/FEB23 | buy | 100 | BID | 10 | buy_peg_1 | 286 | lprov1 | ETH/FEB23 | buy | 200 | BID | 20 | buy_peg_2 | 287 288 Then the parties should have the following margin levels: 289 | party | market id | maintenance | margin mode | margin factor | order | 290 | trader1 | ETH/FEB23 | 20540 | cross margin | 0 | 0 | 291 | trader4 | ETH/FEB23 | 4746 | cross margin | 0 | 0 | 292 And the parties should have the following account balances: 293 | party | asset | market id | margin | general | bond | 294 | trader1 | USD | ETH/FEB23 | 23496 | 99999976504 | | 295 | trader4 | USD | ETH/FEB23 | 5688 | 99999994312 | | 296 297 When the parties submit update margin mode: 298 | party | market | margin_mode | margin_factor | error | 299 | trader3 | ETH/FEB23 | isolated margin | 0.3 | | 300 Then the parties should have the following margin levels: 301 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 302 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 0 | 303 304 # trader3 to place first order in isolated margin mode, check balance and margin levels 305 When the parties place the following orders with ticks: 306 | party | market id | side | volume | price | resulting trades | type | tif | reference | 307 | trader3 | ETH/FEB23 | buy | 100 | 15500 | 0 | TYPE_LIMIT | TIF_GTC | t3-first | 308 Then the parties should have the following margin levels: 309 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 310 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 311 And the order book should have the following volumes for market "ETH/FEB23": 312 | volume | price | side | 313 | 1000 | 200100 | sell | 314 | 300 | 200000 | sell | 315 | 6 | 15802 | sell | 316 | 100 | 15700 | buy | 317 | 100 | 15690 | buy | 318 | 200 | 15680 | buy | 319 | 300 | 15600 | buy | 320 | 100 | 15500 | buy | 321 | 1000 | 14900 | buy | 322 And the parties should have the following account balances: 323 | party | asset | market id | margin | general | order margin | 324 | trader3 | USD | ETH/FEB23 | 0 | 100 | 4650 | 325 326 # trader3 submits an order that would result in a trade, but they don't have enough margin 327 # Make sure the book is in the correct state, and the order gets rejected. 328 # The order + trade would require 4768 of total margin balance 329 When the parties place the following orders with ticks: 330 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 331 | trader3 | ETH/FEB23 | buy | 7 | 15802 | 0 | TYPE_LIMIT | TIF_GTC | t3-second | margin check failed | 332 Then the parties should have the following margin levels: 333 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 334 | trader3 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.3 | 4650 | 335 And the parties should have the following account balances: 336 | party | asset | market id | margin | general | order margin | 337 | trader3 | USD | ETH/FEB23 | 0 | 100 | 4650 | 338 And the order book should have the following volumes for market "ETH/FEB23": 339 | volume | price | side | 340 | 1000 | 200100 | sell | 341 | 300 | 200000 | sell | 342 | 6 | 15802 | sell | 343 | 100 | 15700 | buy | 344 | 100 | 15690 | buy | 345 | 200 | 15680 | buy | 346 | 300 | 15600 | buy | 347 | 100 | 15500 | buy | 348 | 1000 | 14900 | buy | 349 350 # Now ensure the order is still on the book, and we can trade 351 When the parties place the following orders with ticks: 352 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 353 | trader5 | ETH/FEB23 | buy | 5 | 15802 | 1 | TYPE_LIMIT | TIF_GTC | t5-first | | 354 Then the order book should have the following volumes for market "ETH/FEB23": 355 | volume | price | side | 356 | 1000 | 200100 | sell | 357 | 300 | 200000 | sell | 358 | 1 | 15802 | sell | 359 | 100 | 15700 | buy | 360 | 100 | 15690 | buy | 361 | 200 | 15680 | buy | 362 | 300 | 15600 | buy | 363 | 100 | 15500 | buy | 364 | 1000 | 14900 | buy | 365