code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/596-margin-account-non-zero-after-trading-out-market-order.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         | data source config     | price monitoring | 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-eth-for-future | default-none     | 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        | tamlyn | BTC   | 10000   |
    19        | party1 | BTC   | 1000000 |
    20        | party2 | BTC   | 1000000 |
    21        | aux    | BTC   | 1000    |
    22        | lpprov | BTC   | 1000000 |
    23  
    24      When the parties submit the following liquidity provision:
    25        | id  | party  | market id | commitment amount | fee | lp type    |
    26        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
    27        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
    28      And the parties place the following pegged iceberg orders:
    29        | party  | market id | peak size | minimum visible size | side | pegged reference | volume  | offset | reference |
    30        | lpprov | ETH/DEC19 | 90000     | 1                    | buy  | BID              | 90000   | 98     | ice-buy   |
    31        | lpprov | ETH/DEC19 | 444       | 1                    | sell | ASK              | 444     | 99     | ice-sell  |
    32   
    33      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    34      Then the parties place the following orders:
    35        | party | market id | side | volume | price | resulting trades | type       | tif     |
    36        | aux   | ETH/DEC19 | buy  | 1      | 95    | 0                | TYPE_LIMIT | TIF_GTC |
    37        | aux   | ETH/DEC19 | sell | 1      | 105   | 0                | TYPE_LIMIT | TIF_GTC |
    38  
    39      # Trigger an auction to set the mark price
    40      When the parties place the following orders:
    41        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    42        | party1 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party1-2  |
    43        | party2 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party2-2  |
    44      Then the opening auction period ends for market "ETH/DEC19"
    45      And the mark price should be "100" for the market "ETH/DEC19"
    46  
    47      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    48  
    49      When the parties place the following orders with ticks:
    50        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    51        | edd    | ETH/DEC19 | sell | 20     | 101   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    52        | edd    | ETH/DEC19 | sell | 20     | 102   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
    53        | edd    | ETH/DEC19 | sell | 10     | 103   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
    54        | edd    | ETH/DEC19 | sell | 15     | 104   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
    55        | edd    | ETH/DEC19 | sell | 30     | 105   | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
    56        | barney | ETH/DEC19 | buy  | 20     | 99    | 0                | TYPE_LIMIT | TIF_GTC | ref-6     |
    57        | barney | ETH/DEC19 | buy  | 12     | 98    | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
    58        | barney | ETH/DEC19 | buy  | 14     | 97    | 0                | TYPE_LIMIT | TIF_GTC | ref-8     |
    59        | barney | ETH/DEC19 | buy  | 20     | 96    | 0                | TYPE_LIMIT | TIF_GTC | ref-9     |
    60        | barney | ETH/DEC19 | buy  | 5      | 95    | 0                | TYPE_LIMIT | TIF_GTC | ref-10    |
    61      Then the parties should have the following account balances:
    62        | party  | asset | market id | margin | general |
    63        | edd    | BTC   | ETH/DEC19 | 848    | 9152    |
    64        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
    65      When the parties place the following orders with ticks:
    66        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
    67        | chris | ETH/DEC19 | buy  | 50     | 0     | 3                | TYPE_MARKET | TIF_IOC | ref-1     |
    68      Then the parties should have the following account balances:
    69        | party  | asset | market id | margin | general |
    70        | edd    | BTC   | ETH/DEC19 | 1491   | 8449    |
    71        | chris  | BTC   | ETH/DEC19 | 1077   | 8474    |
    72        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
    73      And the cumulated balance for all accounts should be worth "3041000"
    74      
    75      When the parties amend the following pegged iceberg orders:
    76        | party  | reference | size delta | offset |
    77        | lpprov | ice-sell  | 0          | 96     |
    78        | lpprov | ice-buy   | 0          | 95     |
    79      # then chris is trading out
    80      And the parties place the following orders with ticks:
    81        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
    82        | chris | ETH/DEC19 | sell | 50     | 0     | 4                | TYPE_MARKET | TIF_IOC | ref-1     |
    83      Then the parties should have the following account balances:
    84        | party  | asset | market id | margin | general |
    85        | edd    | BTC   | ETH/DEC19 | 1390   | 8900    |
    86        | chris  | BTC   | ETH/DEC19 | 0      | 8808    |
    87        | barney | BTC   | ETH/DEC19 | 1146   | 8756    |
    88      And the cumulated balance for all accounts should be worth "3041000"
    89      # placing new orders to trade out
    90      When the parties place the following orders with ticks:
    91        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
    92        | chris | ETH/DEC19 | buy  | 5      | 0     | 1                | TYPE_MARKET | TIF_IOC | ref-1     |
    93      # placing order which get cancelled
    94      When the parties place the following orders with ticks:
    95        | party | market id | side | volume | price | resulting trades | type       | tif     | reference            |
    96        | chris | ETH/DEC19 | buy  | 60     | 1     | 0                | TYPE_LIMIT | TIF_GTC | chris-id-1-to-cancel |
    97      # # other parties trade together (tamlyn+barney)
    98      When the parties place the following orders with ticks:
    99        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   100        | tamlyn | ETH/DEC19 | sell | 12     | 95    | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   101      # cancel order
   102      Then the parties cancel the following orders:
   103        | party | reference            |
   104        | chris | chris-id-1-to-cancel |
   105      # then chris is trading out
   106      When the parties place the following orders with ticks:
   107        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
   108        | chris | ETH/DEC19 | sell | 5      | 0     | 2                | TYPE_MARKET | TIF_IOC | ref-1     |
   109      Then the parties should have the following account balances:
   110        | party | asset | market id | margin | general |
   111        | chris | BTC   | ETH/DEC19 | 0      | 8666    |
   112      And the cumulated balance for all accounts should be worth "3041000"
   113  
   114    Scenario: Traded out position but monies left in margin account if trade which trade out do not update the markprice
   115      Given the parties deposit on asset's general account the following amount:
   116        | party  | asset | amount  |
   117        | edd    | BTC   | 10000   |
   118        | barney | BTC   | 10000   |
   119        | chris  | BTC   | 10000   |
   120        | tamlyn | BTC   | 10000   |
   121        | party1 | BTC   | 1000000 |
   122        | party2 | BTC   | 1000000 |
   123        | aux    | BTC   | 1000    |
   124        | lpprov | BTC   | 1000000 |
   125  
   126      When the parties submit the following liquidity provision:
   127        | id  | party  | market id | commitment amount | fee | lp type    |
   128        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
   129        | lp1 | lpprov | ETH/DEC19 | 90000             | 0.1 | submission |
   130      And the parties place the following pegged iceberg orders:
   131        | party  | market id | peak size | minimum visible size | side | pegged reference | volume  | offset | reference |
   132        | lpprov | ETH/DEC19 | 90000     | 1                    | buy  | BID              | 90000   | 98     | ice-buy   |
   133        | lpprov | ETH/DEC19 | 444       | 1                    | sell | ASK              | 444     | 99     | ice-sell  |
   134   
   135      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   136      Then the parties place the following orders:
   137        | party | market id | side | volume | price | resulting trades | type       | tif     |
   138        | aux   | ETH/DEC19 | buy  | 1      | 95    | 0                | TYPE_LIMIT | TIF_GTC |
   139        | aux   | ETH/DEC19 | sell | 1      | 105   | 0                | TYPE_LIMIT | TIF_GTC |
   140  
   141      # Trigger an auction to set the mark price
   142      When the parties place the following orders:
   143        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   144        | party1 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party1-2  |
   145        | party2 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party2-2  |
   146      Then the opening auction period ends for market "ETH/DEC19"
   147      And the mark price should be "100" for the market "ETH/DEC19"
   148      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   149  
   150      When the parties place the following orders with ticks:
   151        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   152        | edd    | ETH/DEC19 | sell | 20     | 101   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   153        | edd    | ETH/DEC19 | sell | 20     | 102   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
   154        | edd    | ETH/DEC19 | sell | 10     | 103   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   155        | edd    | ETH/DEC19 | sell | 15     | 104   | 0                | TYPE_LIMIT | TIF_GTC | ref-4     |
   156        | edd    | ETH/DEC19 | sell | 30     | 105   | 0                | TYPE_LIMIT | TIF_GTC | ref-5     |
   157        | barney | ETH/DEC19 | buy  | 20     | 99    | 0                | TYPE_LIMIT | TIF_GTC | ref-6     |
   158        | barney | ETH/DEC19 | buy  | 12     | 98    | 0                | TYPE_LIMIT | TIF_GTC | ref-7     |
   159        | barney | ETH/DEC19 | buy  | 14     | 97    | 0                | TYPE_LIMIT | TIF_GTC | ref-8     |
   160        | barney | ETH/DEC19 | buy  | 20     | 96    | 0                | TYPE_LIMIT | TIF_GTC | ref-9     |
   161        | barney | ETH/DEC19 | buy  | 5      | 95    | 0                | TYPE_LIMIT | TIF_GTC | ref-10    |
   162      Then the parties should have the following account balances:
   163        | party  | asset | market id | margin | general |
   164        | edd    | BTC   | ETH/DEC19 | 848    | 9152    |
   165        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
   166      When the parties place the following orders with ticks:
   167        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
   168        | chris | ETH/DEC19 | buy  | 50     | 0     | 3                | TYPE_MARKET | TIF_IOC | ref-1     |
   169      Then the parties should have the following account balances:
   170        | party  | asset | market id | margin | general |
   171        | edd    | BTC   | ETH/DEC19 | 1491   | 8449    |
   172        | chris  | BTC   | ETH/DEC19 | 1077   | 8474    |
   173        | barney | BTC   | ETH/DEC19 | 594    | 9406    |
   174      And the cumulated balance for all accounts should be worth "3041000"
   175      
   176      When the parties amend the following pegged iceberg orders:
   177        | party  | reference | size delta | offset |
   178        | lpprov | ice-sell  | 0          | 96     |
   179        | lpprov | ice-buy   | 0          | 95     |
   180      # then chris is trading out
   181      And the parties place the following orders with ticks:
   182        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
   183        | chris | ETH/DEC19 | sell | 50     | 0     | 4                | TYPE_MARKET | TIF_IOC | ref-1     |
   184      Then the parties should have the following account balances:
   185        | party  | asset | market id | margin | general |
   186        | edd    | BTC   | ETH/DEC19 | 1390   | 8900    |
   187        | chris  | BTC   | ETH/DEC19 | 0      | 8808    |
   188        | barney | BTC   | ETH/DEC19 | 1146   | 8756    |
   189      And the cumulated balance for all accounts should be worth "3041000"
   190      # placing new orders to trade out
   191      When the parties place the following orders with ticks:
   192        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
   193        | chris | ETH/DEC19 | buy  | 5      | 0     | 1                | TYPE_MARKET | TIF_IOC | ref-1     |
   194      # placing order which get cancelled
   195      When the parties place the following orders with ticks:
   196        | party | market id | side | volume | price | resulting trades | type       | tif     | reference            |
   197        | chris | ETH/DEC19 | buy  | 60     | 1     | 0                | TYPE_LIMIT | TIF_GTC | chris-id-1-to-cancel |
   198      # other parties trade together (tamlyn+barney)
   199      When the parties place the following orders with ticks:
   200        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   201        | tamlyn | ETH/DEC19 | sell | 3      | 95    | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
   202      # cancel order
   203      Then the parties cancel the following orders:
   204        | party | reference            |
   205        | chris | chris-id-1-to-cancel |
   206      # then chris is trading out
   207      When the parties place the following orders with ticks:
   208        | party | market id | side | volume | price | resulting trades | type        | tif     | reference |
   209        | chris | ETH/DEC19 | sell | 5      | 0     | 1                | TYPE_MARKET | TIF_IOC | ref-1     |
   210      Then the parties should have the following account balances:
   211        | party | asset | market id | margin | general |
   212        | chris | BTC   | ETH/DEC19 | 0      | 8668    |
   213      And the cumulated balance for all accounts should be worth "3041000"