code.vegaprotocol.io/vega@v0.79.0/core/integration/features/closeouts/closeout-long-with-custom-strategy.feature (about) 1 Feature: Same as 1847-closeout-long test, but with a custom liquidation strategy in place 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.1 | 10 | 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 @DisposalStrat 18 Scenario: https://drive.google.com/file/d/1bYWbNJvG7E-tcqsK26JMu2uGwaqXqm0L/view 19 # setup accounts 20 Given the parties deposit on asset's general account the following amount: 21 | party | asset | amount | 22 | tt_4 | BTC | 500000 | 23 | tt_5 | BTC | 100 | 24 | tt_6 | BTC | 100000000 | 25 | tt_10 | BTC | 10000000 | 26 | tt_11 | BTC | 10000000 | 27 | tt_aux | BTC | 100000000 | 28 | t2_aux | BTC | 100000000 | 29 | lpprov | BTC | 100000000 | 30 31 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 32 Then the parties place the following orders: 33 | party | market id | side | volume | price | resulting trades | type | tif | reference | 34 | tt_aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-1 | 35 | tt_aux | ETH/DEC19 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-1 | 36 | t2_aux | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-2 | 37 | tt_aux | ETH/DEC19 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-2 | 38 And the parties submit the following liquidity provision: 39 | id | party | market id | commitment amount | fee | lp type | 40 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 41 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 42 And the parties place the following pegged iceberg orders: 43 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 44 | lpprov | ETH/DEC19 | 2 | 1 | buy | MID | 50 | 100 | 45 | lpprov | ETH/DEC19 | 2 | 1 | sell | MID | 50 | 100 | 46 Then the opening auction period ends for market "ETH/DEC19" 47 48 # place orders and generate trades, do not progress time 49 When the parties place the following orders with ticks: 50 | party | market id | side | volume | price | resulting trades | type | tif | reference | expires in | 51 | tt_10 | ETH/DEC19 | buy | 5 | 100 | 0 | TYPE_LIMIT | TIF_GTT | tt_10-1 | 3600 | 52 | tt_11 | ETH/DEC19 | sell | 5 | 100 | 1 | TYPE_LIMIT | TIF_GTT | tt_11-1 | 3600 | 53 | tt_4 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_4-1 | | 54 | tt_4 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_4-2 | | 55 | tt_5 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_5-1 | | 56 | tt_6 | ETH/DEC19 | sell | 2 | 150 | 1 | TYPE_LIMIT | TIF_GTC | tt_6-1 | | 57 | tt_5 | ETH/DEC19 | buy | 2 | 150 | 0 | TYPE_LIMIT | TIF_GTC | tt_5-2 | | 58 | tt_6 | ETH/DEC19 | sell | 2 | 150 | 1 | TYPE_LIMIT | TIF_GTC | tt_6-2 | | 59 | tt_10 | ETH/DEC19 | buy | 25 | 100 | 0 | TYPE_LIMIT | TIF_GTC | tt_10-2 | | 60 | tt_11 | ETH/DEC19 | sell | 25 | 0 | 3 | TYPE_MARKET | TIF_FOK | tt_11-2 | | 61 62 And the mark price should be "100" for the market "ETH/DEC19" 63 64 # checking margins 65 Then the parties should have the following account balances: 66 | party | asset | market id | margin | general | 67 | tt_5 | BTC | ETH/DEC19 | 0 | 0 | 68 69 # then we make sure the insurance pool collected the funds 70 And the insurance pool balance should be "0" for the market "ETH/DEC19" 71 72 #check positions 73 Then the parties should have the following profit and loss: 74 | party | volume | unrealised pnl | realised pnl | 75 | tt_4 | 4 | -200 | 0 | 76 | tt_5 | 0 | 0 | -100 | 77 | tt_6 | -4 | 200 | -27 | 78 | tt_10 | 26 | 0 | 0 | 79 | tt_11 | -30 | 200 | -65 | 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 # clear trade events to ensure that we are not picking up a closeout trade that happened before the disposal step expires 91 And clear trade events 92 93 94 # some time passes, now the network disposes of its position 95 When the network moves ahead "4" blocks 96 Then the parties should have the following profit and loss: 97 | party | volume | unrealised pnl | realised pnl | 98 | tt_4 | 4 | -200 | 0 | 99 | tt_5 | 0 | 0 | -100 | 100 | tt_6 | -4 | 200 | -27 | 101 | tt_10 | 26 | 0 | 0 | 102 | tt_11 | -30 | 200 | -65 | 103 And debug trades 104 And the following network trades should be executed: 105 | party | aggressor side | volume | 106 | tt_10 | sell | 4 | 107