code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0011-MARA-ensure_margin_funds_are_released.feature (about) 1 Feature: Test margins releases on position = 0 2 3 Background: 4 Given the markets: 5 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 6 | ETH/DEC19 | BTC | BTC | default-simple-risk-model | default-overkill-margin-calculator | 1 | default-none | default-none | default-eth-for-future | 0.25 | 0 | default-futures | 7 And the following network parameters are set: 8 | name | value | 9 | network.markPriceUpdateMaximumFrequency | 0s | 10 | limits.markets.maxPeggedOrders | 2 | 11 12 Scenario: No margin left for fok order as first order (0011-MARA-003) 13 Given the parties deposit on asset's general account the following amount: 14 | party | asset | amount | 15 | partyGuy | BTC | 1000000000 | 16 | party1 | BTC | 1000000 | 17 | party2 | BTC | 1000000 | 18 | aux | BTC | 100000 | 19 | lpprov | BTC | 100000 | 20 21 When the parties submit the following liquidity provision: 22 | id | party | market id | commitment amount | fee | lp type | 23 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 24 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 25 And the parties place the following pegged iceberg orders: 26 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 27 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 10 | 28 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 10 | 29 30 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 31 Then the parties place the following orders: 32 | party | market id | side | volume | price | resulting trades | type | tif | 33 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 34 | aux | ETH/DEC19 | sell | 1 | 15001 | 0 | TYPE_LIMIT | TIF_GTC | 35 36 # Trigger an auction to set the mark price 37 When the parties place the following orders: 38 | party | market id | side | volume | price | resulting trades | type | tif | reference | 39 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 40 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 41 | party1 | ETH/DEC19 | buy | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 42 | party2 | ETH/DEC19 | sell | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 43 Then the opening auction period ends for market "ETH/DEC19" 44 And the mark price should be "94" for the market "ETH/DEC19" 45 Then the parties cancel the following orders: 46 | party | reference | 47 | party1 | party1-1 | 48 | party2 | party2-1 | 49 50 When the parties place the following orders with ticks: 51 | party | market id | side | volume | price | resulting trades | type | tif | reference | 52 | partyGuy | ETH/DEC19 | buy | 13 | 15000 | 0 | TYPE_LIMIT | TIF_FOK | ref-1 | 53 Then the parties should have the following account balances: 54 | party | asset | market id | margin | general | 55 | partyGuy | BTC | ETH/DEC19 | 0 | 1000000000 | 56 57 Scenario: No margin left for wash trade (0011-MARA-003) 58 Given the parties deposit on asset's general account the following amount: 59 | party | asset | amount | 60 | partyGuy | BTC | 1000000000 | 61 | party1 | BTC | 1000000 | 62 | party2 | BTC | 1000000 | 63 | aux | BTC | 100000 | 64 | lpprov | BTC | 100000 | 65 66 When the parties submit the following liquidity provision: 67 | id | party | market id | commitment amount | fee | lp type | 68 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 69 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 70 And the parties place the following pegged iceberg orders: 71 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 72 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 10 | 73 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 10 | 74 75 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 76 Then the parties place the following orders: 77 | party | market id | side | volume | price | resulting trades | type | tif | 78 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 79 | aux | ETH/DEC19 | sell | 1 | 15001 | 0 | TYPE_LIMIT | TIF_GTC | 80 81 # Trigger an auction to set the mark price 82 When the parties place the following orders: 83 | party | market id | side | volume | price | resulting trades | type | tif | reference | 84 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 85 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 86 | party1 | ETH/DEC19 | buy | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 87 | party2 | ETH/DEC19 | sell | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 88 Then the opening auction period ends for market "ETH/DEC19" 89 And the mark price should be "94" for the market "ETH/DEC19" 90 Then the parties cancel the following orders: 91 | party | reference | 92 | party1 | party1-1 | 93 | party2 | party2-1 | 94 95 When the parties place the following orders with ticks: 96 | party | market id | side | volume | price | resulting trades | type | tif | reference | 97 | partyGuy | ETH/DEC19 | buy | 13 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 98 Then the parties should have the following account balances: 99 | party | asset | market id | margin | general | 100 | partyGuy | BTC | ETH/DEC19 | 980 | 999999020 | 101 102 # now we place an order which would wash trade and see 103 When the parties place the following orders with ticks: 104 | party | market id | side | volume | price | resulting trades | type | tif | reference | 105 | partyGuy | ETH/DEC19 | sell | 13 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 106 107 # checking margins, should have the margins required for the current order 108 Then the parties should have the following account balances: 109 | party | asset | market id | margin | general | 110 | partyGuy | BTC | ETH/DEC19 | 980 | 999999020 | 111 112 Scenario: No margin left after cancelling order and getting back to 0 position (0011-MARA-003) 113 Given the parties deposit on asset's general account the following amount: 114 | party | asset | amount | 115 | partyGuy | BTC | 1000000000 | 116 | party1 | BTC | 1000000 | 117 | party2 | BTC | 1000000 | 118 | aux | BTC | 100000 | 119 | lpprov | BTC | 100000 | 120 121 When the parties submit the following liquidity provision: 122 | id | party | market id | commitment amount | fee | lp type | 123 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 124 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 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 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 10 | 128 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 10 | 129 130 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 131 Then the parties place the following orders: 132 | party | market id | side | volume | price | resulting trades | type | tif | 133 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 134 | aux | ETH/DEC19 | sell | 1 | 15001 | 0 | TYPE_LIMIT | TIF_GTC | 135 136 # Trigger an auction to set the mark price 137 When the parties place the following orders: 138 | party | market id | side | volume | price | resulting trades | type | tif | reference | 139 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 140 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 141 | party1 | ETH/DEC19 | buy | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 142 | party2 | ETH/DEC19 | sell | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 143 Then the opening auction period ends for market "ETH/DEC19" 144 And the mark price should be "94" for the market "ETH/DEC19" 145 Then the parties cancel the following orders: 146 | party | reference | 147 | party1 | party1-1 | 148 | party2 | party2-1 | 149 150 When the parties place the following orders with ticks: 151 | party | market id | side | volume | price | resulting trades | type | tif | reference | 152 | partyGuy | ETH/DEC19 | buy | 13 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 153 154 Then the parties should have the following account balances: 155 | party | asset | market id | margin | general | 156 | partyGuy | BTC | ETH/DEC19 | 980 | 999999020 | 157 158 Then the parties cancel the following orders: 159 | party | reference | 160 | partyGuy | ref-1 | 161 162 Then the parties should have the following account balances: 163 | party | asset | market id | margin | general | 164 | partyGuy | BTC | ETH/DEC19 | 0 | 1000000000 | 165 166 Scenario: No margin left for wash trade after cancelling first order (0011-MARA-003) 167 Given the parties deposit on asset's general account the following amount: 168 | party | asset | amount | 169 | partyGuy | BTC | 1000000000 | 170 | party1 | BTC | 1000000 | 171 | party2 | BTC | 1000000 | 172 | aux | BTC | 100000 | 173 | lpprov | BTC | 100000 | 174 175 When the parties submit the following liquidity provision: 176 | id | party | market id | commitment amount | fee | lp type | 177 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 178 | lp1 | lpprov | ETH/DEC19 | 90000 | 0.1 | submission | 179 And the parties place the following pegged iceberg orders: 180 | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset | 181 | lpprov | ETH/DEC19 | 2 | 1 | buy | BID | 50 | 10 | 182 | lpprov | ETH/DEC19 | 2 | 1 | sell | ASK | 50 | 10 | 183 184 # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction 185 Then the parties place the following orders: 186 | party | market id | side | volume | price | resulting trades | type | tif | 187 | aux | ETH/DEC19 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | 188 | aux | ETH/DEC19 | sell | 1 | 15001 | 0 | TYPE_LIMIT | TIF_GTC | 189 190 # Trigger an auction to set the mark price 191 When the parties place the following orders: 192 | party | market id | side | volume | price | resulting trades | type | tif | reference | 193 | party1 | ETH/DEC19 | buy | 1 | 10 | 0 | TYPE_LIMIT | TIF_GTC | party1-1 | 194 | party2 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | party2-1 | 195 | party1 | ETH/DEC19 | buy | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party1-2 | 196 | party2 | ETH/DEC19 | sell | 1 | 94 | 0 | TYPE_LIMIT | TIF_GFA | party2-2 | 197 Then the opening auction period ends for market "ETH/DEC19" 198 And the mark price should be "94" for the market "ETH/DEC19" 199 Then the parties cancel the following orders: 200 | party | reference | 201 | party1 | party1-1 | 202 | party2 | party2-1 | 203 204 When the parties place the following orders with ticks: 205 | party | market id | side | volume | price | resulting trades | type | tif | reference | 206 | partyGuy | ETH/DEC19 | buy | 13 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | 207 208 Then the parties should have the following account balances: 209 | party | asset | market id | margin | general | 210 | partyGuy | BTC | ETH/DEC19 | 980 | 999999020 | 211 212 # now we place an order which would wash trade and see 213 When the parties place the following orders with ticks: 214 | party | market id | side | volume | price | resulting trades | type | tif | reference | 215 | partyGuy | ETH/DEC19 | sell | 13 | 15000 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | 216 217 # checking margins, should have the margins required for the current order 218 Then the parties should have the following account balances: 219 | party | asset | market id | margin | general | 220 | partyGuy | BTC | ETH/DEC19 | 980 | 999999020 | 221 222 # cancel the first order 223 Then the parties cancel the following orders: 224 | party | reference | 225 | partyGuy | ref-1 | 226 227 Then the parties should have the following account balances: 228 | party | asset | market id | margin | general | 229 | partyGuy | BTC | ETH/DEC19 | 0 | 1000000000 |