code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-168.feature (about) 1 Feature: when party holds both orders and positions, amend order so order is filled\partially filled while party does not have enough collateral to cover 2 Background: 3 # Set liquidity parameters to allow "zero" target-stake which is needed to construct the order-book defined in the ACs 4 Given the following network parameters are set: 5 | name | value | 6 | network.markPriceUpdateMaximumFrequency | 1s | 7 And the liquidity monitoring parameters: 8 | name | triggering ratio | time window | scaling factor | 9 | lqm-params | 0.00 | 24h | 1e-9 | 10 And the simple risk model named "simple-risk-model": 11 | long | short | max move up | min move down | probability of trading | 12 | 0.1 | 0.1 | 100 | -100 | 0.2 | 13 And the markets: 14 | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 15 | ETH/FEB23 | ETH | USD | lqm-params | simple-risk-model | default-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.000125 | 0 | default-futures | 16 17 Scenario: 001 party and party1 both orders and positions 18 Given the parties deposit on asset's general account the following amount: 19 | party | asset | amount | 20 | buySideProvider | USD | 100000000000 | 21 | sellSideProvider | USD | 100000000000 | 22 | party | USD | 26440 | 23 | party1 | USD | 26440 | 24 And the parties place the following orders: 25 | party | market id | side | volume | price | resulting trades | type | tif | reference | 26 | buySideProvider | ETH/FEB23 | buy | 10 | 14900 | 0 | TYPE_LIMIT | TIF_GTC | | 27 | buySideProvider | ETH/FEB23 | buy | 2 | 15300 | 0 | TYPE_LIMIT | TIF_GTC | | 28 | buySideProvider | ETH/FEB23 | buy | 5 | 15500 | 0 | TYPE_LIMIT | TIF_GTC | | 29 | buySideProvider | ETH/FEB23 | buy | 6 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 30 | party | ETH/FEB23 | sell | 3 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 31 | party1 | ETH/FEB23 | sell | 3 | 15900 | 0 | TYPE_LIMIT | TIF_GTC | | 32 | party | ETH/FEB23 | sell | 5 | 16900 | 0 | TYPE_LIMIT | TIF_GTC | party-sell | 33 | party1 | ETH/FEB23 | sell | 5 | 16900 | 0 | TYPE_LIMIT | TIF_GTC | party1-sell | 34 | sellSideProvider | ETH/FEB23 | sell | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GTC | | 35 | sellSideProvider | ETH/FEB23 | sell | 10 | 100100 | 0 | TYPE_LIMIT | TIF_GTC | | 36 37 When the network moves ahead "2" blocks 38 Then the mark price should be "15900" for the market "ETH/FEB23" 39 40 And the order book should have the following volumes for market "ETH/FEB23": 41 | side | price | volume | 42 | sell | 15900 | 0 | 43 | sell | 16900 | 10 | 44 45 And the parties submit update margin mode: 46 | party | market | margin_mode | margin_factor | error | 47 | party | ETH/FEB23 | isolated margin | 0.2 | | 48 | party1 | ETH/FEB23 | isolated margin | 0.2 | | 49 50 And the parties should have the following margin levels: 51 | party | market id | maintenance | margin mode | margin factor | order | 52 | party | ETH/FEB23 | 4776 | isolated margin | 0.2 | 16900 | 53 | party1 | ETH/FEB23 | 4776 | isolated margin | 0.2 | 16900 | 54 55 #AC: 0019-MCAL-168, 0019-MCAL-169, amend order price so order get filled/partially filled 56 When the parties amend the following orders: 57 | party | reference | price | size delta | tif | error | 58 | party | party-sell | 15500 | 0 | TIF_GTC | | 59 | party1 | party1-sell | 15300 | 0 | TIF_GTC | | 60 61 Then the orders should have the following status: 62 | party | reference | status | 63 | party | party-sell | STATUS_FILLED | 64 | party1 | party1-sell | STATUS_ACTIVE | 65 66 #margin for party: 15900*0.2*3+15500*0.2*5=25040 67 #margin for party1: 15900*0.2*3+15300*0.2*2=15660 68 #order margin for party1: 15300*0.2*3=9180 69 70 Then the parties should have the following account balances: 71 | party | asset | market id | margin | general | order margin | 72 | party | USD | ETH/FEB23 | 25040 | 1400 | 0 | 73 | party1 | USD | ETH/FEB23 | 15660 | 1600 | 9180 | 74 75 And the parties should have the following margin levels: 76 | party | market id | maintenance | margin mode | margin factor | order | 77 | party | ETH/FEB23 | 12736 | isolated margin | 0.2 | 0 | 78 | party1 | ETH/FEB23 | 7960 | isolated margin | 0.2 | 9180 | 79 80 #party1's order is partially filled, and the rest of the order is left on the order book 81 And the order book should have the following volumes for market "ETH/FEB23": 82 | side | price | volume | 83 | sell | 15300 | 3 | 84 85 And the markets are updated: 86 | id | linear slippage factor | 87 | ETH/FEB23 | 0.25 | 88 89 When the network moves ahead "2" blocks 90 Then the mark price should be "15300" for the market "ETH/FEB23" 91 92 Then the orders should have the following status: 93 | party | reference | status | 94 | party | party-sell | STATUS_FILLED | 95 | party1 | party1-sell | STATUS_FILLED | 96 97 #party1's order is partially filled, and the rest of the order is canceled 98 And the order book should have the following volumes for market "ETH/FEB23": 99 | side | price | volume | 100 | sell | 15300 | 0 | 101 102 # in M2M party has insufficient margin hence getting closed out, party1 then trades with the network... 103 And the parties should have the following margin levels: 104 | party | market id | maintenance | search | initial | release | margin mode | margin factor | order | 105 | party | ETH/FEB23 | 0 | 0 | 0 | 0 | isolated margin | 0.2 | 0 | 106 | party1 | ETH/FEB23 | 16065 | 0 | 19278 | 0 | isolated margin | 0.2 | 0 | 107 108 #margin for party1: 3*0.2*15300=9180 109 Then the parties should have the following account balances: 110 | party | asset | market id | margin | general | order margin | 111 | party | USD | ETH/FEB23 | 0 | 1400 | 0 | 112 | party1 | USD | ETH/FEB23 | 9180 | 1600 | 0 | 113 114 And the following trades should be executed: 115 | buyer | price | size | seller | 116 | buySideProvider | 15900 | 3 | party | 117 | buySideProvider | 15900 | 3 | party1 | 118 | buySideProvider | 15500 | 5 | party | 119 | buySideProvider | 15300 | 2 | party1 | 120 | party | 15300 | 8 | network | 121 | party1 | 15300 | 5 | network | 122 | network | 15300 | 3 | party1 |