code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/network_pnl.feature (about) 1 Feature: Profit and loss for network a running liquidation strategy 2 3 Background: 4 5 # Configure the network 6 Given the average block duration is "1" 7 And the following network parameters are set: 8 | name | value | 9 | network.markPriceUpdateMaximumFrequency | 0s | 10 And the following assets are registered: 11 | id | decimal places | quantum | 12 | USD.0.1 | 0 | 1 | 13 14 # Configure the markets 15 Given the liquidation strategies: 16 | name | disposal step | disposal fraction | full disposal size | max fraction consumed | disposal slippage range | 17 | liquidation-strat-1 | 3600 | 0.5 | 0 | 1 | 0.1 | 18 | liquidation-strat-2 | 5 | 0.5 | 0 | 1 | 0.1 | 19 20 And the markets: 21 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | liquidation strategy | sla params | 22 | ETH/MAR22 | ETH | USD.0.10 | default-log-normal-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.001 | 0 | liquidation-strat-1 | default-basic | 23 | ETH/MAR23 | ETH | USD.0.10 | default-log-normal-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.001 | 0 | liquidation-strat-2 | default-basic | 24 25 26 27 @NetPNL 28 Scenario: Network long then liquidates short positions (0003-MTMK-015)(0012-POSR-016) 29 30 # Setup the market 31 Given the initial insurance pool balance is "10000" for all the markets 32 And the parties deposit on asset's general account the following amount: 33 | party | asset | amount | 34 | lp1 | USD.0.10 | 100000000000 | 35 | aux1 | USD.0.10 | 10000000000 | 36 | aux2 | USD.0.10 | 10000000000 | 37 And the parties submit the following liquidity provision: 38 | id | party | market id | commitment amount | fee | lp type | 39 | lp1 | lp1 | ETH/MAR22 | 500000 | 0 | submission | 40 When the parties place the following orders: 41 | party | market id | side | volume | price | resulting trades | type | tif | reference | 42 | lp1 | ETH/MAR22 | buy | 1000 | 199 | 0 | TYPE_LIMIT | TIF_GTC | best-bid | 43 | lp1 | ETH/MAR22 | sell | 1000 | 201 | 0 | TYPE_LIMIT | TIF_GTC | best-ask | 44 When the parties place the following orders: 45 | party | market id | side | volume | price | resulting trades | type | tif | 46 | aux1 | ETH/MAR22 | buy | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 47 | aux2 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 48 And the opening auction period ends for market "ETH/MAR22" 49 Then the market data for the market "ETH/MAR22" should be: 50 | mark price | trading mode | 51 | 200 | TRADING_MODE_CONTINUOUS | 52 53 # atRiskPary opens a long position 54 Given the parties deposit on asset's general account the following amount: 55 | party | asset | amount | 56 | atRiskParty | USD.0.10 | 100 | 57 And the parties place the following orders: 58 | party | market id | side | volume | price | resulting trades | type | tif | 59 | aux1 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 60 | atRiskParty | ETH/MAR22 | buy | 1 | 200 | 1 | TYPE_LIMIT | TIF_GTC | 61 When the network moves ahead "1" blocks 62 Then the parties should have the following profit and loss: 63 | party | volume | unrealised pnl | realised pnl | 64 | atRiskParty | 1 | 0 | 0 | 65 And the parties should have the following margin levels: 66 | party | market id | maintenance | search | initial | release | 67 | atRiskParty | ETH/MAR22 | 15 | 16 | 18 | 21 | 68 And the parties should have the following account balances: 69 | party | asset | market id | margin | general | 70 | atRiskParty | USD.0.10 | ETH/MAR22 | 16 | 84 | 71 72 # Market moves against atRiskParty whom is liquidated 73 Given the parties amend the following orders: 74 | party | reference | price | size delta | tif | 75 | lp1 | best-bid | 99 | 0 | TIF_GTC | 76 | lp1 | best-ask | 101 | 0 | TIF_GTC | 77 And the parties place the following orders: 78 | party | market id | side | volume | price | resulting trades | type | tif | 79 | aux1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 80 | aux2 | ETH/MAR22 | sell | 1 | 100 | 1 | TYPE_LIMIT | TIF_GTC | 81 When the network moves ahead "1" blocks 82 Then the mark price should be "100" for the market "ETH/MAR22" 83 And the parties should have the following profit and loss: 84 | party | volume | unrealised pnl | realised pnl | 85 | atRiskParty | 0 | 0 | -100 | 86 | network | 1 | 0 | 0 | 87 And the insurance pool balance should be "10000" for the market "ETH/MAR22" 88 89 # atRiskPary opens a short position 90 Given the parties deposit on asset's general account the following amount: 91 | party | asset | amount | 92 | atRiskParty | USD.0.10 | 20 | 93 And the parties place the following orders: 94 | party | market id | side | volume | price | resulting trades | type | tif | 95 | aux1 | ETH/MAR22 | buy | 2 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 96 | atRiskParty | ETH/MAR22 | sell | 2 | 100 | 1 | TYPE_LIMIT | TIF_GTC | 97 When the network moves ahead "1" blocks 98 Then the parties should have the following profit and loss: 99 | party | volume | unrealised pnl | realised pnl | 100 | atRiskParty | -2 | 0 | -100 | 101 And the parties should have the following margin levels: 102 | party | market id | maintenance | search | initial | release | 103 | atRiskParty | ETH/MAR22 | 16 | 17 | 19 | 22 | 104 And the parties should have the following account balances: 105 | party | asset | market id | margin | general | 106 | atRiskParty | USD.0.10 | ETH/MAR22 | 18 | 2 | 107 108 # Market moves against atRiskParty whom is liquidated 109 Given the parties amend the following orders: 110 | party | reference | price | size delta | tif | 111 | lp1 | best-ask | 121 | 0 | TIF_GTC | 112 | lp1 | best-bid | 119 | 0 | TIF_GTC | 113 And the parties place the following orders: 114 | party | market id | side | volume | price | resulting trades | type | tif | 115 | aux1 | ETH/MAR22 | buy | 1 | 120 | 0 | TYPE_LIMIT | TIF_GTC | 116 | aux2 | ETH/MAR22 | sell | 1 | 120 | 1 | TYPE_LIMIT | TIF_GTC | 117 When the network moves ahead "1" blocks 118 Then the mark price should be "120" for the market "ETH/MAR22" 119 And the parties should have the following profit and loss: 120 | party | volume | unrealised pnl | realised pnl | 121 | atRiskParty | 0 | 0 | -140 | 122 | network | -1 | 0 | 20 | 123 And the insurance pool balance should be "10000" for the market "ETH/MAR22" 124 125 # Market moves in favour of the network 126 Given the parties amend the following orders: 127 | party | reference | price | size delta | tif | 128 | lp1 | best-bid | 59 | 0 | TIF_GTC | 129 | lp1 | best-ask | 61 | 0 | TIF_GTC | 130 And the parties place the following orders: 131 | party | market id | side | volume | price | resulting trades | type | tif | 132 | aux1 | ETH/MAR22 | buy | 1 | 60 | 0 | TYPE_LIMIT | TIF_GTC | 133 | aux2 | ETH/MAR22 | sell | 1 | 60 | 1 | TYPE_LIMIT | TIF_GTC | 134 When the network moves ahead "1" blocks 135 Then the mark price should be "60" for the market "ETH/MAR22" 136 And the parties should have the following profit and loss: 137 | party | volume | unrealised pnl | realised pnl | 138 | atRiskParty | 0 | 0 | -140 | 139 | network | -1 | 60 | 20 | 140 And the insurance pool balance should be "10060" for the market "ETH/MAR22" 141 142 143 @NetPNL 144 Scenario: Network long then liquidates further long positions (0003-MTMK-016)(0012-POSR-017) 145 146 # Setup the market 147 Given the initial insurance pool balance is "10000" for all the markets 148 And the parties deposit on asset's general account the following amount: 149 | party | asset | amount | 150 | lp1 | USD.0.10 | 100000000000 | 151 | aux1 | USD.0.10 | 10000000000 | 152 | aux2 | USD.0.10 | 10000000000 | 153 And the parties submit the following liquidity provision: 154 | id | party | market id | commitment amount | fee | lp type | 155 | lp1 | lp1 | ETH/MAR22 | 500000 | 0 | submission | 156 When the parties place the following orders: 157 | party | market id | side | volume | price | resulting trades | type | tif | reference | 158 | lp1 | ETH/MAR22 | buy | 1000 | 199 | 0 | TYPE_LIMIT | TIF_GTC | best-bid | 159 | lp1 | ETH/MAR22 | sell | 1000 | 201 | 0 | TYPE_LIMIT | TIF_GTC | best-ask | 160 When the parties place the following orders: 161 | party | market id | side | volume | price | resulting trades | type | tif | 162 | aux1 | ETH/MAR22 | buy | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 163 | aux2 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 164 And the opening auction period ends for market "ETH/MAR22" 165 Then the market data for the market "ETH/MAR22" should be: 166 | mark price | trading mode | 167 | 200 | TRADING_MODE_CONTINUOUS | 168 169 # atRiskPary opens a long position 170 Given the parties deposit on asset's general account the following amount: 171 | party | asset | amount | 172 | atRiskParty | USD.0.10 | 100 | 173 And the parties place the following orders: 174 | party | market id | side | volume | price | resulting trades | type | tif | 175 | aux1 | ETH/MAR22 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 176 | atRiskParty | ETH/MAR22 | buy | 1 | 200 | 1 | TYPE_LIMIT | TIF_GTC | 177 When the network moves ahead "1" blocks 178 Then the parties should have the following profit and loss: 179 | party | volume | unrealised pnl | realised pnl | 180 | atRiskParty | 1 | 0 | 0 | 181 And the parties should have the following margin levels: 182 | party | market id | maintenance | search | initial | release | 183 | atRiskParty | ETH/MAR22 | 15 | 16 | 18 | 21 | 184 And the parties should have the following account balances: 185 | party | asset | market id | margin | general | 186 | atRiskParty | USD.0.10 | ETH/MAR22 | 16 | 84 | 187 188 # Market moves against atRiskParty whom is liquidated 189 Given the parties amend the following orders: 190 | party | reference | price | size delta | tif | 191 | lp1 | best-bid | 99 | 0 | TIF_GTC | 192 | lp1 | best-ask | 101 | 0 | TIF_GTC | 193 And the parties place the following orders: 194 | party | market id | side | volume | price | resulting trades | type | tif | 195 | aux1 | ETH/MAR22 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 196 | aux2 | ETH/MAR22 | sell | 1 | 100 | 1 | TYPE_LIMIT | TIF_GTC | 197 When the network moves ahead "1" blocks 198 Then the mark price should be "100" for the market "ETH/MAR22" 199 And the parties should have the following profit and loss: 200 | party | volume | unrealised pnl | realised pnl | 201 | atRiskParty | 0 | 0 | -100 | 202 | network | 1 | 0 | 0 | 203 And the insurance pool balance should be "10000" for the market "ETH/MAR22" 204 205 # atRiskPary opens a long position 206 Given the parties deposit on asset's general account the following amount: 207 | party | asset | amount | 208 | atRiskParty | USD.0.10 | 10 | 209 And the parties place the following orders: 210 | party | market id | side | volume | price | resulting trades | type | tif | 211 | aux1 | ETH/MAR22 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 212 | atRiskParty | ETH/MAR22 | buy | 1 | 100 | 1 | TYPE_LIMIT | TIF_GTC | 213 When the network moves ahead "1" blocks 214 Then the parties should have the following profit and loss: 215 | party | volume | unrealised pnl | realised pnl | 216 | atRiskParty | 1 | 0 | -100 | 217 And the parties should have the following margin levels: 218 | party | market id | maintenance | search | initial | release | 219 | atRiskParty | ETH/MAR22 | 8 | 8 | 9 | 11 | 220 And the parties should have the following account balances: 221 | party | asset | market id | margin | general | 222 | atRiskParty | USD.0.10 | ETH/MAR22 | 8 | 2 | 223 224 # Market moves against atRiskParty whom is liquidated 225 Given the parties amend the following orders: 226 | party | reference | price | size delta | tif | 227 | lp1 | best-bid | 89 | 0 | TIF_GTC | 228 | lp1 | best-ask | 91 | 0 | TIF_GTC | 229 And the parties place the following orders: 230 | party | market id | side | volume | price | resulting trades | type | tif | 231 | aux1 | ETH/MAR22 | buy | 1 | 90 | 0 | TYPE_LIMIT | TIF_GTC | 232 | aux2 | ETH/MAR22 | sell | 1 | 90 | 1 | TYPE_LIMIT | TIF_GTC | 233 When the network moves ahead "1" blocks 234 Then the mark price should be "90" for the market "ETH/MAR22" 235 And the parties should have the following profit and loss: 236 | party | volume | unrealised pnl | realised pnl | 237 | atRiskParty | 0 | 0 | -110 | 238 | network | 2 | -10 | 0 | 239 And the insurance pool balance should be "9990" for the market "ETH/MAR22" 240 241 # Market moves against the network 242 Given the parties amend the following orders: 243 | party | reference | price | size delta | tif | 244 | lp1 | best-bid | 59 | 0 | TIF_GTC | 245 | lp1 | best-ask | 61 | 0 | TIF_GTC | 246 And the parties place the following orders: 247 | party | market id | side | volume | price | resulting trades | type | tif | 248 | aux1 | ETH/MAR22 | buy | 1 | 60 | 0 | TYPE_LIMIT | TIF_GTC | 249 | aux2 | ETH/MAR22 | sell | 1 | 60 | 1 | TYPE_LIMIT | TIF_GTC | 250 When the network moves ahead "1" blocks 251 Then the mark price should be "60" for the market "ETH/MAR22" 252 And the parties should have the following profit and loss: 253 | party | volume | unrealised pnl | realised pnl | 254 | atRiskParty | 0 | 0 | -110 | 255 | network | 2 | -70 | 0 | 256 And the insurance pool balance should be "9930" for the market "ETH/MAR22" 257 258 @NetPNL 259 Scenario: Network disposes long position at a loss, loss socialisation applied (0003-MTMK-017)(0012-POSR-018) 260 261 # Setup the market 262 Given the initial insurance pool balance is "0" for all the markets 263 And the parties deposit on asset's general account the following amount: 264 | party | asset | amount | 265 | lp1 | USD.0.10 | 100000000000 | 266 | aux1 | USD.0.10 | 10000000000 | 267 | aux2 | USD.0.10 | 10000000000 | 268 | atRiskParty | USD.0.10 | 100 | 269 And the cumulated balance for all accounts should be worth "120000000100" 270 And the parties submit the following liquidity provision: 271 | id | party | market id | commitment amount | fee | lp type | 272 | lp1 | lp1 | ETH/MAR23 | 500000 | 0 | submission | 273 When the parties place the following orders: 274 | party | market id | side | volume | price | resulting trades | type | tif | reference | 275 | lp1 | ETH/MAR23 | buy | 1000 | 199 | 0 | TYPE_LIMIT | TIF_GTC | best-bid | 276 | lp1 | ETH/MAR23 | sell | 1000 | 201 | 0 | TYPE_LIMIT | TIF_GTC | best-ask | 277 When the parties place the following orders: 278 | party | market id | side | volume | price | resulting trades | type | tif | 279 | aux1 | ETH/MAR23 | buy | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 280 | aux2 | ETH/MAR23 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 281 And the opening auction period ends for market "ETH/MAR23" 282 Then the market data for the market "ETH/MAR23" should be: 283 | mark price | trading mode | 284 | 200 | TRADING_MODE_CONTINUOUS | 285 286 # atRiskPary opens a long position 287 Given the parties place the following orders: 288 | party | market id | side | volume | price | resulting trades | type | tif | 289 | aux1 | ETH/MAR23 | sell | 2 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 290 | atRiskParty | ETH/MAR23 | buy | 2 | 200 | 1 | TYPE_LIMIT | TIF_GTC | 291 When the network moves ahead "1" blocks 292 Then the parties should have the following profit and loss: 293 | party | volume | unrealised pnl | realised pnl | 294 | atRiskParty | 2 | 0 | 0 | 295 And the parties should have the following margin levels: 296 | party | market id | maintenance | search | initial | release | 297 | atRiskParty | ETH/MAR23 | 29 | 31 | 34 | 40 | 298 And the parties should have the following account balances: 299 | party | asset | market id | margin | general | 300 | atRiskParty | USD.0.10 | ETH/MAR23 | 33 | 67 | 301 302 # Market moves against atRiskParty whom is liquidated 303 Given the parties amend the following orders: 304 | party | reference | price | size delta | tif | 305 | lp1 | best-bid | 99 | 0 | TIF_GTC | 306 | lp1 | best-ask | 101 | 0 | TIF_GTC | 307 And the parties place the following orders: 308 | party | market id | side | volume | price | resulting trades | type | tif | 309 | aux1 | ETH/MAR23 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 310 | aux2 | ETH/MAR23 | sell | 1 | 100 | 1 | TYPE_LIMIT | TIF_GTC | 311 When the network moves ahead "1" blocks 312 Then the mark price should be "100" for the market "ETH/MAR23" 313 And the parties should have the following profit and loss: 314 | party | volume | unrealised pnl | realised pnl | 315 | atRiskParty | 0 | 0 | -100 | 316 | network | 2 | 0 | 0 | 317 And the insurance pool balance should be "0" for the market "ETH/MAR23" 318 319 # Network disposes position at a loss, the mark price is not updated, loss socialisation applied cumulated balances unchanged 320 Given the insurance pool balance should be "0" for the market "ETH/MAR23" 321 And the cumulated balance for all accounts should be worth "120000000100" 322 When the network moves ahead "5" blocks 323 Then the parties should have the following profit and loss: 324 | party | volume | unrealised pnl | realised pnl | 325 | network | 1 | 0 | -1 | 326 And the mark price should be "100" for the market "ETH/MAR23" 327 And the cumulated balance for all accounts should be worth "120000000100" 328 329 # Network disposes position at a loss, the mark price is not updated, loss socialisation applied cumulated balances unchanged 330 Given the insurance pool balance should be "0" for the market "ETH/MAR23" 331 And the cumulated balance for all accounts should be worth "120000000100" 332 When the network moves ahead "5" blocks 333 Then the parties should have the following profit and loss: 334 | party | volume | unrealised pnl | realised pnl | 335 | network | 0 | 0 | -2 | 336 And the mark price should be "100" for the market "ETH/MAR23" 337 And the cumulated balance for all accounts should be worth "120000000100" 338