code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0019-MCAL-margin_calculator-verified_margins_case1.feature (about) 1 Feature: CASE-1: Trader submits long order that will trade - new formula & high exit price (0019-MCAL-001, 0019-MCAL-002, 0019-MCAL-003) 2 # https://drive.google.com/drive/folders/1BCOKaEb7LZYAKoiPfXfaqwM4BNicPpF- 3 4 Background: 5 6 Given the markets: 7 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 8 | ETH/DEC19 | ETH | ETH | default-simple-risk-model | default-overkill-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0 | 0 | default-futures | 9 And the following network parameters are set: 10 | name | value | 11 | market.auction.minimumDuration | 1 | 12 | network.markPriceUpdateMaximumFrequency | 0s | 13 | limits.markets.maxPeggedOrders | 2 | 14 And the parties deposit on asset's general account the following amount: 15 | party | asset | amount | 16 | party1 | ETH | 1000000000 | 17 | sellSideMM | ETH | 2000000000 | 18 | buySideMM | ETH | 2000000000 | 19 | aux | ETH | 1000000000 | 20 | aux2 | ETH | 1000000000 | 21 | lpprov | ETH | 1000000000 | 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 | 900000000 | 0.1 | submission | 26 | lp1 | lpprov | ETH/DEC19 | 900000000 | 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 | 400 | 1 | buy | BID | 400 | 10 | 30 | lpprov | ETH/DEC19 | 600 | 1 | sell | ASK | 600 | 10 | 31 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 32 And the parties place the following orders: 33 | party | market id | side | volume | price | resulting trades | type | tif | 34 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 35 | aux | ETH/DEC19 | sell | 1 | 20000000 | 0 | TYPE_LIMIT | TIF_GTC | 36 | aux | ETH/DEC19 | buy | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | 37 | aux2 | ETH/DEC19 | sell | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | 38 Then the market data for the market "ETH/DEC19" should be: 39 | target stake | supplied stake | 40 | 20600000 | 900000000 | 41 Then the opening auction period ends for market "ETH/DEC19" 42 And the mark price should be "10300000" for the market "ETH/DEC19" 43 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 44 45 # setting mark price 46 And the parties place the following orders: 47 | party | market id | side | volume | price | resulting trades | type | tif | reference | 48 | sellSideMM | ETH/DEC19 | sell | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 49 | buySideMM | ETH/DEC19 | buy | 1 | 10300000 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 50 51 52 # setting order book 53 And the parties place the following orders: 54 | party | market id | side | volume | price | resulting trades | type | tif | reference | 55 | sellSideMM | ETH/DEC19 | sell | 100 | 25000000 | 0 | TYPE_LIMIT | TIF_GTC | _sell1 | 56 | sellSideMM | ETH/DEC19 | sell | 11 | 14000000 | 0 | TYPE_LIMIT | TIF_GTC | _sell2 | 57 | sellSideMM | ETH/DEC19 | sell | 2 | 11200000 | 0 | TYPE_LIMIT | TIF_GTC | _sell3 | 58 | buySideMM | ETH/DEC19 | buy | 1 | 10000000 | 0 | TYPE_LIMIT | TIF_GTC | buy1 | 59 | buySideMM | ETH/DEC19 | buy | 3 | 9600000 | 0 | TYPE_LIMIT | TIF_GTC | buy2 | 60 | buySideMM | ETH/DEC19 | buy | 15 | 9000000 | 0 | TYPE_LIMIT | TIF_GTC | buy3 | 61 | buySideMM | ETH/DEC19 | buy | 50 | 8700000 | 0 | TYPE_LIMIT | TIF_GTC | _buy4 | 62 63 And the order book should have the following volumes for market "ETH/DEC19": 64 | side | price | volume | 65 | buy | 1 | 1 | 66 | buy | 8700000 | 50 | 67 | buy | 9000000 | 15 | 68 | buy | 9600000 | 3 | 69 | buy | 9999990 | 400 | 70 | buy | 10000000 | 1 | 71 | sell | 11200000 | 2 | 72 | sell | 11200010 | 600 | 73 | sell | 14000000 | 11 | 74 | sell | 20000000 | 1 | 75 | sell | 25000000 | 100 | 76 77 Scenario: 78 # no margin account created for party1, just general account 79 Given "party1" should have one account per asset 80 # placing test order 81 82 And the average fill price is: 83 | market | volume | side | ref price | mark price | equivalent linear slippage factor | 84 | ETH/DEC19 | 13 | sell | 10300000 | 10300000 | 0.0873794174757282 | 85 86 # update linear slippage factor more in line with what book-based slippage used to be 87 And the markets are updated: 88 | id | linear slippage factor | 89 | ETH/DEC19 | 0.0873794174757282 | 90 91 When the parties place the following orders with ticks: 92 | party | market id | side | volume | price | resulting trades | type | tif | reference | 93 | party1 | ETH/DEC19 | buy | 13 | 15000000 | 2 | TYPE_LIMIT | TIF_GTC | ref-1 | 94 And "party1" should have general account balance of "832630096" for asset "ETH" 95 And the order book should have the following volumes for market "ETH/DEC19": 96 | side | price | volume | 97 | buy | 1 | 1 | 98 | buy | 8700000 | 50 | 99 | buy | 9000000 | 15 | 100 | buy | 9600000 | 3 | 101 | buy | 9999990 | 400 | 102 | buy | 10000000 | 1 | 103 | sell | 11200000 | 0 | 104 | sell | 11200010 | 0 | 105 | sell | 14000000 | 11 | 106 | sell | 14000010 | 589 | 107 | sell | 20000000 | 1 | 108 | sell | 25000000 | 100 | 109 And the following trades should be executed: 110 | buyer | price | size | seller | 111 | party1 | 11200000 | 2 | sellSideMM | 112 | party1 | 11200010 | 11 | lpprov | 113 114 Then the parties should have the following profit and loss: 115 | party | volume | unrealised pnl | realised pnl | 116 | party1 | 13 | 20 | 0 | 117 | sellSideMM | -3 | -900030 | 0 | 118 | lpprov | -11 | 0 | 0 | 119 120 Then the following transfers should happen: 121 | from | to | from account | to account | market id | amount | asset | 122 | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 20 | ETH | 123 124 Then the parties should have the following account balances: 125 | party | asset | market id | margin | general | 126 | party1 | ETH | ETH/DEC19 | 167369924 | 832630096 | 127 And the parties should have the following margin levels: 128 | party | market id | maintenance | search | initial | release | 129 | party1 | ETH/DEC19 | 41842481 | 133895939 | 167369924 | 209212405 | 130 And the parties should have the following profit and loss: 131 | party | volume | unrealised pnl | realised pnl | 132 | party1 | 13 | 20 | 0 | 133 134 # NEW ORDERS ADDED WITHOUT ANOTHER TRADE HAPPENING 135 Then the parties cancel the following orders: 136 | party | reference | 137 | buySideMM | buy1 | 138 | buySideMM | buy2 | 139 | buySideMM | buy3 | 140 141 And the order book should have the following volumes for market "ETH/DEC19": 142 | side | price | volume | 143 | buy | 1 | 1 | 144 | buy | 8699990 | 400 | 145 | buy | 8700000 | 50 | 146 | buy | 9000000 | 0 | 147 | buy | 9600000 | 0 | 148 | buy | 9999990 | 0 | 149 | buy | 10000000 | 0 | 150 | sell | 11200000 | 0 | 151 | sell | 11200010 | 0 | 152 | sell | 14000000 | 11 | 153 | sell | 14000010 | 589 | 154 | sell | 20000000 | 1 | 155 | sell | 25000000 | 100 | 156 When the parties place the following orders: 157 | party | market id | side | volume | price | resulting trades | type | tif | reference | 158 | buySideMM | ETH/DEC19 | buy | 1 | 11900000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 159 | buySideMM | ETH/DEC19 | buy | 3 | 11800000 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 160 | buySideMM | ETH/DEC19 | buy | 15 | 11700000 | 0 | TYPE_LIMIT | TIF_GTC | ref-3 | 161 162 Then the parties should have the following account balances: 163 | party | asset | market id | margin | general | 164 | party1 | ETH | ETH/DEC19 | 167369924 | 832630096 | 165 And the parties should have the following margin levels: 166 | party | market id | maintenance | search | initial | release | 167 | party1 | ETH/DEC19 | 41842481 | 133895939 | 167369924 | 209212405 | 168 And the parties should have the following profit and loss: 169 | party | volume | unrealised pnl | realised pnl | 170 | party1 | 13 | 20 | 0 | 171 172 # ANOTHER TRADE HAPPENING (BY A DIFFERENT PARTY) 173 # updating mark price to 200 174 When the parties place the following orders with ticks: 175 | party | market id | side | volume | price | resulting trades | type | tif | reference | 176 | sellSideMM | ETH/DEC19 | sell | 1 | 20000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 177 | buySideMM | ETH/DEC19 | buy | 1 | 20000000 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 178 179 And the following transfers should happen: 180 | from | to | from account | to account | market id | amount | asset | 181 | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 36399870 | ETH | 182 183 Then the parties should have the following account balances: 184 | party | asset | market id | margin | general | 185 | party1 | ETH | ETH/DEC19 | 203769794 | 832630096 | 186 And the parties should have the following margin levels: 187 | party | market id | maintenance | search | initial | release | 188 | party1 | ETH/DEC19 | 52303054 | 167369772 | 209212216 | 261515270 | 189 And the parties should have the following profit and loss: 190 | party | volume | unrealised pnl | realised pnl | 191 | party1 | 13 | 36399890 | 0 | 192 193 # FULL CLOSEOUT BY TRADER 194 When the parties place the following orders with ticks: 195 | party | market id | side | volume | price | resulting trades | type | tif | 196 | party1 | ETH/DEC19 | sell | 13 | 11600000 | 3 | TYPE_LIMIT | TIF_GTC | 197 And the parties should have the following margin levels: 198 | party | market id | maintenance | search | initial | release | 199 | party1 | ETH/DEC19 | 0 | 0 | 0 | 0 | 200 And the parties should have the following profit and loss: 201 | party | volume | unrealised pnl | realised pnl | 202 | party1 | 0 | 0 | 6999890 |