code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0003-MTMK-verified-mark-to-market-settlement.feature (about)

     1  Feature: MTM settlement tests
     2  
     3    # Reference spreadsheet: https://drive.google.com/open?id=1ZCj7WWvP236wiJDgiGD_f9Xsun9o8PsW
     4    # Reference spreadsheet: https://drive.google.com/open?id=1q5gE2yBA1SnA2V4Yu6XwQo3ytBzhk61M
     5    # Both the above sheets are the same though
     6  
     7    Background:
     8      Given the markets:
     9        | id        | quote name | asset | risk model                  | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    10        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-2 | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 1e0                    | 0                         | default-futures |
    11      And the following network parameters are set:
    12        | name                                    | value |
    13        | network.markPriceUpdateMaximumFrequency | 0s    |
    14  
    15    Scenario: case 1 - LONG - MORE LONG - one trade (0003-MTMK-007)
    16      # setup accounts
    17      Given the parties deposit on asset's general account the following amount:
    18        | party  | asset | amount   |
    19        | party1 | BTC   | 10000    |
    20        | party2 | BTC   | 10000    |
    21        | party3 | BTC   | 10000    |
    22        | party4 | BTC   | 10000000 |
    23        | party5 | BTC   | 10000000 |
    24        | aux    | BTC   | 100000   |
    25  
    26      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    27      Then the parties place the following orders:
    28        | party | market id | side | volume | price | resulting trades | type       | tif     |
    29        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
    30        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
    31  
    32      # Trigger an auction to set the mark price
    33      When the parties place the following orders:
    34        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    35        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
    36        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
    37        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
    38        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
    39      Then the opening auction period ends for market "ETH/DEC19"
    40      And the mark price should be "100" for the market "ETH/DEC19"
    41      And the market data for the market "ETH/DEC19" should be:
    42         | mark price | trading mode             | target stake | supplied stake | open interest |
    43         | 100        | TRADING_MODE_CONTINUOUS  | 0            | 0              | 1             |
    44  
    45      Then the parties cancel the following orders:
    46        | party  | reference |
    47        | party4 | party4-1  |
    48        | party5 | party5-1  |
    49  
    50      # setup previous volume at 20
    51      When the parties place the following orders with ticks:
    52        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    53        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    54        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    55  
    56      # place trade for 10@110
    57      When the parties place the following orders with ticks:
    58        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    59        | party1 | ETH/DEC19 | buy  | 10     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    60        | party2 | ETH/DEC19 | sell | 10     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    61  
    62      And the mark price should be "110" for the market "ETH/DEC19"
    63  
    64      # MTM win transfers
    65      Then the following transfers should happen:
    66        | from   | to     | from account            | to account          | market id | amount | asset |
    67        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
    68  
    69      # place trade for 1@111 to set new mark price
    70      When the parties place the following orders with ticks:
    71        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    72        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
    73        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
    74  
    75      And the mark price should be "111" for the market "ETH/DEC19"
    76  
    77      # MTM win transfers: 200+30=230 as per spreadsheet
    78      Then the following transfers should happen:
    79        | from   | to     | from account            | to account          | market id | amount | asset |
    80        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 30     | BTC   |
    81  
    82    Scenario: case 2 - LONG - MORE LONG - multiple trades (0003-MTMK-007)
    83      # setup accounts
    84      Given the parties deposit on asset's general account the following amount:
    85        | party  | asset | amount   |
    86        | party1 | BTC   | 10000    |
    87        | party2 | BTC   | 10000    |
    88        | party3 | BTC   | 10000    |
    89        | party4 | BTC   | 10000000 |
    90        | party5 | BTC   | 10000000 |
    91        | aux    | BTC   | 100000   |
    92  
    93      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    94      Then the parties place the following orders:
    95        | party | market id | side | volume | price | resulting trades | type       | tif     |
    96        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
    97        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
    98  
    99      # Trigger an auction to set the mark price
   100      When the parties place the following orders:
   101        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   102        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   103        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   104        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   105        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   106      Then the opening auction period ends for market "ETH/DEC19"
   107      And the mark price should be "100" for the market "ETH/DEC19"
   108      Then the parties cancel the following orders:
   109        | party  | reference |
   110        | party4 | party4-1  |
   111        | party5 | party5-1  |
   112  
   113      # setup previous volume at 20
   114      When the parties place the following orders with ticks:
   115        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   116        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   117        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   118  
   119      # place trade 1 for 10@110
   120      When the parties place the following orders with ticks:
   121        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   122        | party1 | ETH/DEC19 | buy  | 10     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   123        | party2 | ETH/DEC19 | sell | 10     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   124  
   125      And the mark price should be "110" for the market "ETH/DEC19"
   126  
   127      # place trade 2 for 2@113
   128      When the parties place the following orders with ticks:
   129        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   130        | party1 | ETH/DEC19 | buy  | 2      | 113   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   131        | party2 | ETH/DEC19 | sell | 2      | 113   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   132  
   133      And the mark price should be "113" for the market "ETH/DEC19"
   134  
   135      # MTM win transfers
   136      Then the following transfers should happen:
   137        | from   | to     | from account            | to account          | market id | amount | asset |
   138        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   139        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 90     | BTC   |
   140  
   141      # place trade for 1@111 to set new mark price
   142      When the parties place the following orders with ticks:
   143        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   144        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   145        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   146  
   147      And the mark price should be "111" for the market "ETH/DEC19"
   148  
   149      # MTM win transfers: 200+90-64=226 as per spreadsheet
   150      Then the following transfers should happen:
   151        | from   | to     | from account            | to account              | market id | amount | asset |
   152        | party1 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 64     | BTC   |
   153        | market | party2 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 64     | BTC   |
   154  
   155  
   156    Scenario: case 3 - LONG - LESS LONG - one trade (0003-MTMK-007)
   157      # setup accounts
   158      Given the parties deposit on asset's general account the following amount:
   159        | party  | asset | amount   |
   160        | party1 | BTC   | 10000    |
   161        | party2 | BTC   | 10000    |
   162        | party3 | BTC   | 10000    |
   163        | party4 | BTC   | 10000000 |
   164        | party5 | BTC   | 10000000 |
   165        | aux    | BTC   | 100000   |
   166  
   167      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   168      Then the parties place the following orders:
   169        | party | market id | side | volume | price | resulting trades | type       | tif     |
   170        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   171        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   172  
   173      # Trigger an auction to set the mark price
   174      When the parties place the following orders:
   175        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   176        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   177        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   178        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   179        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   180      Then the opening auction period ends for market "ETH/DEC19"
   181      And the mark price should be "100" for the market "ETH/DEC19"
   182      Then the parties cancel the following orders:
   183        | party  | reference |
   184        | party4 | party4-1  |
   185        | party5 | party5-1  |
   186  
   187      # setup previous volume at 20
   188      When the parties place the following orders with ticks:
   189        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   190        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   191        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   192  
   193      # place trade 1 for -5@110
   194      When the parties place the following orders with ticks:
   195        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   196        | party1 | ETH/DEC19 | sell | 5      | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   197        | party2 | ETH/DEC19 | buy  | 5      | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   198  
   199      And the mark price should be "110" for the market "ETH/DEC19"
   200  
   201      # MTM win transfers
   202      Then the following transfers should happen:
   203        | from   | to     | from account            | to account          | market id | amount | asset |
   204        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   205  
   206      # place trade for 1@111 to set new mark price
   207      When the parties place the following orders with ticks:
   208        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   209        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   210        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   211  
   212      And the mark price should be "111" for the market "ETH/DEC19"
   213  
   214      # MTM win transfers: 200+15=215 as per spreadsheet
   215      Then the following transfers should happen:
   216        | from   | to     | from account            | to account          | market id | amount | asset |
   217        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 15     | BTC   |
   218  
   219    Scenario: case 4 - LONG - LESS LONG - multiple trades ((0003-MTMK-001, 0003-MTMK-007)
   220      # setup accounts
   221      Given the parties deposit on asset's general account the following amount:
   222        | party  | asset | amount   |
   223        | party1 | BTC   | 10000    |
   224        | party2 | BTC   | 10000    |
   225        | party3 | BTC   | 10000    |
   226        | party4 | BTC   | 10000000 |
   227        | party5 | BTC   | 10000000 |
   228        | aux    | BTC   | 100000   |
   229  
   230      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   231      Then the parties place the following orders:
   232        | party | market id | side | volume | price | resulting trades | type       | tif     |
   233        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   234        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   235  
   236      # Trigger an auction to set the mark price
   237      When the parties place the following orders:
   238        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   239        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   240        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   241        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   242        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   243      Then the opening auction period ends for market "ETH/DEC19"
   244      And the mark price should be "100" for the market "ETH/DEC19"
   245      Then the parties cancel the following orders:
   246        | party  | reference |
   247        | party4 | party4-1  |
   248        | party5 | party5-1  |
   249  
   250      # setup previous volume at 20
   251      When the parties place the following orders with ticks:
   252        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   253        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   254        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   255  
   256      # place trade 1 for -10@110
   257      When the parties place the following orders with ticks:
   258        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   259        | party1 | ETH/DEC19 | sell | 10     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   260        | party2 | ETH/DEC19 | buy  | 10     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   261  
   262      And the mark price should be "110" for the market "ETH/DEC19"
   263  
   264      # place trade 2 for -2@113
   265      When the parties place the following orders with ticks:
   266        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   267        | party1 | ETH/DEC19 | sell | 2      | 113   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   268        | party2 | ETH/DEC19 | buy  | 2      | 113   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   269  
   270      And the mark price should be "113" for the market "ETH/DEC19"
   271  
   272      # MTM win transfers
   273      Then the following transfers should happen:
   274        | from   | to     | from account            | to account              | market id | amount | asset |
   275        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 200    | BTC   |
   276        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN     | ETH/DEC19 | 30     | BTC   |
   277        | party2 | market | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 200    | BTC   |
   278  
   279      # place trade for 1@111 to set new mark price
   280      When the parties place the following orders with ticks:
   281        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   282        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   283        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   284  
   285      And the mark price should be "111" for the market "ETH/DEC19"
   286  
   287      # MTM win transfers: 200+30-16=214 as per spreadsheet
   288      Then the following transfers should happen:
   289        | from   | to     | from account        | to account              | market id | amount | asset |
   290        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 16     | BTC   |
   291  
   292    Scenario: case 5 - LONG - ZERO - one trade (0003-MTMK-007)
   293      # setup accounts
   294      Given the parties deposit on asset's general account the following amount:
   295        | party  | asset | amount   |
   296        | party1 | BTC   | 10000    |
   297        | party2 | BTC   | 10000    |
   298        | party4 | BTC   | 10000000 |
   299        | party5 | BTC   | 10000000 |
   300        | aux    | BTC   | 100000   |
   301  
   302      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   303      Then the parties place the following orders:
   304        | party | market id | side | volume | price | resulting trades | type       | tif     |
   305        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   306        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   307  
   308      # Trigger an auction to set the mark price
   309      When the parties place the following orders:
   310        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   311        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   312        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   313        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   314        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   315      Then the opening auction period ends for market "ETH/DEC19"
   316      And the mark price should be "100" for the market "ETH/DEC19"
   317      Then the parties cancel the following orders:
   318        | party  | reference |
   319        | party4 | party4-1  |
   320        | party5 | party5-1  |
   321  
   322      # setup previous volume at 20
   323      When the parties place the following orders with ticks:
   324        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   325        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   326        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   327  
   328      # place trade 1 for -20@110
   329      When the parties place the following orders with ticks:
   330        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   331        | party1 | ETH/DEC19 | sell | 20     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   332        | party2 | ETH/DEC19 | buy  | 20     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   333  
   334      And the mark price should be "110" for the market "ETH/DEC19"
   335  
   336      # MTM win transfers
   337      Then the following transfers should happen:
   338        | from   | to     | from account            | to account          | market id | amount | asset |
   339        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   340  
   341    Scenario: case 6 - LONG - ZERO - multiple trades (0003-MTMK-007)
   342      # setup accounts
   343      Given the parties deposit on asset's general account the following amount:
   344        | party  | asset | amount   |
   345        | party1 | BTC   | 10000    |
   346        | party2 | BTC   | 10000    |
   347        | party4 | BTC   | 10000000 |
   348        | party5 | BTC   | 10000000 |
   349        | aux    | BTC   | 100000   |
   350  
   351      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   352      Then the parties place the following orders:
   353        | party | market id | side | volume | price | resulting trades | type       | tif     |
   354        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   355        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   356  
   357      # Trigger an auction to set the mark price
   358      When the parties place the following orders:
   359        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   360        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   361        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   362        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   363        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   364      Then the opening auction period ends for market "ETH/DEC19"
   365      And the mark price should be "100" for the market "ETH/DEC19"
   366      Then the parties cancel the following orders:
   367        | party  | reference |
   368        | party4 | party4-1  |
   369        | party5 | party5-1  |
   370  
   371      # setup previous volume at 20
   372      When the parties place the following orders with ticks:
   373        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   374        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   375        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   376  
   377      # place trade 1 for -10@110
   378      When the parties place the following orders with ticks:
   379        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   380        | party1 | ETH/DEC19 | sell | 10     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   381        | party2 | ETH/DEC19 | buy  | 10     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   382  
   383      And the mark price should be "110" for the market "ETH/DEC19"
   384  
   385      # place trade 2 for -10@113
   386      When the parties place the following orders with ticks:
   387        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   388        | party1 | ETH/DEC19 | sell | 10     | 114   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   389        | party2 | ETH/DEC19 | buy  | 10     | 114   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   390  
   391      And the mark price should be "114" for the market "ETH/DEC19"
   392  
   393      # MTM win transfers
   394      Then the following transfers should happen:
   395        | from   | to     | from account            | to account          | market id | amount | asset |
   396        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   397        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 40     | BTC   |
   398  
   399    Scenario: case 7 - LONG - SHORT - one trade (0003-MTMK-007)
   400      # setup accounts
   401      Given the parties deposit on asset's general account the following amount:
   402        | party  | asset | amount   |
   403        | party1 | BTC   | 10000    |
   404        | party2 | BTC   | 10000    |
   405        | party4 | BTC   | 10000000 |
   406        | party5 | BTC   | 10000000 |
   407        | aux    | BTC   | 100000   |
   408  
   409      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   410      Then the parties place the following orders:
   411        | party | market id | side | volume | price | resulting trades | type       | tif     |
   412        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   413        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   414  
   415      # Trigger an auction to set the mark price
   416      When the parties place the following orders:
   417        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   418        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   419        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   420        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   421        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   422      Then the opening auction period ends for market "ETH/DEC19"
   423      And the mark price should be "100" for the market "ETH/DEC19"
   424      Then the parties cancel the following orders:
   425        | party  | reference |
   426        | party4 | party4-1  |
   427        | party5 | party5-1  |
   428  
   429      # setup previous volume at 20
   430      When the parties place the following orders with ticks:
   431        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   432        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   433        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   434  
   435      # place trade 1 for -30@110
   436      When the parties place the following orders with ticks:
   437        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   438        | party1 | ETH/DEC19 | sell | 30     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   439        | party2 | ETH/DEC19 | buy  | 30     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   440  
   441      And the mark price should be "110" for the market "ETH/DEC19"
   442  
   443      # MTM win transfers
   444      Then the following transfers should happen:
   445        | from   | to     | from account            | to account          | market id | amount | asset |
   446        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   447  
   448    Scenario: case 8 - LONG - SHORT - multiple trades (0003-MTMK-007)
   449      # setup accounts
   450      Given the parties deposit on asset's general account the following amount:
   451        | party  | asset | amount   |
   452        | party1 | BTC   | 10000    |
   453        | party2 | BTC   | 10000    |
   454        | party3 | BTC   | 10000    |
   455        | party4 | BTC   | 10000000 |
   456        | party5 | BTC   | 10000000 |
   457        | aux    | BTC   | 100000   |
   458  
   459      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   460      Then the parties place the following orders:
   461        | party | market id | side | volume | price | resulting trades | type       | tif     |
   462        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   463        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   464  
   465      # Trigger an auction to set the mark price
   466      When the parties place the following orders:
   467        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   468        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   469        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   470        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   471        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   472      Then the opening auction period ends for market "ETH/DEC19"
   473      And the mark price should be "100" for the market "ETH/DEC19"
   474      Then the parties cancel the following orders:
   475        | party  | reference |
   476        | party4 | party4-1  |
   477        | party5 | party5-1  |
   478  
   479      # setup previous volume at 20
   480      When the parties place the following orders with ticks:
   481        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   482        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   483        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   484  
   485      # place trade 1 for 5@110
   486      When the parties place the following orders with ticks:
   487        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   488        | party1 | ETH/DEC19 | buy  | 5      | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   489        | party2 | ETH/DEC19 | sell | 5      | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   490  
   491      And the mark price should be "110" for the market "ETH/DEC19"
   492  
   493      # place trade 2 for -30@114
   494      When the parties place the following orders with ticks:
   495        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   496        | party1 | ETH/DEC19 | sell | 30     | 114   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   497        | party2 | ETH/DEC19 | buy  | 30     | 114   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   498  
   499      And the mark price should be "114" for the market "ETH/DEC19"
   500  
   501      # MTM win transfers
   502      Then the following transfers should happen:
   503        | from   | to     | from account            | to account          | market id | amount | asset |
   504        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   505        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 100    | BTC   |
   506  
   507      # place trade for 1@111 to set new mark price
   508      When the parties place the following orders with ticks:
   509        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   510        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   511        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   512  
   513      And the mark price should be "111" for the market "ETH/DEC19"
   514  
   515      # MTM win transfers: 200+100+15=315 as per spreadsheet
   516      Then the following transfers should happen:
   517        | from   | to     | from account            | to account          | market id | amount | asset |
   518        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 15     | BTC   |
   519  
   520    Scenario: case 9 - LONG - SAME AMOUNT - multiple trades ((0003-MTMK-001, 0003-MTMK-007)
   521      # setup accounts
   522      Given the parties deposit on asset's general account the following amount:
   523        | party  | asset | amount   |
   524        | party1 | BTC   | 10000    |
   525        | party2 | BTC   | 10000    |
   526        | party3 | BTC   | 10000    |
   527        | party4 | BTC   | 10000000 |
   528        | party5 | BTC   | 10000000 |
   529        | aux    | BTC   | 100000   |
   530  
   531      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   532      Then the parties place the following orders:
   533        | party | market id | side | volume | price | resulting trades | type       | tif     |
   534        | aux   | ETH/DEC19 | buy  | 10     | 99    | 0                | TYPE_LIMIT | TIF_GTC |
   535        | aux   | ETH/DEC19 | sell | 10     | 115   | 0                | TYPE_LIMIT | TIF_GTC |
   536  
   537      # Trigger an auction to set the mark price
   538      When the parties place the following orders:
   539        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   540        | party4 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | party4-1  |
   541        | party5 | ETH/DEC19 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | party5-1  |
   542        | party4 | ETH/DEC19 | buy  | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party4-2  |
   543        | party5 | ETH/DEC19 | sell | 1      | 100   | 0                | TYPE_LIMIT | TIF_GFA | party5-2  |
   544      Then the opening auction period ends for market "ETH/DEC19"
   545      And the mark price should be "100" for the market "ETH/DEC19"
   546      Then the parties cancel the following orders:
   547        | party  | reference |
   548        | party4 | party4-1  |
   549        | party5 | party5-1  |
   550  
   551      # setup previous volume at 20
   552      When the parties place the following orders with ticks:
   553        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   554        | party1 | ETH/DEC19 | buy  | 20     | 100   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   555        | party2 | ETH/DEC19 | sell | 20     | 100   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   556  
   557      # place trade 1 for 10@110
   558      When the parties place the following orders with ticks:
   559        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   560        | party1 | ETH/DEC19 | buy  | 10     | 110   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   561        | party2 | ETH/DEC19 | sell | 10     | 110   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   562  
   563      And the mark price should be "110" for the market "ETH/DEC19"
   564  
   565      # place trade 2 for -10@114
   566      When the parties place the following orders with ticks:
   567        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   568        | party1 | ETH/DEC19 | sell | 10     | 114   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   569        | party2 | ETH/DEC19 | buy  | 10     | 114   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   570  
   571      And the mark price should be "114" for the market "ETH/DEC19"
   572  
   573      # MTM win transfers
   574      Then the following transfers should happen:
   575        | from   | to     | from account            | to account          | market id | amount | asset |
   576        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 200    | BTC   |
   577        | market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 120    | BTC   |
   578  
   579      # place trade for 1@111 to set new mark price
   580      When the parties place the following orders with ticks:
   581        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   582        | party3 | ETH/DEC19 | buy  | 1      | 111   | 0                | TYPE_LIMIT | TIF_GTC | ref-1     |
   583        | party2 | ETH/DEC19 | sell | 1      | 111   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
   584  
   585      And the mark price should be "111" for the market "ETH/DEC19"
   586  
   587      # MTM win transfers: 200+120-60=260 as per spreadsheet
   588      Then the following transfers should happen:
   589        | from   | to     | from account        | to account              | market id | amount | asset |
   590        | party1 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 60     | BTC   |