code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-068.feature (about) 1 Feature: Test order amendment which lead to cancellation of all orders and fund returned to the genral account, and active positions shoule be untouched and active 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: 001 when party has open position, check margin and general account when mark price increases and MTM, then closeout (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 | 275500 | 23 24 And the parties place the following orders: 25 | party | market id | side | volume | price | resulting trades | type | tif | reference | 26 | buySideProvider | ETH/FEB23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 27 | buySideProvider | ETH/FEB23 | buy | 6 | 15800 | 0 | TYPE_LIMIT | TIF_GTC | | 28 | buySideProvider | ETH/FEB23 | buy | 10 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 29 | party1 | ETH/FEB23 | sell | 10 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 30 | party1 | ETH/FEB23 | sell | 2 | 49920 | 0 | TYPE_LIMIT | TIF_GTC | sell-1 | 31 | party1 | ETH/FEB23 | sell | 4 | 49940 | 0 | TYPE_LIMIT | TIF_GTC | sell-2 | 32 | sellSideProvider | ETH/FEB23 | sell | 1 | 200000 | 0 | TYPE_LIMIT | TIF_GTC | | 33 | sellSideProvider | ETH/FEB23 | sell | 10 | 200100 | 0 | TYPE_LIMIT | TIF_GTC | | 34 35 When the network moves ahead "2" blocks 36 Then the mark price should be "15900" for the market "ETH/FEB23" 37 38 And the parties should have the following margin levels: 39 | party | market id | maintenance | initial | 40 | party1 | ETH/FEB23 | 65190 | 78228 | 41 #margin = min(3*(100000-15900), 15900*(0.25))+0.1*15900=5565 42 43 Then the parties should have the following account balances: 44 | party | asset | market id | margin | general | 45 | party1 | USD | ETH/FEB23 | 78228 | 197272 | 46 47 #switch to isolated margin 48 And the parties submit update margin mode: 49 | party | market | margin_mode | margin_factor | 50 | party1 | ETH/FEB23 | isolated margin | 0.6 | 51 52 And the parties should have the following margin levels: 53 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 54 | party1 | ETH/FEB23 | 55650 | 0 | 66780 | 0 | isolated margin | 0.6 | 179760 | 55 56 Then the parties should have the following account balances: 57 | party | asset | market id | margin | general | order margin | 58 | party1 | USD | ETH/FEB23 | 95400 | 340 | 179760 | 59 60 #AC 0019-MCAL-068 amend the order (increase size) so that new side margin + margin account balance < maintenance margin, the remainding should be stopped 61 When the parties amend the following orders: 62 | party | reference | price | size delta | tif | error | 63 | party1 | sell-1 | 49940 | 2 | TIF_GTC | margin check failed | 64 Then the parties should have the following account balances: 65 | party | asset | market id | margin | general | order margin | 66 | party1 | USD | ETH/FEB23 | 95400 | 180100 | 0 | 67 68 And the orders should have the following status: 69 | party | reference | status | 70 | party1 | sell-1 | STATUS_STOPPED | 71 | party1 | sell-2 | STATUS_STOPPED | 72 73 And the parties place the following orders: 74 | party | market id | side | volume | price | resulting trades | type | tif | reference | 75 | party1 | ETH/FEB23 | sell | 2 | 49920 | 0 | TYPE_LIMIT | TIF_GTC | sell-3 | 76 | party1 | ETH/FEB23 | sell | 4 | 49940 | 0 | TYPE_LIMIT | TIF_GTC | sell-4 | 77 78 Then the parties should have the following account balances: 79 | party | asset | market id | margin | general | order margin | 80 | party1 | USD | ETH/FEB23 | 95400 | 340 | 179760 | 81 82 #check amendment does happened when new side margin + margin account balance > maintenance margin 83 When the parties amend the following orders: 84 | party | reference | price | size delta | tif | error | 85 | party1 | sell-3 | 49920 | -2 | TIF_GTC | | 86 Then the parties should have the following account balances: 87 | party | asset | market id | margin | general | order margin | 88 | party1 | USD | ETH/FEB23 | 95400 | 60244 | 119856 | 89 90 And the orders should have the following status: 91 | party | reference | status | 92 | party1 | sell-3 | STATUS_CANCELLED | 93 | party1 | sell-4 | STATUS_ACTIVE | 94 95 And the order book should have the following volumes for market "ETH/FEB23": 96 | side | price | volume | 97 | buy | 14900 | 10 | 98 | buy | 15800 | 6 | 99 | sell | 49920 | 0 | 100 | sell | 200000 | 1 | 101 102 #check amendment does happened when new side margin + margin account balance > maintenance margin 103 When the parties amend the following orders: 104 | party | reference | price | size delta | tif | error | 105 | party1 | sell-4 | 49910 | 0 | TIF_GTC | | 106 Then the parties should have the following account balances: 107 | party | asset | market id | margin | general | order margin | 108 | party1 | USD | ETH/FEB23 | 95400 | 60316 | 119784 | 109 110 And the orders should have the following status: 111 | party | reference | status | 112 | party1 | sell-3 | STATUS_CANCELLED | 113 | party1 | sell-4 | STATUS_ACTIVE | 114 115 #AC 0019-MCAL-074 amend the order (increase price) so that new side margin + margin account balance < maintenance margin, the remainding should be stopped 116 When the parties amend the following orders: 117 | party | reference | price | size delta | tif | error | 118 | party1 | sell-4 | 109910 | 0 | TIF_GTC | margin check failed | 119 Then the parties should have the following account balances: 120 | party | asset | market id | margin | general | order margin | 121 | party1 | USD | ETH/FEB23 | 95400 | 180100 | 0 | 122 123 And the orders should have the following status: 124 | party | reference | status | 125 | party1 | sell-3 | STATUS_CANCELLED | 126 | party1 | sell-4 | STATUS_STOPPED | 127 128 And the parties place the following orders: 129 | party | market id | side | volume | price | resulting trades | type | tif | reference | 130 | party1 | ETH/FEB23 | sell | 2 | 49920 | 0 | TYPE_LIMIT | TIF_GTC | sell-5 | 131 | party1 | ETH/FEB23 | sell | 4 | 49940 | 0 | TYPE_LIMIT | TIF_GTC | sell-6 | 132 133 #AC 0019-MCAL-075 amend the order (decrease size, increase price) so that new side margin + margin account balance < maintenance margin, the remainding should be stopped 134 When the parties amend the following orders: 135 | party | reference | price | size delta | tif | error | 136 | party1 | sell-5 | 109910 | -1 | TIF_GTC | margin check failed | 137 Then the parties should have the following account balances: 138 | party | asset | market id | margin | general | order margin | 139 | party1 | USD | ETH/FEB23 | 95400 | 180100 | 0 | 140 141 And the orders should have the following status: 142 | party | reference | status | 143 | party1 | sell-5 | STATUS_STOPPED | 144 | party1 | sell-6 | STATUS_STOPPED | 145 146 And the parties place the following orders: 147 | party | market id | side | volume | price | resulting trades | type | tif | reference | 148 | party1 | ETH/FEB23 | sell | 2 | 49920 | 0 | TYPE_LIMIT | TIF_GTC | sell-7 | 149 | party1 | ETH/FEB23 | sell | 4 | 49940 | 0 | TYPE_LIMIT | TIF_GTC | sell-8 | 150 151 #AC 0019-MCAL-076 amend the order (increase size, decrease price) so that new side margin + margin account balance < maintenance margin, the remainding should be stopped 152 When the parties amend the following orders: 153 | party | reference | price | size delta | tif | error | 154 | party1 | sell-7 | 19920 | 5 | TIF_GTC | margin check failed | 155 Then the parties should have the following account balances: 156 | party | asset | market id | margin | general | order margin | 157 | party1 | USD | ETH/FEB23 | 95400 | 180100 | 0 | 158 159 And the orders should have the following status: 160 | party | reference | status | 161 | party1 | sell-7 | STATUS_STOPPED | 162 | party1 | sell-8 | STATUS_STOPPED | 163 164