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