code.vegaprotocol.io/vega@v0.79.0/core/integration/features/closeouts/0012-POSR-033.feature (about) 1 Feature: Covers 0012-POSR-033 2 3 Background: 4 # disposal strategy every 5 seconds, 20% until 10 or less, max 10% of the book used, slippage is set to 10 so price range is always wide enough 5 Given the liquidation strategies: 6 | name | disposal step | disposal fraction | full disposal size | max fraction consumed | disposal slippage range | 7 | disposal-strat-1 | 5 | 0.2 | 10 | 0.5 | 0.1 | 8 And the markets: 9 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | liquidation strategy | 10 | ETH/DEC19 | BTC | BTC | default-simple-risk-model-4 | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures | disposal-strat-1 | 11 And the following network parameters are set: 12 | name | value | 13 | market.auction.minimumDuration | 1 | 14 | network.markPriceUpdateMaximumFrequency | 0s | 15 | limits.markets.maxPeggedOrders | 2 | 16 17 Scenario: When calculating the available volume, volume outside the disposal price range should not be considered. 18 # setup accounts 19 Given the parties deposit on asset's general account the following amount: 20 | party | asset | amount | 21 | tt_4 | BTC | 500000 | 22 | tt_5 | BTC | 100 | 23 | tt_6 | BTC | 100000000 | 24 | tt_10 | BTC | 10000000 | 25 | tt_11 | BTC | 10000000 | 26 | tt_aux | BTC | 100000000 | 27 | t2_aux | BTC | 100000000 | 28 | lpprov | BTC | 100000000 | 29 30 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 31 Then the parties place the following orders: 32 | party | market id | side | volume | price | resulting trades | type | tif | reference | 33 | tt_aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-1 | 34 | tt_aux | ETH/DEC19 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1 | 35 | t2_aux | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-2 | 36 | tt_aux | ETH/DEC19 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-2 | 37 And the parties submit the following liquidity provision: 38 | id | party | market id | commitment amount | fee | lp type | 39 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 40 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 41 And the parties place the following pegged iceberg orders: 42 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 43 | lpprov | ETH/DEC19 | 2 | 1 | buy | MID | 50 | 100 | 44 | lpprov | ETH/DEC19 | 2 | 1 | sell | MID | 50 | 100 | 45 Then the opening auction period ends for market "ETH/DEC19" 46 47 # place orders and generate trades, do not progress time 48 When the parties place the following orders with ticks: 49 | party | market id | side | volume | price | resulting trades | type | tif | reference | expires in | 50 | tt_10 | ETH/DEC19 | buy | 5 | 100 | 0 | TYPE_LIMIT | TIF_GTT | tt_10-1 | 3600 | 51 | tt_11 | ETH/DEC19 | sell | 5 | 100 | 1 | TYPE_LIMIT | TIF_GTT | tt_11-1 | 3600 | 52 | tt_4 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_4-1 | | 53 | tt_4 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_4-2 | | 54 | tt_5 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_5-1 | | 55 | tt_6 | ETH/DEC19 | sell | 2 | 150 | 1 | TYPE_LIMIT | TIF_GTC | tt_6-1 | | 56 | tt_5 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_5-2 | | 57 | tt_6 | ETH/DEC19 | sell | 2 | 150 | 1 | TYPE_LIMIT | TIF_GTC | tt_6-2 | | 58 | tt_10 | ETH/DEC19 | buy | 25 | 100 | 0 | TYPE_LIMIT | TIF_GTC | tt_10-2 | | 59 | tt_11 | ETH/DEC19 | sell | 25 | 0 | 3 | TYPE_MARKET | TIF_FOK | tt_11-2 | | 60 61 And the mark price should be "100" for the market "ETH/DEC19" 62 63 # checking margins 64 Then the parties should have the following account balances: 65 | party | asset | market id | margin | general | 66 | tt_5 | BTC | ETH/DEC19 | 0 | 0 | 67 68 # then we make sure the insurance pool collected the funds 69 And the insurance pool balance should be "0" for the market "ETH/DEC19" 70 71 #check positions 72 Then the parties should have the following profit and loss: 73 | party | volume | unrealised pnl | realised pnl | 74 | tt_4 | 4 | -200 | 0 | 75 | tt_5 | 0 | 0 | -100 | 76 | tt_6 | -4 | 200 | -27 | 77 | tt_10 | 26 | 0 | 0 | 78 | tt_11 | -30 | 200 | -65 | 79 | network | 4 | 0 | 0 | 80 81 # some time passes, position network still hasn't been closed/disposed of 82 When the network moves ahead "1" blocks 83 Then the parties should have the following profit and loss: 84 | party | volume | unrealised pnl | realised pnl | 85 | tt_4 | 4 | -200 | 0 | 86 | tt_5 | 0 | 0 | -100 | 87 | tt_6 | -4 | 200 | -27 | 88 | tt_10 | 26 | 0 | 0 | 89 | tt_11 | -30 | 200 | -65 | 90 | network | 4 | 0 | 0 | 91 # clear trade events to ensure that we are not picking up a closeout trade that happened before the disposal step expires 92 And clear trade events 93 # move mid price + create an order within the 10% range, max fraction is 0.5, so we expect half of the volume to trade 94 # The book has much, much move volume, but we only check the volume in the available range 95 And the parties place the following orders: 96 | party | market id | side | volume | price | resulting trades | type | tif | reference | 97 | tt_6 | ETH/DEC19 | sell | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_10-2 | 98 | tt_10 | ETH/DEC19 | buy | 4 | 126 | 0 | TYPE_LIMIT | TIF_GTC | tt_10-2 | 99 100 101 102 # some time passes, now the network disposes of its position 103 When the network moves ahead "5" blocks 104 Then the parties should have the following profit and loss: 105 | party | volume | unrealised pnl | realised pnl | 106 | tt_4 | 4 | -200 | 0 | 107 | tt_5 | 0 | 0 | -100 | 108 | tt_6 | -4 | 200 | -27 | 109 | tt_10 | 28 | -52 | 0 | 110 | tt_11 | -30 | 200 | -65 | 111 | network | 2 | 0 | 52 | 112 # Disposal fraction == 0.5, only a half of which trades 113 And the following network trades should be executed: 114 | party | aggressor side | volume | 115 | tt_10 | sell | 2 | 116 117 118 # Next closeout check -> the network trades again, but only consumes half again, so we expect a volume of 1 119 When the network moves ahead "6" blocks 120 Then the parties should have the following profit and loss: 121 | party | volume | unrealised pnl | realised pnl | 122 | tt_4 | 4 | -200 | 0 | 123 | tt_5 | 0 | 0 | -100 | 124 | tt_6 | -4 | 200 | -27 | 125 | tt_10 | 29 | -78 | 0 | 126 | tt_11 | -30 | 200 | -65 | 127 | network | 1 | 0 | 78 | 128 # Disposal fraction == 0.5, only a half of which trades 129 And the following network trades should be executed: 130 | party | aggressor side | volume | 131 | tt_10 | sell | 1 | 132