code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-204.feature (about) 1 Feature: Test switch between 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 17 Scenario: Amending an order to make it match while in isolated mode can fail if the margin requirements are not met. 18 Given the parties deposit on asset's general account the following amount: 19 | party | asset | amount | 20 | buySideProvider | USD | 100000000000 | 21 | sellSideProvider | USD | 100000000000 | 22 | party1 | USD | 16000 | 23 When the parties submit the following liquidity provision: 24 | id | party | market id | commitment amount | fee | lp type | 25 | lp1 | party1 | ETH/FEB23 | 1000 | 0.1 | submission | 26 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 | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 30 | buySideProvider | ETH/FEB23 | buy | 10 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 31 | buySideProvider | ETH/FEB23 | sell | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 32 | sellSideProvider | ETH/FEB23 | sell | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | s-1 | 33 | sellSideProvider | ETH/FEB23 | sell | 1 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 34 | sellSideProvider | ETH/FEB23 | sell | 10 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 35 36 When the network moves ahead "2" blocks 37 Then the mark price should be "15900" for the market "ETH/FEB23" 38 39 #switch to isolated margin 40 And the parties submit update margin mode: 41 | party | market | margin_mode | margin_factor | 42 | party1 | ETH/FEB23 | isolated margin | 0.4 | 43 44 And the parties should have the following margin levels: 45 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 46 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 47 48 Then the parties should have the following account balances: 49 | party | asset | market id | margin | general | 50 | party1 | USD | ETH/FEB23 | 0 | 15000 | 51 52 # Now place an order that sits on the book which we can amend to match later 53 And the parties place the following orders: 54 | party | market id | side | volume | price | resulting trades | type | tif | reference | 55 | sellSideProvider | ETH/FEB23 | sell | 1 | 20000 | 0 | TYPE_LIMIT | TIF_GTC | sell-1 | 56 | party1 | ETH/FEB23 | buy | 1 | 19000 | 0 | TYPE_LIMIT | TIF_GTC | party1-buy | 57 58 And the parties should have the following margin levels: 59 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 60 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 7600 | 61 62 Then the parties should have the following account balances: 63 | party | asset | market id | margin | general | 64 | party1 | USD | ETH/FEB23 | 0 | 7400 | 65 66 # Set up two orders which do not cross so we can amend one of them to force the trade 67 Then the order book should have the following volumes for market "ETH/FEB23": 68 | side | price | volume | 69 | buy | 19000 | 1 | 70 | sell | 20000 | 1 | 71 72 # This will make the two orders cross but will fail the margin check once the order has already been cancelled/replaced. 73 When the parties amend the following orders: 74 | party | reference | price | tif | error | 75 | party1| party1-buy | 20001 | TIF_GTC | margin check failed | 76 77 # party 1 no longer has it's order due to insufficient margin 78 And the parties should have the following margin levels: 79 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 80 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 81 82 Then the orders should have the following status: 83 | party | reference | status | 84 | party1 | party1-buy | STATUS_STOPPED | 85 | sellSideProvider | sell-1 | STATUS_ACTIVE | 86 87 # The amended order should be removed from the book and the order it was trying to match with will be restored 88 Then the order book should have the following volumes for market "ETH/FEB23": 89 | side | price | volume | 90 | buy | 19000 | 0 | 91 | sell | 20000 | 1 | 92 93