code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-100.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.01 | 0 | default-futures | 16 17 Scenario: 001 closeout when party's open position is under maintenance level (0019-MCAL-070) 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 | 172500 | 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 #AC0019-MCAL-100:switch to isolated margin with no position and no order (before the first order ever has been sent) in continuous mode 45 And the parties should have the following margin levels: 46 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 47 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 48 49 Then the parties should have the following account balances: 50 | party | asset | market id | margin | general | 51 | party1 | USD | ETH/FEB23 | 0 | 171500 | 52 53 When the network moves ahead "2" blocks 54 55 #switch to cross margin 56 And the parties submit update margin mode: 57 | party | market | margin_mode | 58 | party1 | ETH/FEB23 | cross margin | 59 60 #AC0019-MCAL-101:switch back to cross margin with no position and no order in continuous mode 61 And the parties should have the following margin levels: 62 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 63 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | cross margin | 0 | 0 | 64 65 Then the parties should have the following account balances: 66 | party | asset | market id | margin | general | 67 | party1 | USD | ETH/FEB23 | 0 | 171500 | 68 69 And the parties place the following orders: 70 | party | market id | side | volume | price | resulting trades | type | tif | reference | 71 | party1 | ETH/FEB23 | buy | 6 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | b-1 | 72 When the network moves ahead "1" blocks 73 74 And the parties should have the following margin levels: 75 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 76 | party1 | ETH/FEB23 | 9540 | 10494 | 11448 | 13356 | cross margin | 0 | 0 | 77 78 #AC0019-MCAL-106:switch to isolated margin without position and with orders with margin factor such that position margin is < initial should fail in continuous 79 #order margin: 6*15800*0.11=10428 80 #maintenance margin level in cross margin: 15900*0.1*6=9540 81 And the parties submit update margin mode: 82 | party | market | margin_mode | margin_factor | error | 83 | party1 | ETH/FEB23 | isolated margin | 0.2 | | 84 And the parties should have the following margin levels: 85 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 86 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.2 | 18960 | 87 88 And the orders should have the following status: 89 | party | reference | status | 90 | party1 | b-1 | STATUS_ACTIVE | 91 92 Scenario: 002 switch to isolated margin mode without position and no order (0019-MCAL-110) 93 Given the parties deposit on asset's general account the following amount: 94 | party | asset | amount | 95 | buySideProvider | USD | 100000000000 | 96 | sellSideProvider | USD | 100000000000 | 97 | party1 | USD | 22000 | 98 99 When the parties submit the following liquidity provision: 100 | id | party | market id | commitment amount | fee | lp type | 101 | lp1 | party1 | ETH/FEB23 | 1000 | 0.1 | submission | 102 103 And the parties place the following orders: 104 | party | market id | side | volume | price | resulting trades | type | tif | reference | 105 | buySideProvider | ETH/FEB23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 106 | buySideProvider | ETH/FEB23 | buy | 3 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 107 | sellSideProvider | ETH/FEB23 | sell | 1 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | s-1 | 108 | sellSideProvider | ETH/FEB23 | sell | 1 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 109 | sellSideProvider | ETH/FEB23 | sell | 10 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 110 111 When the network moves ahead "2" blocks 112 Then the mark price should be "15900" for the market "ETH/FEB23" 113 114 #switch to isolated margin 115 And the parties submit update margin mode: 116 | party | market | margin_mode | margin_factor | error | 117 | party1 | ETH/FEB23 | isolated margin | 0.4 | | 118 119 #AC0019-MCAL-100:switch to isolated margin with no position and no order (before the first order ever has been sent) in continuous mode 120 And the parties should have the following margin levels: 121 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 122 | party1 | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.4 | 0 | 123 124 Then the parties should have the following account balances: 125 | party | asset | market id | margin | general | bond | 126 | party1 | USD | ETH/FEB23 | 0 | 21000 | 1000 | 127 128 #AC0019-MCAL-117:update margin factor when already in isolated mode to the same cases as in switch to isolated failures. 129 And the parties submit update margin mode: 130 | party | market | margin_mode | margin_factor | error | 131 | party1 | ETH/FEB23 | isolated margin | 0.4 | | 132 133 #switch back to cross margin 134 And the parties submit update margin mode: 135 | party | market | margin_mode | margin_factor | error | 136 | party1 | ETH/FEB23 | cross margin | | | 137 When the network moves ahead "2" blocks 138 139 And the parties place the following orders: 140 | party | market id | side | volume | price | resulting trades | type | tif | reference | 141 | party1 | ETH/FEB23 | sell | 5 | 15900 | 1 | TYPE_LIMIT | TIF_GTC | s-2 | 142 143 And the parties should have the following margin levels: 144 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 145 | party1 | ETH/FEB23 | 7950 | 8745 | 9540 | 11130 | cross margin | 0 | 0 | 146 147 #AC0019-MCAL-115:switch to isolate margin with out of range margin factor 148 And the parties submit update margin mode: 149 | party | market | margin_mode | margin_factor | error | 150 | party1 | ETH/FEB23 | isolated margin | 0.1 | margin factor (0.1) must be greater than max(riskFactorLong (0.1), riskFactorShort (0.1)) + linearSlippageFactor (0.01) | 151 152 #this number should be validated with correct message 153 And the parties submit update margin mode: 154 | party | market | margin_mode | margin_factor | error | 155 | party1 | ETH/FEB23 | isolated margin | 1.2 | insufficient balance in general account to cover for required order margin | 156 157 And the parties submit update margin mode: 158 | party | market | margin_mode | margin_factor | error | 159 | party1 | ETH/FEB23 | isolated margin | -0.2 | margin factor (-0.2) must be greater than max(riskFactorLong (0.1), riskFactorShort (0.1)) + linearSlippageFactor (0.01) | 160 161 #AC0019-MCAL-114: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 162 And the parties submit update margin mode: 163 | party | market | margin_mode | margin_factor | error | 164 | party1 | ETH/FEB23 | isolated margin | 0.4 | insufficient balance in general account to cover for required order margin | 165 166 #AC0019-MCAL-116:submit update margin mode transaction with no state change (already in cross margin, "change" to cross margin, or already in isolated, submit with same margin factor) 167 And the parties submit update margin mode: 168 | party | market | margin_mode | margin_factor | error | 169 | party1 | ETH/FEB23 | cross margin | | | 170 171