code.vegaprotocol.io/vega@v0.79.0/core/integration/features/release-margins-issues.feature (about) 1 Feature: Test margin release on order cancel 2 3 Background: 4 Given the markets: 5 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 6 | ETH/DEC19 | ETH | ETH | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures | 7 And the oracles broadcast data signed with "0xDEADBEEF": 8 | name | value | 9 | prices.ETH.value | 42 | 10 And the following network parameters are set: 11 | name | value | 12 | network.markPriceUpdateMaximumFrequency | 0s | 13 14 @MarginRelease 15 Scenario: a party place a new order in the system, margin are updated, the order is closed, margin is 0ed 16 Given the parties deposit on asset's general account the following amount: 17 | party | asset | amount | 18 | partyGuy | ETH | 10000 | 19 | party1 | ETH | 1000000 | 20 | party2 | ETH | 1000000 | 21 | aux | ETH | 100000000000 | 22 | lpprov | ETH | 100000000000 | 23 24 When the parties submit the following liquidity provision: 25 | id | party | market id | commitment amount | fee | lp type | 26 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 27 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 28 29 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 30 Then the parties place the following orders: 31 | party | market id | side | volume | price | resulting trades | type | tif | 32 | aux | ETH/DEC19 | buy | 1 | 9 | 0 | TYPE_LIMIT | TIF_GTC | 33 | aux | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | 34 35 # Trigger an auction to set the mark price 36 When the parties place the following orders: 37 | party | market id | side | volume | price | resulting trades | type | tif | reference | 38 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 39 | party2 | ETH/DEC19 | sell | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 40 | party1 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 41 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 42 Then the opening auction period ends for market "ETH/DEC19" 43 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 44 And the mark price should be "1000" for the market "ETH/DEC19" 45 46 When the parties place the following orders: 47 | party | market id | side | volume | price | resulting trades | type | tif | reference | 48 | partyGuy | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 49 50 Then the parties should have the following margin levels: 51 | party | market id | maintenance | search | initial | release | 52 | partyGuy | ETH/DEC19 | 100 | 110 | 120 | 140 | 53 54 And the parties should have the following account balances: 55 | party | asset | market id | margin | general | 56 | partyGuy | ETH | ETH/DEC19 | 120 | 9880 | 57 58 When the parties cancel the following orders: 59 | party | reference | 60 | partyGuy | ref-1 | 61 62 Then the parties should have the following account balances: 63 | party | asset | market id | margin | general | 64 | partyGuy | ETH | ETH/DEC19 | 0 | 10000 | 65 66 67 @MarginRelease @Chris 68 Scenario: a party place a new market order in the system, order, trade, party margin is updated, then place an GTC order which will trade, margin is 0ed 69 Given the parties deposit on asset's general account the following amount: 70 | party | asset | amount | 71 | partyGuy | ETH | 10000 | 72 | party1 | ETH | 1000000 | 73 | party2 | ETH | 1000000 | 74 | aux | ETH | 100000000000 | 75 | lpprov | ETH | 100000000000 | 76 77 When the parties submit the following liquidity provision: 78 | id | party | market id | commitment amount | fee | lp type | 79 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 80 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 81 82 83 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 84 Then the parties place the following orders: 85 | party | market id | side | volume | price | resulting trades | type | tif | 86 | aux | ETH/DEC19 | buy | 1 | 9 | 0 | TYPE_LIMIT | TIF_GTC | 87 | aux | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | 88 89 # Trigger an auction to set the mark price 90 When the parties place the following orders: 91 | party | market id | side | volume | price | resulting trades | type | tif | reference | 92 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 93 | party1 | ETH/DEC19 | buy | 10 | 990 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 94 | party2 | ETH/DEC19 | sell | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 95 | party2 | ETH/DEC19 | sell | 10 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 96 | party1 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 97 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 98 Then the opening auction period ends for market "ETH/DEC19" 99 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 100 And the mark price should be "1000" for the market "ETH/DEC19" 101 102 When the parties place the following orders with ticks: 103 | party | market id | side | volume | price | resulting trades | type | tif | reference | 104 | partyGuy | ETH/DEC19 | sell | 1 | 0 | 1 | TYPE_MARKET | TIF_IOC | ref-1 | 105 106 Then the parties should have the following margin levels: 107 | party | market id | maintenance | 108 | partyGuy | ETH/DEC19 | 347 | 109 110 And the parties should have the following account balances: 111 | party | asset | market id | margin | general | 112 | partyGuy | ETH | ETH/DEC19 | 420 | 9481 | 113 114 Then the parties should have the following profit and loss: 115 | party | volume | unrealised pnl | realised pnl | 116 | partyGuy | -1 | 0 | 0 | 117 118 When the parties place the following orders: 119 | party | market id | side | volume | price | resulting trades | type | tif | reference | 120 | partyGuy | ETH/DEC19 | buy | 1 | 1005 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 121 122 Then the parties should have the following margin levels: 123 | party | market id | maintenance | 124 | partyGuy | ETH/DEC19 | 347 | 125 126 When the parties place the following orders with ticks: 127 | party | market id | side | volume | price | resulting trades | type | tif | reference | 128 | party1 | ETH/DEC19 | sell | 1 | 1005 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 129 130 Then the parties should have the following margin levels: 131 | party | market id | maintenance | search | initial | release | 132 | partyGuy | ETH/DEC19 | 0 | 0 | 0 | 0 | 133 134 And the parties should have the following account balances: 135 | party | asset | market id | margin | general | 136 | partyGuy | ETH | ETH/DEC19 | 0 | 9886 | 137 138 139 @MarginRelease 140 Scenario: a party place a new order in the system, party is closed out with only potential position, margin is 0ed 141 Given the parties deposit on asset's general account the following amount: 142 | party | asset | amount | 143 | partyGuy | ETH | 120 | 144 | party1 | ETH | 1000000 | 145 | party2 | ETH | 1000000 | 146 | aux | ETH | 100000000000 | 147 | lpprov | ETH | 100000000000 | 148 149 When the parties submit the following liquidity provision: 150 | id | party | market id | commitment amount | fee | lp type | 151 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 152 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 153 154 155 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 156 Then the parties place the following orders: 157 | party | market id | side | volume | price | resulting trades | type | tif | 158 | aux | ETH/DEC19 | buy | 1 | 9 | 0 | TYPE_LIMIT | TIF_GTC | 159 | aux | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | 160 161 # Trigger an auction to set the mark price 162 When the parties place the following orders: 163 | party | market id | side | volume | price | resulting trades | type | tif | reference | 164 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 165 | party2 | ETH/DEC19 | sell | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 166 | party1 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 167 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 168 Then the opening auction period ends for market "ETH/DEC19" 169 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 170 And the mark price should be "1000" for the market "ETH/DEC19" 171 172 When the parties place the following orders: 173 | party | market id | side | volume | price | resulting trades | type | tif | reference | 174 | partyGuy | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 175 176 Then the parties should have the following margin levels: 177 | party | market id | maintenance | search | initial | release | 178 | partyGuy | ETH/DEC19 | 100 | 110 | 120 | 140 | 179 180 And the parties should have the following account balances: 181 | party | asset | market id | margin | general | 182 | partyGuy | ETH | ETH/DEC19 | 120 | 0 | 183 184 When the parties place the following orders with ticks: 185 | party | market id | side | volume | price | resulting trades | type | tif | reference | 186 | party1 | ETH/DEC19 | sell | 1 | 500 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 187 | party2 | ETH/DEC19 | buy | 1 | 500 | 1 | TYPE_LIMIT | TIF_GTC | ref-1 | 188 189 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 190 And the mark price should be "500" for the market "ETH/DEC19" 191 192 Then the parties should have the following account balances: 193 | party | asset | market id | margin | general | 194 | partyGuy | ETH | ETH/DEC19 | 60 | 60 | 195 196 @MarginRelease @NoPerp 197 Scenario: a party place a new order in the system, party is closing position via closeout of other parties 198 Given the parties deposit on asset's general account the following amount: 199 | party | asset | amount | 200 | partyGuy | ETH | 120 | 201 | partyGuyGood | ETH | 1000000 | 202 | party1 | ETH | 1000000 | 203 | party2 | ETH | 1000000 | 204 | aux | ETH | 100000000000 | 205 | lpprov | ETH | 100000000000 | 206 207 When the parties submit the following liquidity provision: 208 | id | party | market id | commitment amount | fee | lp type | 209 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 210 | lp1 | lpprov | ETH/DEC19 | 90000000 | 0.1 | submission | 211 212 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 213 Then the parties place the following orders: 214 | party | market id | side | volume | price | resulting trades | type | tif | 215 | aux | ETH/DEC19 | buy | 1 | 9 | 0 | TYPE_LIMIT | TIF_GTC | 216 | aux | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | 217 218 # Trigger an auction to set the mark price 219 When the parties place the following orders: 220 | party | market id | side | volume | price | resulting trades | type | tif | reference | 221 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 222 | party2 | ETH/DEC19 | sell | 1 | 10001 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 223 | party1 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 224 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 225 Then the opening auction period ends for market "ETH/DEC19" 226 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 227 And the mark price should be "1000" for the market "ETH/DEC19" 228 229 When the parties place the following orders: 230 | party | market id | side | volume | price | resulting trades | type | tif | reference | 231 | partyGuy | ETH/DEC19 | sell | 1 | 9999 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 232 | partyGuyGood | ETH/DEC19 | sell | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 233 234 Then the parties should have the following margin levels: 235 | party | market id | maintenance | search | initial | release | 236 | partyGuy | ETH/DEC19 | 100 | 110 | 120 | 140 | 237 238 When the parties place the following orders with ticks: 239 | party | market id | side | volume | price | resulting trades | type | tif | reference | 240 | partyGuyGood | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | party2-2 | 241 | party1 | ETH/DEC19 | sell | 1 | 1000 | 1 | TYPE_LIMIT | TIF_GTC | party1-2 | 242 243 Then the parties should have the following profit and loss: 244 | party | volume | unrealised pnl | realised pnl | 245 | partyGuyGood | 1 | 0 | 0 | 246 247 And the parties should have the following account balances: 248 | party | asset | market id | margin | general | 249 | partyGuy | ETH | ETH/DEC19 | 120 | 0 | 250 | partyGuyGood | ETH | ETH/DEC19 | 432 | 999568 | 251 252 # this will trade with party guy 253 # which is going to get him distressed 254 When the parties place the following orders with ticks: 255 | party | market id | side | volume | price | resulting trades | type | tif | reference | 256 | party2 | ETH/DEC19 | buy | 1 | 9999 | 1 | TYPE_LIMIT | TIF_GTC | ref-1 | 257 And the network moves ahead "1" blocks 258 259 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 260 261 # now the margins should be back to 0, but it's actually 262 # not being released when the party is used in the distressed flow 263 Then the parties should have the following account balances: 264 | party | asset | market id | margin | general | 265 | partyGuy | ETH | ETH/DEC19 | 0 | 0 | 266 | partyGuyGood | ETH | ETH/DEC19 | 0 | 1008999 | 267 #| partyGuyGood | ETH | ETH/DEC19 | 13307 | 995693 | 268 # TODO: SHOULD BE THIS 269 270 271 # TODO: FIX THIS 272 # partyGuyGood should have a margin of 0 here. 273 # Position is actuall 0, and the party have no potential position 274 # so we just have collateral stuck in the margin account 275 Then the parties should have the following profit and loss: 276 | party | volume | unrealised pnl | realised pnl | 277 | partyGuyGood | 0 | 0 | 8999 |