code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/verified_margins_case1-decimal-places.feature (about) 1 Feature: CASE-1: Trader submits long order that will trade - new formula & high exit price 2 # https://drive.google.com/drive/folders/1BCOKaEb7LZYAKoiPfXfaqwM4BNicPpF- 3 4 Background: 5 6 Given the following assets are registered: 7 | id | decimal places | 8 | ETH | 5 | 9 And the markets: 10 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | decimal places | linear slippage factor | quadratic slippage factor | sla params | 11 | ETH/DEC19 | ETH | ETH | default-simple-risk-model | default-overkill-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 2 | 0.341758241785 | 0 | default-futures | 12 And the following network parameters are set: 13 | name | value | 14 | market.auction.minimumDuration | 1 | 15 And the parties deposit on asset's general account the following amount: 16 | party | asset | amount | 17 | party1 | ETH | 100000000000000 | 18 | sellSideMM | ETH | 100000000000000 | 19 | buySideMM | ETH | 100000000000000 | 20 | aux | ETH | 100000000000000 | 21 | aux2 | ETH | 100000000000000 | 22 | lpprov | ETH | 100000000000000 | 23 And the following network parameters are set: 24 | name | value | 25 | network.markPriceUpdateMaximumFrequency | 0s | 26 | limits.markets.maxPeggedOrders | 2 | 27 28 When the parties submit the following liquidity provision: 29 | id | party | market id | commitment amount | fee | lp type | 30 | lp1 | lpprov | ETH/DEC19 | 90000000000 | 0.0 | submission | 31 | lp1 | lpprov | ETH/DEC19 | 90000000000 | 0.0 | submission | 32 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 33 Then the parties place the following orders: 34 | party | market id | side | volume | price | resulting trades | type | tif | 35 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 36 | aux | ETH/DEC19 | sell | 1 | 20000000 | 0 | TYPE_LIMIT | TIF_GTC | 37 | aux | ETH/DEC19 | buy | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | 38 | aux2 | ETH/DEC19 | sell | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | 39 Then the opening auction period ends for market "ETH/DEC19" 40 And the mark price should be "10300000" for the market "ETH/DEC19" 41 And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19" 42 43 # setting mark price 44 And the parties place the following orders with ticks: 45 | party | market id | side | volume | price | resulting trades | type | tif | reference | 46 | sellSideMM | ETH/DEC19 | sell | 1 | 10300000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 47 | buySideMM | ETH/DEC19 | buy | 1 | 10300000 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 48 49 50 # setting order book 51 And the parties place the following orders with ticks: 52 | party | market id | side | volume | price | resulting trades | type | tif | reference | 53 | sellSideMM | ETH/DEC19 | sell | 100 | 25000000 | 0 | TYPE_LIMIT | TIF_GTC | _sell1 | 54 | sellSideMM | ETH/DEC19 | sell | 11 | 14000000 | 0 | TYPE_LIMIT | TIF_GTC | _sell2 | 55 | sellSideMM | ETH/DEC19 | sell | 2 | 11200000 | 0 | TYPE_LIMIT | TIF_GTC | _sell3 | 56 | buySideMM | ETH/DEC19 | buy | 1 | 10000000 | 0 | TYPE_LIMIT | TIF_GTC | buy1 | 57 | buySideMM | ETH/DEC19 | buy | 3 | 9600000 | 0 | TYPE_LIMIT | TIF_GTC | buy2 | 58 | buySideMM | ETH/DEC19 | buy | 15 | 9000000 | 0 | TYPE_LIMIT | TIF_GTC | buy3 | 59 | buySideMM | ETH/DEC19 | buy | 50 | 8700000 | 0 | TYPE_LIMIT | TIF_GTC | _buy4 | 60 61 62 Scenario: 63 # no margin account created for party1, just general account 64 And "party1" should have one account per asset 65 # placing test order 66 When the parties place the following orders with ticks: 67 | party | market id | side | volume | price | resulting trades | type | tif | reference | 68 | party1 | ETH/DEC19 | buy | 13 | 15000000 | 2 | TYPE_LIMIT | TIF_GTC | ref-1 | 69 And "party1" should have general account balance of "99611199999980" for asset "ETH" 70 And the following trades should be executed: 71 | buyer | price | size | seller | 72 | party1 | 11200000 | 2 | sellSideMM | 73 | party1 | 14000000 | 11 | sellSideMM | 74 75 Then the following transfers should happen: 76 | from | to | from account | to account | market id | amount | asset | 77 | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 5600000000 | ETH | 78 79 Then the parties should have the following account balances: 80 | party | asset | market id | margin | general | 81 | party1 | ETH | ETH/DEC19 | 394400000020 | 99611199999980 | 82 And the parties should have the following margin levels: 83 | party | market id | maintenance | search | initial | release | 84 | party1 | ETH/DEC19 | 98600000005 | 315520000016 | 394400000020 | 493000000025 | 85 And the parties should have the following profit and loss: 86 | party | volume | unrealised pnl | realised pnl | 87 | party1 | 13 | 5600000000 | 0 | 88 89 # NEW ORDERS ADDED WITHOUT ANOTHER TRADE HAPPENING 90 Then the parties cancel the following orders: 91 | party | reference | 92 | buySideMM | buy1 | 93 | buySideMM | buy2 | 94 | buySideMM | buy3 | 95 When the parties place the following orders with ticks: 96 | party | market id | side | volume | price | resulting trades | type | tif | reference | 97 | buySideMM | ETH/DEC19 | buy | 1 | 19000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 98 | buySideMM | ETH/DEC19 | buy | 3 | 18000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 99 | buySideMM | ETH/DEC19 | buy | 15 | 17000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-3 | 100 101 Then the parties should have the following account balances: 102 | party | asset | market id | margin | general | 103 | party1 | ETH | ETH/DEC19 | 394400000020 | 99611199999980 | 104 105 And the parties should have the following margin levels: 106 | party | market id | maintenance | search | initial | release | 107 | party1 | ETH/DEC19 | 98600000005 | 315520000016 | 394400000020 | 493000000025 | 108 And the parties should have the following profit and loss: 109 | party | volume | unrealised pnl | realised pnl | 110 | party1 | 13 | 5600000000 | 0 | 111 112 # ANOTHER TRADE HAPPENING (BY A DIFFERENT PARTY) 113 # updating mark price to 200 114 When the parties place the following orders with ticks: 115 | party | market id | side | volume | price | resulting trades | type | tif | reference | 116 | sellSideMM | ETH/DEC19 | sell | 1 | 20000000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 117 | buySideMM | ETH/DEC19 | buy | 1 | 20000000 | 1 | TYPE_LIMIT | TIF_GTC | ref-2 | 118 119 And the following transfers should happen: 120 | from | to | from account | to account | market id | amount | asset | 121 | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 78000000000 | ETH | 122 123 Then the parties should have the following account balances: 124 | party | asset | market id | margin | general | 125 | party1 | ETH | ETH/DEC19 | 472400000020 | 99611199999980 | 126 And the parties should have the following margin levels: 127 | party | market id | maintenance | 128 | party1 | ETH/DEC19 | 140857142865 | 129 And the parties should have the following profit and loss: 130 | party | volume | unrealised pnl | realised pnl | 131 | party1 | 13 | 83600000000 | 0 | 132 133 # FULL CLOSEOUT BY TRADER 134 When the parties place the following orders with ticks: 135 | party | market id | side | volume | price | resulting trades | type | tif | reference | 136 | party1 | ETH/DEC19 | sell | 13 | 16500000 | 3 | TYPE_LIMIT | TIF_GTC | ref-1 | 137 And the parties should have the following margin levels: 138 | party | market id | maintenance | search | initial | release | 139 | party1 | ETH/DEC19 | 0 | 0 | 0 | 0 | 140 And the parties should have the following profit and loss: 141 | party | volume | unrealised pnl | realised pnl | 142 | party1 | 0 | 0 | 49600000000 |