code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/3885-margin-release-after-cancel.feature (about) 1 Feature: Regression test for issue 3885 2 3 Background: 4 5 Given the markets: 6 | id | quote name | asset | auction duration | risk model | margin calculator | fees | data source config | price monitoring | linear slippage factor | quadratic slippage factor | sla params | 7 | ETH/DEC19 | BTC | BTC | 1 | default-log-normal-risk-model | default-margin-calculator | default-none | default-eth-for-future | default-none | 1e0 | 0 | default-futures | 8 And the following network parameters are set: 9 | name | value | 10 | network.markPriceUpdateMaximumFrequency | 0s | 11 | limits.markets.maxPeggedOrders | 2 | 12 13 @Cancel 14 Scenario: Margin should be released after the order was canceled 15 Given the parties deposit on asset's general account the following amount: 16 | party | asset | amount | 17 | party1 | BTC | 10000 | 18 | party2 | BTC | 10000 | 19 | party3 | BTC | 10000 | 20 | party4 | BTC | 10000 | 21 | lpprov | BTC | 10000 | 22 23 When the parties submit the following liquidity provision: 24 | id | party | market id | commitment amount | fee | lp type | 25 | lp1 | lpprov | ETH/DEC19 | 9000 | 0.1 | submission | 26 | lp1 | lpprov | ETH/DEC19 | 9000 | 0.1 | submission | 27 And the parties place the following pegged iceberg orders: 28 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 29 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 100 | 30 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 100 | 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 | 34 | party4 | ETH/DEC19 | buy | 1 | 95 | 0 | TYPE_LIMIT | TIF_GTC | 35 | party4 | ETH/DEC19 | sell | 1 | 105 | 0 | TYPE_LIMIT | TIF_GTC | 36 37 # Trigger an auction to set the mark price 38 When the parties place the following orders: 39 | party | market id | side | volume | price | resulting trades | type | tif | reference | 40 | party1 | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GFA | party1-1 | 41 | party2 | ETH/DEC19 | sell | 1 | 100 | 0 | TYPE_LIMIT | TIF_GFA | party2-1 | 42 Then the opening auction period ends for market "ETH/DEC19" 43 And the mark price should be "100" for the market "ETH/DEC19" 44 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 45 And the parties should have the following account balances: 46 | party | asset | market id | margin | general | 47 | party1 | BTC | ETH/DEC19 | 128 | 9872 | 48 49 When the parties place the following orders with ticks: 50 | party | market id | side | volume | price | resulting trades | type | tif | reference | 51 | party1 | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | party1-2 | 52 | party2 | ETH/DEC19 | sell | 1 | 100 | 1 | TYPE_LIMIT | TIF_GTC | party2-2 | 53 Then the mark price should be "100" for the market "ETH/DEC19" 54 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 55 And the parties should have the following account balances: 56 | party | asset | market id | margin | general | 57 | party1 | BTC | ETH/DEC19 | 256 | 9744 | 58 59 When the parties place the following orders with ticks: 60 | party | market id | side | volume | price | resulting trades | type | tif | reference | 61 | party1 | ETH/DEC19 | buy | 1 | 100 | 0 | TYPE_LIMIT | TIF_GTC | party1-3 | 62 Then the parties should have the following account balances: 63 | party | asset | market id | margin | general | 64 | party1 | BTC | ETH/DEC19 | 265 | 9735 | 65 And the mark price should be "100" for the market "ETH/DEC19" 66 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 67 68 When the parties cancel the following orders: 69 | party | reference | 70 | party1 | party1-3 | 71 Then the parties should have the following account balances: 72 | party | asset | market id | margin | general | 73 | party1 | BTC | ETH/DEC19 | 265 | 9735 | 74 # With a small change to force margin recalculating whennever an order is removed, we can have margins released. 75 # But back when we implemented this, we decided not to check margins for parties who still have an open position. 76 # The reasoning being that any party with an open position will get their margin released/topped up next MTM cycle. 77 # Cancelling an order, even if it changes the potential long/short, will always decrease margin requirements. All this would do is 78 # increase the number of transfers between margin and general accounts. 79 # | party1 | BTC | ETH/DEC19 | 24 | 9976 | 80 And the mark price should be "100" for the market "ETH/DEC19" 81 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 82