code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/596-Opened-positions-traded-out-but-there-is-still-money-sitting-in-a-margin-account.feature (about)

     1  Feature: Regression test for issue 596
     2  
     3    Background:
     4      Given the markets:
     5        | id        | quote name | asset | auction duration | risk model                    | margin calculator         | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
     6        | ETH/DEC19 | BTC        | BTC   | 1                | default-log-normal-risk-model | default-margin-calculator | default-none | default-none     | default-eth-for-future | 0.1                    | 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: Traded out position but monies left in margin account
    13      Given the parties deposit on asset's general account the following amount:
    14        | party  | asset | amount  |
    15        | edd    | BTC   | 10000   |
    16        | barney | BTC   | 10000   |
    17        | chris  | BTC   | 10000   |
    18        | party1 | BTC   | 1000000 |
    19        | party2 | BTC   | 1000000 |
    20        | aux    | BTC   | 1000    |
    21        | lpprov | BTC   | 1000000 |
    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 | 90000             | 0.1 | submission |
    26        | lp1 | lpprov | ETH/DEC19 | 90000             | 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 | reference |
    29        | lpprov | ETH/DEC19 | 90000     | 1                    | buy  | BID              | 90000   | 98     | ice-buy   |
    30        | lpprov | ETH/DEC19 | 444       | 1                    | sell | ASK              | 444     | 99     | ice-sell  |
    31  
    32      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    33      And the parties place the following orders:
    34        | party | market id | side | volume | price | resulting trades | type       | tif     |
    35        | aux   | ETH/DEC19 | buy  | 1      | 95    | 0                | TYPE_LIMIT | TIF_GTC |
    36        | aux   | ETH/DEC19 | sell | 1      | 105   | 0                | TYPE_LIMIT | TIF_GTC |
    37  
    38      # Trigger an auction to set the mark price
    39      Then the parties place the following orders:
    40        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    41        | party1 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party1-2  |
    42        | party2 | ETH/DEC19 | sell | 1      | 100   | 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 "100" for the market "ETH/DEC19"
    45  
    46      When the parties place the following orders with ticks:
    47        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    48        | edd    | ETH/DEC19 | sell | 20     | 101   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    49        | edd    | ETH/DEC19 | sell | 20     | 102   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    50        | edd    | ETH/DEC19 | sell | 10     | 103   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    51        | edd    | ETH/DEC19 | sell | 15     | 104   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    52        | edd    | ETH/DEC19 | sell | 30     | 105   | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
    53        | barney | ETH/DEC19 | buy  | 20     | 99    | 0                | TYPE_LIMIT | TIF_GTC | ref-6     |
    54        | barney | ETH/DEC19 | buy  | 12     | 98    | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
    55        | barney | ETH/DEC19 | buy  | 14     | 97    | 0                | TYPE_LIMIT | TIF_GTC | ref-8     |
    56        | barney | ETH/DEC19 | buy  | 20     | 96    | 0                | TYPE_LIMIT | TIF_GTC | ref-9     |
    57        | barney | ETH/DEC19 | buy  | 5      | 95    | 0                | TYPE_LIMIT | TIF_GTC | ref-10    |
    58      Then the parties should have the following account balances:
    59        | party  | asset | market id | margin | general |
    60        | edd    | BTC   | ETH/DEC19 | 848    | 9152    |
    61        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
    62      When the parties place the following orders with ticks:
    63        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    64        | chris | ETH/DEC19 | buy  | 50     | 110   | 3                | TYPE_LIMIT | TIF_GTC | ref-1     |
    65      Then the parties should have the following account balances:
    66        | party  | asset | market id | margin | general |
    67        | edd    | BTC   | ETH/DEC19 | 1491   | 8449    |
    68        | chris  | BTC   | ETH/DEC19 | 1048   | 8503    |
    69        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
    70      And the cumulated balance for all accounts should be worth "3031000"
    71      And the market data for the market "ETH/DEC19" should be:
    72        | trading mode            | best static bid price | best static offer price |
    73        | TRADING_MODE_CONTINUOUS | 99                    | 104                     | 
    74      And the order book should have the following volumes for market "ETH/DEC19":
    75        | side | price | volume |
    76        | sell | 203   |   444  |
    77        | sell | 105   |    31  |
    78        | sell | 104   |    15  |
    79        | buy  | 99    |    20  |
    80        | buy  | 98    |    12  |
    81        | buy  | 97    |    14  |
    82        | buy  | 96    |    20  |
    83        | buy  | 95    |     6  |
    84        | buy  |  1    | 90000  |
    85      When the parties amend the following pegged iceberg orders:
    86        | party  | reference | size delta | offset |
    87        | lpprov | ice-sell  | 0          | 96     |
    88        | lpprov | ice-buy   | 0          | 95     |
    89      #then chris is trading out
    90      And the parties place the following orders with ticks:
    91        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    92        | chris | ETH/DEC19 | sell | 50     | 90    | 4                | TYPE_LIMIT | TIF_GTC | ref-1     |
    93      Then the following trades should be executed:
    94        | buyer  | price | size | seller |
    95        | barney | 99    | 20   | chris  |
    96        | barney | 98    | 12   | chris  |
    97        | barney | 97    | 14   | chris  |
    98        | barney | 96    |  4   | chris  |
    99      And the parties should have the following profit and loss:
   100        | party  | volume | unrealised pnl | realised pnl |
   101        | edd    | -50    |  290           | 0            |
   102        | barney |  50    |  -98           | 0            |
   103        | chris  |   0    | 0              | -192         |
   104      And the order book should have the following volumes for market "ETH/DEC19":
   105        | side | price | volume |
   106        | sell | 200   |   444  |
   107        | sell | 105   |    31  |
   108        | sell | 104   |    15  |
   109        | buy  |  96   |    16  |
   110        | buy  |  95   |     6  |
   111        | buy  |   1   | 90000  |
   112      And the parties should have the following account balances:
   113        | party  | asset | market id | margin | general |
   114        | edd    | BTC   | ETH/DEC19 | 1390   | 8900    |
   115        | chris  | BTC   | ETH/DEC19 | 0      | 8808    |
   116        | barney | BTC   | ETH/DEC19 | 1146   | 8756    |
   117      And the cumulated balance for all accounts should be worth "3031000"
   118  
   119    Scenario: Traded out position, with cancelled half traded order, but monies left in margin account
   120      Given the parties deposit on asset's general account the following amount:
   121        | party  | asset | amount  |
   122        | edd    | BTC   | 10000   |
   123        | barney | BTC   | 10000   |
   124        | chris  | BTC   | 10000   |
   125        | party1 | BTC   | 1000000 |
   126        | party2 | BTC   | 1000000 |
   127        | aux    | BTC   | 1000    |
   128        | lpprov | BTC   | 1000000 |
   129  
   130      When the parties submit the following liquidity provision:
   131        | id  | party  | market id | commitment amount | fee | lp type    |
   132        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
   133        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
   134      And the parties place the following pegged iceberg orders:
   135        | party  | market id | peak size | minimum visible size | side | pegged reference | volume  | offset | reference |
   136        | lpprov | ETH/DEC19 | 90000     | 1                    | buy  | BID              | 90000   | 98     | ice-buy   |
   137        | lpprov | ETH/DEC19 | 444       | 1                    | sell | ASK              | 444     | 99     | ice-sell  |
   138   
   139      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   140      Then the parties place the following orders:
   141        | party | market id | side | volume | price | resulting trades | type       | tif     |
   142        | aux   | ETH/DEC19 | buy  | 1      | 95    | 0                | TYPE_LIMIT | TIF_GTC |
   143        | aux   | ETH/DEC19 | sell | 1      | 105   | 0                | TYPE_LIMIT | TIF_GTC |
   144  
   145      # Trigger an auction to set the mark price
   146      When the parties place the following orders:
   147        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   148        | party1 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party1-2  |
   149        | party2 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party2-2  |
   150      Then the opening auction period ends for market "ETH/DEC19"
   151      And the mark price should be "100" for the market "ETH/DEC19"
   152  
   153      When the parties place the following orders with ticks:
   154        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   155        | edd    | ETH/DEC19 | sell | 20     | 101   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   156        | edd    | ETH/DEC19 | sell | 20     | 102   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   157        | edd    | ETH/DEC19 | sell | 10     | 103   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   158        | edd    | ETH/DEC19 | sell | 15     | 104   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   159        | edd    | ETH/DEC19 | sell | 30     | 105   | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
   160        | barney | ETH/DEC19 | buy  | 20     | 99    | 0                | TYPE_LIMIT | TIF_GTC | ref-6     |
   161        | barney | ETH/DEC19 | buy  | 12     | 98    | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
   162        | barney | ETH/DEC19 | buy  | 14     | 97    | 0                | TYPE_LIMIT | TIF_GTC | ref-8     |
   163        | barney | ETH/DEC19 | buy  | 20     | 96    | 0                | TYPE_LIMIT | TIF_GTC | ref-10    |
   164        | barney | ETH/DEC19 | buy  | 5      | 95    | 0                | TYPE_LIMIT | TIF_GTC | ref-11    |
   165      Then the parties should have the following account balances:
   166        | party  | asset | market id | margin | general |
   167        | edd    | BTC   | ETH/DEC19 | 848    | 9152    |
   168        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
   169      # Chris place an order for a volume of 60, but only 2 trades happen at that price
   170      When the parties place the following orders with ticks:
   171        | party | market id | side | volume | price | resulting trades | type       | tif     | reference            |
   172        | chris | ETH/DEC19 | buy  | 60     | 102   | 2                | TYPE_LIMIT | TIF_GTC | chris-id-1-to-cancel |
   173      Then the parties should have the following account balances:
   174        | party  | asset | market id | margin | general |
   175        | edd    | BTC   | ETH/DEC19 | 1354   | 8626    |
   176        | chris  | BTC   | ETH/DEC19 | 1000   | 8614    |
   177        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
   178      And the cumulated balance for all accounts should be worth "3031000"
   179      Then the parties cancel the following orders:
   180        | party | reference            |
   181        | chris | chris-id-1-to-cancel |
   182      When the parties amend the following pegged iceberg orders:
   183        | party  | reference | size delta | offset |
   184        | lpprov | ice-sell  | 0          | 96     |
   185        | lpprov | ice-buy   | 0          | 95     |
   186      # then chris is trading out
   187      And the parties place the following orders with ticks:
   188        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   189        | chris | ETH/DEC19 | sell | 40     | 90    | 3                | TYPE_LIMIT | TIF_GTC | ref-1     |
   190      Then the parties should have the following account balances:
   191        | party  | asset | market id | margin | general |
   192        | edd    | BTC   | ETH/DEC19 | 1288   | 8892    |
   193        | chris  | BTC   | ETH/DEC19 | 0      | 9072    |
   194        | barney | BTC   | ETH/DEC19 | 1041   | 8907    |
   195      And the cumulated balance for all accounts should be worth "3031000"
   196      When the parties place the following orders with ticks:
   197        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   198        | barney | ETH/DEC19 | buy  | 1      | 105   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   199      Then the parties should have the following account balances:
   200        | party  | asset | market id | margin | general |
   201        | edd    | BTC   | ETH/DEC19 | 1380   | 8560    |
   202        | chris  | BTC   | ETH/DEC19 | 0      | 9072    |
   203        | barney | BTC   | ETH/DEC19 | 1290   | 8887    |
   204      And the cumulated balance for all accounts should be worth "3031000"