code.vegaprotocol.io/vega@v0.79.0/core/integration/features/settlement/10568-pnl-underflow.feature (about) 1 Feature: Test loss socialization case 1 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 | BTC | BTC | default-simple-risk-model-2 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures | 7 And the following network parameters are set: 8 | name | value | 9 | market.auction.minimumDuration | 1 | 10 | network.markPriceUpdateMaximumFrequency | 0s | 11 12 @LossSocEvts 13 Scenario: Case 1: trader1 has insufficient MTM & only trader2 socialises the losses (0002-STTL-009) 14 Description : Case 1 from https://docs.google.com/spreadsheets/d/1CIPH0aQmIKj6YeFW9ApP_l-jwB4OcsNQ/edit#gid=1555964910 15 16 # setup accounts 17 Given the parties deposit on asset's general account the following amount: 18 | party | asset | amount | 19 | sellSideProvider | BTC | 100000000 | 20 | buySideProvider | BTC | 100000000 | 21 | party1 | BTC | 5000 | 22 | party2 | BTC | 50000 | 23 | party3 | BTC | 50000 | 24 | aux1 | BTC | 100000000 | 25 | aux2 | BTC | 100000000 | 26 # setup order book 27 When the parties place the following orders: 28 | party | market id | side | volume | price | resulting trades | type | tif | reference | 29 | sellSideProvider | ETH/DEC19 | sell | 1000 | 120 | 0 | TYPE_LIMIT | TIF_GTC | sell-provider-1 | 30 | buySideProvider | ETH/DEC19 | buy | 1000 | 80 | 0 | TYPE_LIMIT | TIF_GTC | buy-provider-1 | 31 | aux1 | ETH/DEC19 | sell | 1 | 120 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1 | 32 | aux2 | ETH/DEC19 | buy | 1 | 80 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-1 | 33 | aux1 | ETH/DEC19 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-2 | 34 | aux2 | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-2 | 35 Then the opening auction period ends for market "ETH/DEC19" 36 And the mark price should be "100" for the market "ETH/DEC19" 37 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 38 # party 1 place an order + we check margins 39 When the parties place the following orders with ticks: 40 | party | market id | side | volume | price | resulting trades | type | tif | reference | 41 | party1 | ETH/DEC19 | sell | 100 | 100 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 42 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 43 # then party2 place an order, and we calculate the margins again 44 When the parties place the following orders with ticks: 45 | party | market id | side | volume | price | resulting trades | type | tif | reference | 46 | party2 | ETH/DEC19 | buy | 100 | 100 | 1 | TYPE_LIMIT | TIF_GTC | ref-1 | 47 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 48 # then we change the volume in the book 49 Then the parties cancel the following orders: 50 | party | reference | 51 | sellSideProvider | sell-provider-1 | 52 | buySideProvider | buy-provider-1 | 53 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 54 When the parties place the following orders with ticks: 55 | party | market id | side | volume | price | resulting trades | type | tif | reference | 56 | sellSideProvider | ETH/DEC19 | sell | 1000 | 200 | 0 | TYPE_LIMIT | TIF_GTC | sell-provider-2 | 57 | buySideProvider | ETH/DEC19 | buy | 1000 | 80 | 0 | TYPE_LIMIT | TIF_GTC | buy-provider-2 | 58 Then the parties cancel the following orders: 59 | party | reference | 60 | aux1 | aux-s-1 | 61 | aux2 | aux-b-1 | 62 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 63 When the parties place the following orders with ticks: 64 | party | market id | side | volume | price | resulting trades | type | tif | reference | 65 | party2 | ETH/DEC19 | buy | 100 | 180 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 66 | party3 | ETH/DEC19 | sell | 100 | 180 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 67 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 68 Then the parties should have the following profit and loss: 69 | party | volume | unrealised pnl | realised pnl | 70 | party1 | 0 | 0 | -5000 | 71 | party2 | 200 | 8000 | -2970 | 72 | party3 | -100 | 0 | 0 | 73 | aux2 | 1 | 80 | -30 | 74 And the insurance pool balance should be "0" for the market "ETH/DEC19" 75 And debug loss socialisation events 76 And the cumulated balance for all accounts should be worth "400105000"