code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0011-MARA-006.feature (about) 1 Feature: check margin account with partially filled order 2 3 Background: 4 Given the log normal risk model named "log-normal-risk-model-1": 5 | risk aversion | tau | mu | r | sigma | 6 | 0.000001 | 0.1 | 0 | 0 | 1.0 | 7 #risk factor short = 3.55690359157934000 8 #risk factor long = 0.801225765 9 And the margin calculator named "margin-calculator-0": 10 | search factor | initial factor | release factor | 11 | 1.2 | 1.5 | 2 | 12 And the price monitoring named "price-monitoring-1": 13 | horizon | probability | auction extension | 14 | 3600 | 0.99 | 300 | 15 16 And the markets: 17 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 18 | ETH/DEC20 | BTC | USD | log-normal-risk-model-1 | margin-calculator-0 | 1 | default-none | default-none | default-eth-for-future | 20 | 0 | default-futures | 19 | ETH/DEC21 | BTC | USD | log-normal-risk-model-1 | margin-calculator-0 | 1 | default-none | price-monitoring-1| default-eth-for-future | 20 | 0 | default-futures | 20 And the following network parameters are set: 21 | name | value | 22 | market.auction.minimumDuration | 1 | 23 | network.markPriceUpdateMaximumFrequency | 0s | 24 | limits.markets.maxPeggedOrders | 2 | 25 And the average block duration is "1" 26 27 @Liquidation 28 Scenario: 001 If an order is partially filled and if this leads to a reduced position and reduced riskiest long / short then the margin requirements are seen to be reduced and if margin balance is above release level then the excess amount is transferred to the general account.0011-MARA-006. 0011-MARA-008 29 Given the parties deposit on asset's general account the following amount: 30 | party | asset | amount | 31 | auxiliary1 | USD | 1000000000000 | 32 | auxiliary2 | USD | 1000000000000 | 33 | trader2 | USD | 90000 | 34 | trader20 | USD | 1000000000000 | 35 | trader3 | USD | 90000 | 36 | lprov | USD | 1000000000000 | 37 38 When the parties submit the following liquidity provision: 39 | id | party | market id | commitment amount | fee | lp type | 40 | lp0 | lprov | ETH/DEC20 | 100000 | 0.001 | submission | 41 | lp0 | lprov | ETH/DEC20 | 100000 | 0.001 | amendment | 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 | lprov | ETH/DEC20 | 100 | 1 | sell | ASK | 100 | 55 | 45 | lprov | ETH/DEC20 | 100 | 1 | buy | BID | 100 | 55 | 46 47 Then the parties place the following orders: 48 | party | market id | side | volume | price | resulting trades | type | tif | reference | 49 | auxiliary2 | ETH/DEC20 | buy | 5 | 5 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-50 | 50 | auxiliary1 | ETH/DEC20 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-10000 | 51 | auxiliary2 | ETH/DEC20 | buy | 10 | 10 | 0 | TYPE_LIMIT | TIF_GTC | aux-b-10 | 52 | auxiliary1 | ETH/DEC20 | sell | 10 | 10 | 0 | TYPE_LIMIT | TIF_GTC | aux-s-10 | 53 54 When the opening auction period ends for market "ETH/DEC20" 55 And the mark price should be "10" for the market "ETH/DEC20" 56 57 # setup trader2 position for an order which is partially filled and leading to a reduced position 58 When the parties place the following orders with ticks: 59 | party | market id | side | volume | price | resulting trades | type | tif | reference | 60 | trader2 | ETH/DEC20 | sell | 40 | 50 | 0 | TYPE_LIMIT | TIF_GTC | buy-order-3 | 61 | trader20 | ETH/DEC20 | buy | 40 | 50 | 1 | TYPE_LIMIT | TIF_GTC | buy-order-3 | 62 63 And the parties should have the following margin levels: 64 | party | market id | maintenance | 65 | trader2 | ETH/DEC20 | 47114 | 66 67 Then the parties should have the following account balances: 68 | party | asset | market id | margin | general | 69 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 70 71 When the parties place the following orders with ticks: 72 | party | market id | side | volume | price | resulting trades | type | tif | reference | 73 | trader2 | ETH/DEC20 | buy | 40 | 50 | 0 | TYPE_LIMIT | TIF_GTC | buy-order-4 | 74 75 And the parties should have the following margin levels: 76 | party | market id | maintenance | 77 | trader2 | ETH/DEC20 | 47114 | 78 79 Then the parties should have the following account balances: 80 | party | asset | market id | margin | general | 81 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 82 83 When the parties place the following orders with ticks: 84 | party | market id | side | volume | price | resulting trades | type | tif | reference | 85 | trader20 | ETH/DEC20 | sell | 10 | 50 | 1 | TYPE_LIMIT | TIF_GTC | sell-order-4 | 86 87 And the parties should have the following margin levels: 88 | party | market id | maintenance | 89 | trader2 | ETH/DEC20 | 35336 | 90 91 # margin is under above level, then the excess amount is transferred to the general account 92 Then the parties should have the following account balances: 93 | party | asset | market id | margin | general | 94 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 95 96 When the parties place the following orders with ticks: 97 | party | market id | side | volume | price | resulting trades | type | tif | reference | 98 | trader20 | ETH/DEC20 | sell | 1 | 50 | 1 | TYPE_LIMIT | TIF_GTC | sell-order-4 | 99 100 And the parties should have the following margin levels: 101 | party | market id | maintenance | 102 | trader2 | ETH/DEC20 | 34158 | 103 104 # margin is under release level, then no excess amount is transferred to the general account 105 Then the parties should have the following account balances: 106 | party | asset | market id | margin | general | 107 | trader2 | USD | ETH/DEC20 | 51237 | 38763 | 108 109 @Liquidation 110 Scenario: 002 check margin for GTT order type.0011-MARA-007 111 Given the parties deposit on asset's general account the following amount: 112 | party | asset | amount | 113 | auxiliary1 | USD | 1000000000000 | 114 | auxiliary2 | USD | 1000000000000 | 115 | trader2 | USD | 90000 | 116 | trader20 | USD | 1000000000000 | 117 | trader3 | USD | 90000 | 118 | trader4 | USD | 90000 | 119 | lprov | USD | 1000000000000 | 120 121 When the parties submit the following liquidity provision: 122 | id | party | market id | commitment amount | fee | lp type | 123 | lp0 | lprov | ETH/DEC20 | 100000 | 0.001 | submission | 124 | lp0 | lprov | ETH/DEC20 | 100000 | 0.001 | amendment | 125 And the parties place the following pegged iceberg orders: 126 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 127 | lprov | ETH/DEC20 | 2 | 1 | sell | ASK | 100 | 55 | 128 | lprov | ETH/DEC20 | 2 | 1 | buy | BID | 100 | 55 | 129 130 Then the parties place the following orders: 131 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 132 | auxiliary2 | ETH/DEC20 | buy | 5 | 5 | 0 | TYPE_LIMIT | TIF_GTC | 6 | 133 | auxiliary1 | ETH/DEC20 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | 6 | 134 | auxiliary2 | ETH/DEC20 | buy | 10 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 6 | 135 | auxiliary1 | ETH/DEC20 | sell | 10 | 10 | 0 | TYPE_LIMIT | TIF_GTC | 6 | 136 137 When the opening auction period ends for market "ETH/DEC20" 138 And the mark price should be "10" for the market "ETH/DEC20" 139 140 # setup trader2 position for an order which is partially filled and leading to a reduced position 141 When the parties place the following orders with ticks: 142 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 143 | trader2 | ETH/DEC20 | sell | 40 | 50 | 0 | TYPE_LIMIT | TIF_GTT | 6 | 144 | trader20 | ETH/DEC20 | buy | 40 | 50 | 1 | TYPE_LIMIT | TIF_GTT | 6 | 145 146 And the parties should have the following margin levels: 147 | party | market id | maintenance | 148 | trader2 | ETH/DEC20 | 47114 | 149 150 Then the parties should have the following account balances: 151 | party | asset | market id | margin | general | 152 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 153 154 When the parties place the following orders with ticks: 155 | party | market id | side | volume | price | resulting trades | type | tif |expires in | 156 | trader2 | ETH/DEC20 | buy | 40 | 50 | 0 | TYPE_LIMIT | TIF_GTT | 6 | 157 158 And the parties should have the following margin levels: 159 | party | market id | maintenance | 160 | trader2 | ETH/DEC20 | 47114 | 161 162 Then the parties should have the following account balances: 163 | party | asset | market id | margin | general | 164 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 165 166 When the parties place the following orders with ticks: 167 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 168 | trader20 | ETH/DEC20 | sell | 10 | 50 | 1 | TYPE_LIMIT | TIF_GTT | 6 | 169 170 And the parties should have the following margin levels: 171 | party | market id | maintenance | 172 | trader2 | ETH/DEC20 | 35336 | 173 174 Then the parties should have the following account balances: 175 | party | asset | market id | margin | general | 176 | trader2 | USD | ETH/DEC20 | 70671 | 19329 | 177 178 When the parties place the following orders with ticks: 179 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 180 | trader20 | ETH/DEC20 | sell | 1 | 50 | 1 | TYPE_LIMIT | TIF_GTT | 6 | 181 182 And the parties should have the following margin levels: 183 | party | market id | maintenance | 184 | trader2 | ETH/DEC20 | 34158 | 185 186 Then the parties should have the following account balances: 187 | party | asset | market id | margin | general | 188 | trader2 | USD | ETH/DEC20 | 51237 | 38763 | 189 # trader3 places a new order 190 When the parties place the following orders with ticks: 191 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 192 | trader3 | ETH/DEC20 | buy | 20 | 45 | 0 | TYPE_LIMIT | TIF_GTT | 3 | 193 194 And the parties should have the following margin levels: 195 | party | market id | maintenance | 196 | trader3 | ETH/DEC20 | 801 | 197 198 Then the parties should have the following account balances: 199 | party | asset | market id | margin | general | 200 | trader3 | USD | ETH/DEC20 | 1201 | 88799 | 201 202 Then the network moves ahead "7" blocks 203 #GTT order expires 204 And the parties should have the following margin levels: 205 | party | market id | maintenance | search | initial | release | 206 | trader3 | ETH/DEC20 | 0 | 0 | 0 | 0 | 207 208 Then the parties should have the following account balances: 209 | party | asset | market id | margin | general | 210 | trader3 | USD | ETH/DEC20 | 0 | 90000 | 211 #reset mark price 212 When the parties place the following orders with ticks: 213 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 214 | trader2 | ETH/DEC20 | buy | 1 | 50 | 0 | TYPE_LIMIT | TIF_GTT | 6 | 215 | trader20 | ETH/DEC20 | sell | 1 | 50 | 1 | TYPE_LIMIT | TIF_GTT | 6 | 216 217 And the parties should have the following margin levels: 218 | party | market id | maintenance | search | initial | release | 219 | trader3 | ETH/DEC20 | 0 | 0 | 0 | 0 | 220 221 Then the parties should have the following account balances: 222 | party | asset | market id | margin | general | 223 | trader3 | USD | ETH/DEC20 | 0 | 90000 | 224 225 When the parties place the following orders with ticks: 226 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 227 | trader3 | ETH/DEC20 | buy | 10 | 45 | 0 | TYPE_LIMIT | TIF_GTT | 3 | 228 229 And the parties should have the following margin levels: 230 | party | market id | maintenance | search | initial | release | 231 | trader3 | ETH/DEC20 | 401 | 481 | 601 | 802 | 232 233 Then the parties should have the following account balances: 234 | party | asset | market id | margin | general | 235 | trader3 | USD | ETH/DEC20 | 601 | 89399 | 236 237 Then the network moves ahead "7" blocks 238 #GTT order expires 239 And the parties should have the following margin levels: 240 | party | market id | maintenance | search | initial | release | 241 | trader3 | ETH/DEC20 | 0 | 0 | 0 | 0 | 242 243 Then the parties should have the following account balances: 244 | party | asset | market id | margin | general | 245 | trader3 | USD | ETH/DEC20 | 0 | 90000 | 246 247 # now we create a case when trader 4 place a GTC order first and then GTT order 248 When the parties place the following orders with ticks: 249 | party | market id | side | volume | price | resulting trades | type | tif | expires in | 250 | trader4 | ETH/DEC20 | buy | 5 | 45 | 0 | TYPE_LIMIT | TIF_GTC | | 251 | trader4 | ETH/DEC20 | buy | 10 | 45 | 0 | TYPE_LIMIT | TIF_GTT | 3 | 252 253 And the parties should have the following margin levels: 254 | party | market id | maintenance | search | initial | release | 255 | trader4 | ETH/DEC20 | 601 | 721 | 901 | 1202 | 256 257 Then the parties should have the following account balances: 258 | party | asset | market id | margin | general | 259 | trader4 | USD | ETH/DEC20 | 901 | 89099 | 260 261 Then the network moves ahead "7" blocks 262 And the parties should have the following margin levels: 263 | party | market id | maintenance | search | initial | release | 264 | trader4 | ETH/DEC20 | 601 | 721 | 901 | 1202 | 265 266 Then the parties should have the following account balances: 267 | party | asset | market id | margin | general | 268 | trader4 | USD | ETH/DEC20 | 901 | 89099 | 269 270 @Liquidation 271 Scenario: 003 check margin for GFN order type 0011-MARA-009 272 Given the parties deposit on asset's general account the following amount: 273 | party | asset | amount | 274 | auxiliary1 | USD | 1000000000000 | 275 | auxiliary2 | USD | 1000000000000 | 276 | trader2 | USD | 90000 | 277 | trader20 | USD | 9000000000000 | 278 | trader3 | USD | 90000 | 279 | lprov | USD | 1000000000000 | 280 281 When the parties submit the following liquidity provision: 282 | id | party | market id | commitment amount | fee | lp type | 283 | lp0 | lprov | ETH/DEC21 | 100000 | 0.001 | submission | 284 | lp0 | lprov | ETH/DEC21 | 100000 | 0.001 | amendment | 285 And the parties place the following pegged iceberg orders: 286 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 287 | lprov | ETH/DEC21 | 2 | 1 | sell | ASK | 100 | 55 | 288 | lprov | ETH/DEC21 | 2 | 1 | buy | BID | 100 | 55 | 289 290 Then the parties place the following orders: 291 | party | market id | side | volume | price | resulting trades | type | tif | 292 | auxiliary2 | ETH/DEC21 | buy | 5 | 5 | 0 | TYPE_LIMIT | TIF_GTC | 293 | auxiliary1 | ETH/DEC21 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | 294 | auxiliary2 | ETH/DEC21 | buy | 10 | 50 | 0 | TYPE_LIMIT | TIF_GTC | 295 | auxiliary1 | ETH/DEC21 | sell | 10 | 50 | 0 | TYPE_LIMIT | TIF_GTC | 296 297 When the opening auction period ends for market "ETH/DEC21" 298 And the market data for the market "ETH/DEC21" should be: 299 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 300 | 50 | TRADING_MODE_CONTINUOUS | 3600 | 49 | 51 | 17784 | 100000 | 10 | 301 When the parties place the following orders with ticks: 302 | party | market id | side | volume | price | resulting trades | type | tif | 303 | trader2 | ETH/DEC21 | sell | 40 | 50 | 0 | TYPE_LIMIT | TIF_GFN | 304 | trader20 | ETH/DEC21 | buy | 40 | 50 | 1 | TYPE_LIMIT | TIF_GFN | 305 306 And the parties should have the following margin levels: 307 | party | market id | maintenance | 308 | trader2 | ETH/DEC21 | 47114 | 309 310 Then the parties should have the following account balances: 311 | party | asset | market id | margin | general | 312 | trader2 | USD | ETH/DEC21 | 70671 | 19329 | 313 314 When the parties place the following orders with ticks: 315 | party | market id | side | volume | price | resulting trades | type | tif |reference | 316 | trader2 | ETH/DEC21 | buy | 40 | 50 | 0 | TYPE_LIMIT | TIF_GFN | GFN-order-1 | 317 318 And the parties should have the following margin levels: 319 | party | market id | maintenance | 320 | trader2 | ETH/DEC21 | 47114 | 321 322 Then the parties should have the following account balances: 323 | party | asset | market id | margin | general | 324 | trader2 | USD | ETH/DEC21 | 70671 | 19329 | 325 326 When the parties place the following orders with ticks: 327 | party | market id | side | volume | price | resulting trades | type | tif | reference | 328 | trader20 | ETH/DEC21 | sell | 1 | 50 | 1 | TYPE_LIMIT | TIF_GFN | t20-ref | 329 330 And the parties should have the following margin levels: 331 | party | market id | maintenance | 332 | trader2 | ETH/DEC21 | 45936 | 333 334 # margin is under above level, then the excess amount is transferred to the general account 335 Then the parties should have the following account balances: 336 | party | asset | market id | margin | general | 337 | trader2 | USD | ETH/DEC21 | 70671 | 19329 | 338 339 And the orders should have the following status: 340 | party | reference | status | 341 | trader2 | GFN-order-1 | STATUS_ACTIVE | 342 343 # trigger auction 344 When the parties place the following orders with ticks: 345 | party | market id | side | volume | price | resulting trades | type | tif | 346 | auxiliary1 | ETH/DEC21 | sell | 1 | 52 | 0 | TYPE_LIMIT | TIF_GTC | 347 | auxiliary2 | ETH/DEC21 | buy | 1 | 52 | 0 | TYPE_LIMIT | TIF_GTC | 348 349 And the trading mode should be "TRADING_MODE_MONITORING_AUCTION" for the market "ETH/DEC21" 350 351 #GFN order is canceled during auction 352 And the orders should have the following status: 353 | party | reference | status | 354 | trader2 | GFN-order-1 | STATUS_CANCELLED |