code.vegaprotocol.io/vega@v0.79.0/core/integration/features/closeouts/2878-close-out-orders-allowed-when-under-initial.feature (about) 1 Feature: Trader below initial margin, but above maintenance can submit an order to close their own position 2 3 Background: 4 Given time is updated to "2020-10-16T00:00:00Z" 5 And the markets: 6 | id | quote name | asset | auction duration | risk model | margin calculator | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 7 | ETH/DEC20 | ETH | ETH | 1 | default-simple-risk-model-3 | default-margin-calculator | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures | 8 And the following network parameters are set: 9 | name | value | 10 | market.auction.minimumDuration | 1 | 11 | network.markPriceUpdateMaximumFrequency | 0s | 12 | limits.markets.maxPeggedOrders | 2 | 13 14 Scenario: Trader under initial margin closes out their own position 15 Given the parties deposit on asset's general account the following amount: 16 | party | asset | amount | 17 | party1 | ETH | 10000000000000 | 18 | party2 | ETH | 10000000000000 | 19 | party3 | ETH | 1220 | 20 | party4 | ETH | 10000000000000 | 21 | party5 | ETH | 10000000000000 | 22 | auxiliary | ETH | 100000000000 | 23 | aux2 | ETH | 100000000000 | 24 | auxiliary | ETH | 100000000000 | 25 | lpprov | ETH | 10000000000000 | 26 | party6 | ETH | 10000000000000 | 27 28 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 29 Then the parties place the following orders: 30 | party | market id | side | volume | price | resulting trades | type | tif | 31 | auxiliary | ETH/DEC20 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 32 | auxiliary | ETH/DEC20 | sell | 1 | 200 | 0 | TYPE_LIMIT | TIF_GTC | 33 | aux2 | ETH/DEC20 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 34 | auxiliary | ETH/DEC20 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | 35 And the parties submit the following liquidity provision: 36 | id | party | market id | commitment amount | fee | lp type | 37 | lp1 | lpprov | ETH/DEC20 | 90000 | 0.1 | submission | 38 | lp1 | lpprov | ETH/DEC20 | 90000 | 0.1 | submission | 39 And the parties place the following pegged iceberg orders: 40 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 41 | lpprov | ETH/DEC20 | 410 | 1 | sell | MID | 410 | 100 | 42 | lpprov | ETH/DEC20 | 9000 | 1 | buy | MID | 9000 | 100 | 43 Then the opening auction period ends for market "ETH/DEC20" 44 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20" 45 And the mark price should be "100" for the market "ETH/DEC20" 46 47 # T0 + 1min - this causes the price for comparison of the bounds to be 567 48 Then time is updated to "2020-10-16T00:01:00Z" 49 50 When the parties place the following orders with ticks: 51 | party | market id | side | volume | price | resulting trades | type | tif | reference | 52 | party3 | ETH/DEC20 | sell | 10 | 100 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 53 | party6 | ETH/DEC20 | sell | 10 | 200 | 0 | TYPE_LIMIT | TIF_GTC | ref-61 | 54 55 And the markets are updated: 56 | id | linear slippage factor | 57 | ETH/DEC20 | 1 | 58 59 When the parties place the following orders with ticks: 60 | party | market id | side | volume | price | resulting trades | type | tif | reference | 61 | party5 | ETH/DEC20 | buy | 10 | 100 | 1 | TYPE_LIMIT | TIF_FOK | ref-1 | 62 | party4 | ETH/DEC20 | buy | 10 | 110 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 63 | party4 | ETH/DEC20 | sell | 10 | 120 | 0 | TYPE_LIMIT | TIF_GTC | ref-3 | 64 65 Then the parties should have the following account balances: 66 | party | asset | market id | margin | general | 67 | party4 | ETH | ETH/DEC20 | 132 | 9999999999868 | 68 | party3 | ETH | ETH/DEC20 | 1220 | 0 | 69 | party5 | ETH | ETH/DEC20 | 1332 | 9999999998568 | 70 71 And the parties should have the following margin levels: 72 | party | market id | maintenance | search | initial | release | 73 | party3 | ETH/DEC20 | 1100 | 1210 | 1320 | 1540 | 74 And the markets are updated: 75 | id | linear slippage factor | 76 | ETH/DEC20 | 0.05 | 77 ## Now party 3, though below initial margin places a buy order to close their position out 78 When the parties place the following orders with ticks: 79 | party | market id | side | volume | price | resulting trades | type | tif | reference | 80 | party5 | ETH/DEC20 | sell | 20 | 115 | 0 | TYPE_LIMIT | TIF_GTC | ref-6 | 81 | party4 | ETH/DEC20 | buy | 15 | 115 | 1 | TYPE_LIMIT | TIF_GTC | ref-7 | 82 | party3 | ETH/DEC20 | buy | 10 | 115 | 1 | TYPE_LIMIT | TIF_GTC | ref-8 | 83 ## The trades have happened, party 3 bought 5 -> margin requirements go down 84 Then the mark price should be "115" for the market "ETH/DEC20" 85 And the parties should have the following margin levels: 86 | party | market id | maintenance | 87 | party3 | ETH/DEC20 | 87 | 88 ## Balances of the party accounts reflect the change, total adds up to 1070 -> party3 lost money 89 ## as expected, but was able to close their position 90 Then the parties should have the following account balances: 91 | party | asset | market id | margin | general | 92 | party3 | ETH | ETH/DEC20 | 104 | 908 |