code.vegaprotocol.io/vega@v0.79.0/core/integration/features/margin/0019-MCAL-043.feature (about)

     1  Feature: Iceberg orders in isolated margin mode
     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-3 | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.03                   | 0                         | default-futures |
     7      And the following network parameters are set:
     8        | name                                    | value |
     9        | market.auction.minimumDuration          | 1     |
    10        | network.markPriceUpdateMaximumFrequency | 0s    |
    11        | limits.markets.maxPeggedOrders          | 1500  |
    12      Given the average block duration is "1"
    13  
    14    @iceberg
    15    Scenario: 001 Iceberg order submission with valid TIF's
    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        | aux    | BTC   | 100000   |
    22        | aux2   | BTC   | 100000   |
    23        | lpprov | BTC   | 90000000 |
    24  
    25      When the parties submit the following liquidity provision:
    26        | id  | party  | market id | commitment amount | fee | lp type    |
    27        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    28        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    29      And the parties place the following pegged iceberg orders:
    30        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
    31        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
    32        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
    33      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    34      When the parties place the following orders:
    35        | party | market id | side | volume | price | resulting trades | type       | tif     |
    36        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    37        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
    38        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
    39        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
    40      Then the opening auction period ends for market "ETH/DEC19"
    41      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    42  
    43      And the parties submit update margin mode:
    44        | party  | market    | margin_mode     | margin_factor | error |
    45        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
    46  
    47      And the parties should have the following margin levels:
    48        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
    49        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
    50  
    51      When the parties place the following iceberg orders:
    52        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | only |
    53        | party1 | ETH/DEC19 | buy  | 100    | 10    | 0                | TYPE_LIMIT | TIF_GTC | 10        | 5                    | post |
    54  
    55      Then the iceberg orders should have the following states:
    56        | party  | market id | side | visible volume | price | status        | reserved volume |
    57        | party1 | ETH/DEC19 | buy  | 10             | 10    | STATUS_ACTIVE | 90              |
    58  
    59      When the parties place the following iceberg orders:
    60        | party  | market id | side | volume | price | resulting trades | type       | tif     | expires in | peak size | minimum visible size | only |
    61        | party2 | ETH/DEC19 | buy  | 100    | 10    | 0                | TYPE_LIMIT | TIF_GTT | 3600       | 8         | 4                    | post |
    62  
    63      Then the iceberg orders should have the following states:
    64        | party  | market id | side | visible volume | price | status        | reserved volume |
    65        | party2 | ETH/DEC19 | buy  | 8              | 10    | STATUS_ACTIVE | 92              |
    66  
    67    @iceberg
    68    Scenario: 002 An iceberg order with either an ordinary can be submitted, and iceberg order with pegged limit price will be rejected
    69      # setup accounts
    70      Given the parties deposit on asset's general account the following amount:
    71        | party  | asset | amount   |
    72        | party1 | BTC   | 10000    |
    73        | party2 | BTC   | 10000    |
    74        | aux    | BTC   | 100000   |
    75        | aux2   | BTC   | 100000   |
    76        | lpprov | BTC   | 90000000 |
    77  
    78      When the parties submit the following liquidity provision:
    79        | id  | party  | market id | commitment amount | fee | lp type    |
    80        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    81        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    82      And the parties place the following pegged iceberg orders:
    83        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
    84        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
    85        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
    86      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    87      When the parties place the following orders:
    88        | party | market id | side | volume | price | resulting trades | type       | tif     |
    89        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    90        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
    91        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
    92        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
    93      Then the opening auction period ends for market "ETH/DEC19"
    94      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    95      And the parties submit update margin mode:
    96        | party  | market    | margin_mode     | margin_factor | error |
    97        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
    98  
    99      And the parties should have the following margin levels:
   100        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   101        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   102  
   103      Given the parties place the following orders:
   104        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   105        | party2 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC | best-bid  |
   106        | party2 | ETH/DEC19 | sell | 1      | 20    | 0                | TYPE_LIMIT | TIF_GTC | best-ask  |
   107      When the parties place the following iceberg orders:
   108        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | reference        |
   109        | party1 | ETH/DEC19 | buy  | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC | 3         | 1                    | ordinary-iceberg |
   110      And the parties place the following pegged iceberg orders:
   111        | party  | market id | side | volume | resulting trades | type       | tif     | peak size | minimum visible size | pegged reference | offset | reference      | error                                                         |
   112        | party1 | ETH/DEC19 | buy  | 10     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | BID              | 1      | pegged-iceberg | OrderError: pegged orders not allowed in isolated margin mode |
   113      Then the order book should have the following volumes for market "ETH/DEC19":
   114        | side | price | volume |
   115        | buy  | 5     | 3      |
   116        | buy  | 9     | 0      |
   117        | buy  | 10    | 1      |
   118  
   119      # Move best-bid and check pegged iceberg order is re-priced
   120      When the parties amend the following orders:
   121        | party  | reference | price | size delta | tif     |
   122        | party2 | best-bid  | 9     | 0          | TIF_GTC |
   123      Then the order book should have the following volumes for market "ETH/DEC19":
   124        | side | price | volume |
   125        | buy  | 5     | 3      |
   126        | buy  | 8     | 0      |
   127        | buy  | 9     | 1      |
   128  
   129    @iceberg
   130    Scenario: 003 Iceberg order margin calculation
   131      # setup accounts
   132      Given the parties deposit on asset's general account the following amount:
   133        | party  | asset | amount   |
   134        | party1 | BTC   | 10000    |
   135        | party2 | BTC   | 10000    |
   136        | aux    | BTC   | 100000   |
   137        | aux2   | BTC   | 100000   |
   138        | lpprov | BTC   | 90000000 |
   139  
   140      When the parties submit the following liquidity provision:
   141        | id  | party  | market id | commitment amount | fee | lp type    |
   142        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   143        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   144      And the parties place the following pegged iceberg orders:
   145        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   146        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   147        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   148      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   149      When the parties place the following orders:
   150        | party | market id | side | volume | price | resulting trades | type       | tif     |
   151        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   152        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   153        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   154        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   155      Then the opening auction period ends for market "ETH/DEC19"
   156      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   157  
   158      And the parties submit update margin mode:
   159        | party  | market    | margin_mode     | margin_factor | error |
   160        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   161  
   162      And the parties should have the following margin levels:
   163        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   164        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   165  
   166      When the parties place the following iceberg orders:
   167        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | only | reference       |
   168        | party1 | ETH/DEC19 | buy  | 100    | 10    | 0                | TYPE_LIMIT | TIF_GTC | 10        | 5                    | post | iceberg-order-1 |
   169  
   170      Then the iceberg orders should have the following states:
   171        | party  | market id | side | visible volume | price | status        | reserved volume |
   172        | party1 | ETH/DEC19 | buy  | 10             | 10    | STATUS_ACTIVE | 90              |
   173  
   174      #order margin level: 10*100*0.15=150
   175      And the parties should have the following margin levels:
   176        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   177        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 150   |
   178  
   179      And the parties should have the following account balances:
   180        | party  | asset | market id | margin | general |
   181        | party1 | BTC   | ETH/DEC19 | 0      | 9850    |
   182  
   183      # And another party places a normal limit order for the same price and quantity, then the same margin should be taken
   184      When the parties place the following orders:
   185        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference            |
   186        | party2 | ETH/DEC19 | buy  | 100    | 10    | 0                | TYPE_LIMIT | TIF_GTC | normal-limit-order-1 |
   187  
   188      And the parties should have the following account balances:
   189        | party  | asset | market id | margin | general |
   190        | party2 | BTC   | ETH/DEC19 | 26     | 9974    |
   191  
   192      And the parties submit update margin mode:
   193        | party  | market    | margin_mode     | margin_factor | error |
   194        | party2 | ETH/DEC19 | isolated margin | 0.15          |       |
   195  
   196      And the parties should have the following margin levels:
   197        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   198        | party2 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 150   |
   199  
   200      # Now we cancel the iceberg order
   201      Then the parties cancel the following orders:
   202        | party  | reference       |
   203        | party1 | iceberg-order-1 |
   204  
   205      # And the margin taken for the iceberg order is released
   206      And the parties should have the following account balances:
   207        | party  | asset | market id | margin | general |
   208        | party1 | BTC   | ETH/DEC19 | 0      | 10000   |
   209  
   210      # Now we cancel the normal limit order
   211      Then the parties cancel the following orders:
   212        | party  | reference            |
   213        | party2 | normal-limit-order-1 |
   214  
   215      # And the margin taken for the normal limit order is released
   216      And the parties should have the following account balances:
   217        | party  | asset | market id | margin | general |
   218        | party2 | BTC   | ETH/DEC19 | 0      | 10000   |
   219  
   220    @iceberg
   221    Scenario: 004 iceberg basic refresh
   222      # setup accounts
   223      Given the parties deposit on asset's general account the following amount:
   224        | party  | asset | amount   |
   225        | party1 | BTC   | 10000    |
   226        | party2 | BTC   | 10000    |
   227        | aux    | BTC   | 100000   |
   228        | aux2   | BTC   | 100000   |
   229        | lpprov | BTC   | 90000000 |
   230  
   231      When the parties submit the following liquidity provision:
   232        | id  | party  | market id | commitment amount | fee | lp type    |
   233        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   234        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   235      And the parties place the following pegged iceberg orders:
   236        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   237        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   238        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   239      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   240      When the parties place the following orders:
   241        | party | market id | side | volume | price | resulting trades | type       | tif     |
   242        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   243        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   244        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   245        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   246      Then the opening auction period ends for market "ETH/DEC19"
   247      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   248  
   249      When the parties place the following iceberg orders:
   250        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size |
   251        | party1 | ETH/DEC19 | buy  | 100    | 10    | 0                | TYPE_LIMIT | TIF_GTC | 10        | 5                    |
   252  
   253      And the parties submit update margin mode:
   254        | party  | market    | margin_mode     | margin_factor | error |
   255        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   256  
   257      And the parties should have the following margin levels:
   258        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   259        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 150   |
   260  
   261      Then the iceberg orders should have the following states:
   262        | party  | market id | side | visible volume | price | status        | reserved volume |
   263        | party1 | ETH/DEC19 | buy  | 10             | 10    | STATUS_ACTIVE | 90              |
   264  
   265      When the parties place the following orders:
   266        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   267        | party2 | ETH/DEC19 | sell | 6      | 10    | 1                | TYPE_LIMIT | TIF_GTC |
   268  
   269      Then the iceberg orders should have the following states:
   270        | party  | market id | side | visible volume | price | status        | reserved volume |
   271        | party1 | ETH/DEC19 | buy  | 10             | 10    | STATUS_ACTIVE | 84              |
   272  
   273      #order margin: 10*94*0.15=141
   274      And the parties should have the following margin levels:
   275        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   276        | party1 | ETH/DEC19 | 2           | 0      | 2       | 0       | isolated margin | 0.15          | 141   |
   277  
   278    @iceberg
   279    Scenario: 005 Iceberg order trading during auction uncrossing
   280      # setup accounts
   281      Given the parties deposit on asset's general account the following amount:
   282        | party  | asset | amount   |
   283        | party1 | BTC   | 10000    |
   284        | party2 | BTC   | 10000    |
   285        | party3 | BTC   | 10000    |
   286        | aux    | BTC   | 100000   |
   287        | lpprov | BTC   | 90000000 |
   288  
   289      And the parties submit the following liquidity provision:
   290        | id  | party  | market id | commitment amount | fee | lp type    |
   291        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   292        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   293      And the parties place the following pegged iceberg orders:
   294        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   295        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   296        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   297  
   298      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   299      And the parties place the following orders:
   300        | party | market id | side | volume | price | resulting trades | type       | tif     |
   301        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   302        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   303  
   304      Given the parties place the following iceberg orders:
   305        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference    | peak size | minimum visible size |
   306        | party1 | ETH/DEC19 | buy  | 10     | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-1 | 2         | 1                    |
   307  
   308      And the parties place the following orders:
   309        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   310        | party2 | ETH/DEC19 | buy  | 8      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   311      When the parties place the following iceberg orders:
   312        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference    | peak size | minimum visible size |
   313        | party3 | ETH/DEC19 | sell | 10     | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-1 | 2         | 1                    |
   314  
   315      And the parties submit update margin mode:
   316        | party  | market    | margin_mode     | margin_factor | error |
   317        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   318  
   319      And the parties should have the following margin levels:
   320        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   321        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 3     |
   322      And the opening auction period ends for market "ETH/DEC19"
   323      Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   324      # Check only the display volume of party1 is filled and is refreshed at the back of the que
   325      And the following trades should be executed:
   326        | buyer  | seller | price | size |
   327        | party1 | party3 | 2     | 2    |
   328      # Check the remaining volume of party3s iceberg is filled in a single trade with party2
   329      And the following trades should be executed:
   330        | buyer  | seller | price | size |
   331        | party2 | party3 | 2     | 8    |
   332  
   333    @iceberg
   334    @margin
   335    Scenario: 006 Iceberg increase size success and not losing position in order book
   336      # setup accounts
   337      Given the parties deposit on asset's general account the following amount:
   338        | party  | asset | amount   |
   339        | party1 | BTC   | 10000    |
   340        | party2 | BTC   | 10000    |
   341        | party3 | BTC   | 10000    |
   342        | aux    | BTC   | 100000   |
   343        | aux2   | BTC   | 100000   |
   344        | lpprov | BTC   | 90000000 |
   345  
   346      When the parties submit the following liquidity provision:
   347        | id  | party  | market id | commitment amount | fee | lp type    |
   348        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   349        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   350      And the parties place the following pegged iceberg orders:
   351        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   352        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   353        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   354      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   355      When the parties place the following orders:
   356        | party | market id | side | volume | price | resulting trades | type       | tif     |
   357        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   358        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   359        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   360        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   361      Then the opening auction period ends for market "ETH/DEC19"
   362      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   363      And the parties submit update margin mode:
   364        | party  | market    | margin_mode     | margin_factor | error |
   365        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   366  
   367      And the parties should have the following margin levels:
   368        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   369        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   370  
   371      And the parties place the following iceberg orders:
   372        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference    | peak size | minimum visible size |
   373        | party1 | ETH/DEC19 | sell | 50     | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-1 | 2         | 1                    |
   374        | party2 | ETH/DEC19 | sell | 5      | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-2 | 2         | 1                    |
   375  
   376      And the parties should have the following account balances:
   377        | party  | asset | market id | margin | general | order margin |
   378        | party1 | BTC   | ETH/DEC19 | 0      | 9985    | 15           |
   379  
   380      # increasing size
   381      Then the parties amend the following orders:
   382        | party  | reference    | price | size delta | tif     |
   383        | party1 | this-order-1 | 2     | 50         | TIF_GTC |
   384  
   385      # the visible is the same and only the reserve amount has increased
   386      Then the iceberg orders should have the following states:
   387        | party  | market id | side | visible volume | price | status        | reserved volume |
   388        | party1 | ETH/DEC19 | sell | 2              | 2     | STATUS_ACTIVE | 98              |
   389  
   390      And the parties should have the following account balances:
   391        | party  | asset | market id | margin | general | order margin |
   392        | party1 | BTC   | ETH/DEC19 | 0      | 9970    | 30           |
   393  
   394      # matching the order now
   395      # this should match with the size 2 order of party1
   396      Then the parties place the following orders:
   397        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   398        | party3 | ETH/DEC19 | buy  | 2      | 2     | 1                | TYPE_LIMIT | TIF_GTC | party3    |
   399  
   400      Then the following trades should be executed:
   401        | buyer  | seller | price | size |
   402        | party3 | party1 | 2     | 2    |
   403  
   404    @iceberg
   405    Scenario: 007 Iceberg decrease size success and not losing position in order book
   406      # setup accounts
   407      Given the parties deposit on asset's general account the following amount:
   408        | party  | asset | amount   |
   409        | party1 | BTC   | 10000    |
   410        | party2 | BTC   | 10000    |
   411        | party3 | BTC   | 10000    |
   412        | aux    | BTC   | 100000   |
   413        | aux2   | BTC   | 100000   |
   414        | lpprov | BTC   | 90000000 |
   415  
   416      When the parties submit the following liquidity provision:
   417        | id  | party  | market id | commitment amount | fee | lp type    |
   418        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   419        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   420      And the parties place the following pegged iceberg orders:
   421        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   422        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   423        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   424      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   425  
   426      When the parties place the following orders:
   427        | party | market id | side | volume | price | resulting trades | type       | tif     |
   428        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   429        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   430        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   431        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   432  
   433      And the parties submit update margin mode:
   434        | party  | market    | margin_mode     | margin_factor | error |
   435        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   436  
   437      And the parties should have the following margin levels:
   438        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   439        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   440  
   441      Then the opening auction period ends for market "ETH/DEC19"
   442      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   443  
   444      And the parties place the following iceberg orders:
   445        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference    | peak size | minimum visible size |
   446        | party1 | ETH/DEC19 | sell | 100    | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-1 | 2         | 1                    |
   447        | party2 | ETH/DEC19 | sell | 100    | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-2 | 2         | 1                    |
   448  
   449      And the parties should have the following account balances:
   450        | party  | asset | market id | margin | general | order margin |
   451        | party1 | BTC   | ETH/DEC19 | 0      | 9970    | 30           |
   452  
   453      # decreasing size
   454      Then the parties amend the following orders:
   455        | party  | reference    | price | size delta | tif     |
   456        | party1 | this-order-1 | 2     | -50        | TIF_GTC |
   457  
   458      # the visible is the same and only the reserve amount has decreased
   459      Then the iceberg orders should have the following states:
   460        | party  | market id | side | visible volume | price | status        | reserved volume |
   461        | party1 | ETH/DEC19 | sell | 2              | 2     | STATUS_ACTIVE | 48              |
   462  
   463      And the parties should have the following account balances:
   464        | party  | asset | market id | margin | general | order margin |
   465        | party1 | BTC   | ETH/DEC19 | 0      | 9985    | 15           |
   466  
   467      # matching the order now
   468      # this should match with the size 2 order of party1
   469      Then the parties place the following orders:
   470        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   471        | party3 | ETH/DEC19 | buy  | 2      | 2     | 1                | TYPE_LIMIT | TIF_GTC | party3    |
   472  
   473      Then the following trades should be executed:
   474        | buyer  | seller | price | size |
   475        | party3 | party1 | 2     | 2    |
   476  
   477    @iceberg
   478    Scenario: 008  Iceberg amend price reenters aggressively
   479      # setup accounts
   480      Given the parties deposit on asset's general account the following amount:
   481        | party  | asset | amount   |
   482        | party1 | BTC   | 10000    |
   483        | party2 | BTC   | 10000    |
   484        | aux    | BTC   | 100000   |
   485        | aux2   | BTC   | 100000   |
   486        | lpprov | BTC   | 90000000 |
   487  
   488      When the parties submit the following liquidity provision:
   489        | id  | party  | market id | commitment amount | fee | lp type    |
   490        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   491        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   492      And the parties place the following pegged iceberg orders:
   493        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   494        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   495        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   496      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   497      When the parties place the following orders:
   498        | party | market id | side | volume | price | resulting trades | type       | tif     |
   499        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   500        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   501        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   502        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   503      Then the opening auction period ends for market "ETH/DEC19"
   504      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   505  
   506      And the parties submit update margin mode:
   507        | party  | market    | margin_mode     | margin_factor | error |
   508        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   509  
   510      And the parties should have the following margin levels:
   511        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   512        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   513      And the parties place the following iceberg orders:
   514        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference    | peak size | minimum visible size |
   515        | party1 | ETH/DEC19 | sell | 16     | 5     | 0                | TYPE_LIMIT | TIF_GTC | this-order-1 | 5         | 1                    |
   516        | party2 | ETH/DEC19 | buy  | 10     | 2     | 0                | TYPE_LIMIT | TIF_GTC | this-order-2 | 2         | 1                    |
   517  
   518      # amend the buy order so that it will cross with the other iceberg
   519      Then the parties amend the following orders:
   520        | party  | reference    | price | size delta | tif     |
   521        | party2 | this-order-2 | 5     | 0          | TIF_GTC |
   522  
   523      # the amended iceberg will trade aggressively and be fully consumed
   524      Then the iceberg orders should have the following states:
   525        | party  | market id | side | visible volume | price | status        | reserved volume |
   526        | party1 | ETH/DEC19 | sell | 5              | 5     | STATUS_ACTIVE | 1               |
   527        | party2 | ETH/DEC19 | buy  | 0              | 5     | STATUS_FILLED | 0               |
   528  
   529    @margin
   530    @iceberg
   531    Scenario: 009 Cancelling an active iceberg order
   532      # setup accounts
   533      Given the parties deposit on asset's general account the following amount:
   534        | party  | asset | amount   |
   535        | party1 | BTC   | 10000    |
   536        | aux    | BTC   | 100000   |
   537        | aux2   | BTC   | 100000   |
   538        | lpprov | BTC   | 90000000 |
   539  
   540      When the parties submit the following liquidity provision:
   541        | id  | party  | market id | commitment amount | fee | lp type    |
   542        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   543        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   544      And the parties place the following pegged iceberg orders:
   545        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   546        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   547        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   548      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   549      When the parties place the following orders:
   550        | party | market id | side | volume | price | resulting trades | type       | tif     |
   551        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   552        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   553        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   554        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   555      Then the opening auction period ends for market "ETH/DEC19"
   556      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   557      And the parties submit update margin mode:
   558        | party  | market    | margin_mode     | margin_factor | error |
   559        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   560  
   561      And the parties should have the following margin levels:
   562        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   563        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   564  
   565      Given the parties place the following iceberg orders:
   566        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | reference |
   567        | party1 | ETH/DEC19 | buy  | 100    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
   568      And the parties should have the following account balances:
   569        | party  | asset | market id | margin | general | order margin |
   570        | party1 | BTC   | ETH/DEC19 | 0      | 9925    | 75           |
   571      And the order book should have the following volumes for market "ETH/DEC19":
   572        | side | price | volume |
   573        | buy  | 5     | 2      |
   574      When the parties cancel the following orders:
   575        | party  | reference |
   576        | party1 | iceberg   |
   577      # The order should be cancelled
   578      Then the iceberg orders should have the following states:
   579        | party  | market id | side | visible volume | price | status           | reserved volume | reference |
   580        | party1 | ETH/DEC19 | buy  | 2              | 5     | STATUS_CANCELLED | 98              | iceberg   |
   581      # The margin released
   582      And the parties should have the following account balances:
   583        | party  | asset | market id | margin | general | order margin |
   584        | party1 | BTC   | ETH/DEC19 | 0      | 10000   | 0            |
   585      # And the order book updated
   586      And the order book should have the following volumes for market "ETH/DEC19":
   587        | side | price | volume |
   588        | buy  | 5     | 0      |
   589  
   590    @iceberg
   591    Scenario: 010 An aggressive iceberg order crosses an order with volume > iceberg volume
   592      # setup accounts
   593      Given the parties deposit on asset's general account the following amount:
   594        | party  | asset | amount      |
   595        | party1 | BTC   | 10000000000 |
   596        | party2 | BTC   | 10000       |
   597        | aux    | BTC   | 100000      |
   598        | aux2   | BTC   | 100000      |
   599        | lpprov | BTC   | 90000000    |
   600  
   601      When the parties submit the following liquidity provision:
   602        | id  | party  | market id | commitment amount | fee | lp type    |
   603        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   604        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   605      And the parties place the following pegged iceberg orders:
   606        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset | reference |
   607        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    | p-1       |
   608        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    | p-2       |
   609      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   610      When the parties place the following orders:
   611        | party | market id | side | volume | price | resulting trades | type       | tif     |
   612        | aux   | ETH/DEC19 | buy  | 20     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   613        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   614        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   615        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   616      Then the opening auction period ends for market "ETH/DEC19"
   617      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   618      And the parties submit update margin mode:
   619        | party  | market    | margin_mode     | margin_factor | error |
   620        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   621  
   622      And the parties should have the following margin levels:
   623        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   624        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   625  
   626      When the network moves ahead "1" blocks
   627      And the orders should have the following status:
   628        | party  | reference | status        |
   629        | lpprov | p-1       | STATUS_PARKED |
   630        | lpprov | p-2       | STATUS_ACTIVE |
   631  
   632      Given the parties place the following orders:
   633        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   634        | party2 | ETH/DEC19 | sell | 15     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   635  
   636      Then the order book should have the following volumes for market "ETH/DEC19":
   637        | side | price | volume |
   638        | sell | 105   | 2      |
   639        | sell | 5     | 15     |
   640  
   641      #requried position margin: 10*5*0.15 = 7.5
   642      #maintenance margin: 10*min(5, 2*1e6)+10*0.1*2=52
   643      When the parties place the following iceberg orders:
   644        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | error |
   645        | party1 | ETH/DEC19 | buy  | 10     | 5     | 1                | TYPE_LIMIT | TIF_GTC | 2         | 1                    |       |
   646  
   647      And the parties should have the following account balances:
   648        | party  | asset | market id | margin | general    | order margin |
   649        | party1 | BTC   | ETH/DEC19 | 7      | 9999999988 | 0            |
   650  
   651    @iceberg
   652    Scenario: 011 An aggressive iceberg order crosses an order with volume < iceberg volume
   653      # setup accounts
   654      Given the parties deposit on asset's general account the following amount:
   655        | party  | asset | amount   |
   656        | party1 | BTC   | 10000    |
   657        | party2 | BTC   | 10000    |
   658        | aux    | BTC   | 100000   |
   659        | aux2   | BTC   | 100000   |
   660        | lpprov | BTC   | 90000000 |
   661  
   662      When the parties submit the following liquidity provision:
   663        | id  | party  | market id | commitment amount | fee | lp type    |
   664        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   665        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   666      And the parties place the following pegged iceberg orders:
   667        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   668        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   669        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   670      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   671      When the parties place the following orders:
   672        | party | market id | side | volume | price | resulting trades | type       | tif     |
   673        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   674        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   675        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   676        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   677      Then the opening auction period ends for market "ETH/DEC19"
   678      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   679      And the parties submit update margin mode:
   680        | party  | market    | margin_mode     | margin_factor | error |
   681        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   682  
   683      And the parties should have the following margin levels:
   684        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   685        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   686  
   687      Given the parties place the following orders:
   688        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   689        | party2 | ETH/DEC19 | sell | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   690      When the parties place the following iceberg orders:
   691        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | error               |
   692        | party1 | ETH/DEC19 | buy  | 15000  | 5     | 1                | TYPE_LIMIT | TIF_GTC | 200       | 1                    | margin check failed |
   693  
   694    @iceberg
   695    Scenario: 012 A passive iceberg order (the only order at the price level) crosses an order with volume > iceberg volume
   696      # setup accounts
   697      Given the parties deposit on asset's general account the following amount:
   698        | party  | asset | amount   |
   699        | party1 | BTC   | 10000    |
   700        | party2 | BTC   | 10000    |
   701        | aux    | BTC   | 100000   |
   702        | aux2   | BTC   | 100000   |
   703        | lpprov | BTC   | 90000000 |
   704  
   705      When the parties submit the following liquidity provision:
   706        | id  | party  | market id | commitment amount | fee | lp type    |
   707        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   708        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   709      And the parties place the following pegged iceberg orders:
   710        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   711        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   712        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   713      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   714      When the parties place the following orders:
   715        | party | market id | side | volume | price | resulting trades | type       | tif     |
   716        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   717        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   718        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   719        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   720      Then the opening auction period ends for market "ETH/DEC19"
   721      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   722      And the parties submit update margin mode:
   723        | party  | market    | margin_mode     | margin_factor | error |
   724        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   725  
   726      And the parties should have the following margin levels:
   727        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   728        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   729  
   730      Given the parties place the following iceberg orders:
   731        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size |
   732        | party1 | ETH/DEC19 | buy  | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    |
   733      When the parties place the following orders:
   734        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   735        | party2 | ETH/DEC19 | sell | 15     | 5     | 1                | TYPE_LIMIT | TIF_GTC |
   736      Then the following trades should be executed:
   737        | buyer  | seller | price | size |
   738        | party1 | party2 | 5     | 10   |
   739      And the iceberg orders should have the following states:
   740        | party  | market id | side | visible volume | price | status        | reserved volume |
   741        | party1 | ETH/DEC19 | buy  | 0              | 5     | STATUS_FILLED | 0               |
   742  
   743    @iceberg
   744    Scenario: 013 A passive iceberg order (one of multiple orders at the price level) crosses an order with volume > iceberg volume
   745      # setup accounts
   746      Given the parties deposit on asset's general account the following amount:
   747        | party  | asset | amount   |
   748        | party1 | BTC   | 10000    |
   749        | party2 | BTC   | 10000    |
   750        | party3 | BTC   | 10000    |
   751        | party4 | BTC   | 10000    |
   752        | aux    | BTC   | 100000   |
   753        | aux2   | BTC   | 100000   |
   754        | lpprov | BTC   | 90000000 |
   755      And the markets are updated:
   756        | id        | linear slippage factor |
   757        | ETH/DEC19 | 0                      |
   758      When the parties submit the following liquidity provision:
   759        | id  | party  | market id | commitment amount | fee | lp type    |
   760        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   761        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   762  
   763      And the parties place the following pegged iceberg orders:
   764        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   765        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   766        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   767      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   768      When the parties place the following orders:
   769        | party | market id | side | volume | price | resulting trades | type       | tif     |
   770        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   771        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   772        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   773        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   774      And the parties submit update margin mode:
   775        | party  | market    | margin_mode     | margin_factor | error |
   776        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   777  
   778      And the parties should have the following margin levels:
   779        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   780        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   781      Then the opening auction period ends for market "ETH/DEC19"
   782      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   783  
   784      Given the parties place the following iceberg orders:
   785        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size |
   786        | party1 | ETH/DEC19 | buy  | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    |
   787      And the parties place the following orders:
   788        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   789        | party2 | ETH/DEC19 | buy  | 7      | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   790        | party3 | ETH/DEC19 | buy  | 7      | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   791      When the parties place the following orders:
   792        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   793        | party4 | ETH/DEC19 | sell | 15     | 5     | 3                | TYPE_LIMIT | TIF_GTC |
   794      Then the following trades should be executed:
   795        | buyer  | seller | price | size |
   796        | party1 | party4 | 5     | 2    |
   797        | party2 | party4 | 5     | 7    |
   798        | party3 | party4 | 5     | 6    |
   799      And the iceberg orders should have the following states:
   800        | party  | market id | side | visible volume | price | status        | reserved volume |
   801        | party1 | ETH/DEC19 | buy  | 2              | 5     | STATUS_ACTIVE | 6               |
   802  
   803    @iceberg
   804    Scenario: 014 An aggressive iceberg order crosses orders where the cumulative volume > iceberg volume
   805      # setup accounts
   806      Given the parties deposit on asset's general account the following amount:
   807        | party  | asset | amount   |
   808        | party1 | BTC   | 10000    |
   809        | party2 | BTC   | 10000    |
   810        | party3 | BTC   | 10000    |
   811        | party4 | BTC   | 10000    |
   812        | aux    | BTC   | 100000   |
   813        | aux2   | BTC   | 100000   |
   814        | lpprov | BTC   | 90000000 |
   815  
   816      When the parties submit the following liquidity provision:
   817        | id  | party  | market id | commitment amount | fee | lp type    |
   818        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   819        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   820  
   821      And the parties place the following pegged iceberg orders:
   822        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   823        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   824        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   825      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   826      When the parties place the following orders:
   827        | party | market id | side | volume | price | resulting trades | type       | tif     |
   828        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   829        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   830        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   831        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   832      And the parties submit update margin mode:
   833        | party  | market    | margin_mode     | margin_factor | error |
   834        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   835  
   836      And the parties should have the following margin levels:
   837        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   838        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   839      Then the opening auction period ends for market "ETH/DEC19"
   840      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   841  
   842      Given the parties place the following orders:
   843        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   844        | party2 | ETH/DEC19 | sell | 30     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   845        | party3 | ETH/DEC19 | sell | 40     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   846        | party4 | ETH/DEC19 | sell | 50     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   847      When the parties place the following iceberg orders:
   848        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | error               |
   849        | party1 | ETH/DEC19 | buy  | 50000  | 5     | 3                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | margin check failed |
   850  
   851    @iceberg
   852    Scenario: 015 An aggressive iceberg order crosses orders where the cumulative volume < iceberg volume
   853      # setup accounts
   854      Given the parties deposit on asset's general account the following amount:
   855        | party  | asset | amount   |
   856        | party1 | BTC   | 10000    |
   857        | party2 | BTC   | 10000    |
   858        | party3 | BTC   | 10000    |
   859        | party4 | BTC   | 10000    |
   860        | aux    | BTC   | 100000   |
   861        | aux2   | BTC   | 100000   |
   862        | lpprov | BTC   | 90000000 |
   863  
   864      When the parties submit the following liquidity provision:
   865        | id  | party  | market id | commitment amount | fee | lp type    |
   866        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   867        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   868      And the parties place the following pegged iceberg orders:
   869        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   870        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   871        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   872      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   873      When the parties place the following orders:
   874        | party | market id | side | volume | price | resulting trades | type       | tif     |
   875        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   876        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   877        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   878        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   879      And the parties submit update margin mode:
   880        | party  | market    | margin_mode     | margin_factor | error |
   881        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   882  
   883      And the parties should have the following margin levels:
   884        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   885        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   886      Then the opening auction period ends for market "ETH/DEC19"
   887      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   888  
   889      Given the parties place the following orders:
   890        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   891        | party2 | ETH/DEC19 | sell | 30     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   892        | party3 | ETH/DEC19 | sell | 40     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   893      #order margin: 50000*5*0.15=37500
   894      When the parties place the following iceberg orders:
   895        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | error               |
   896        | party1 | ETH/DEC19 | buy  | 50000  | 5     | 2                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | margin check failed |
   897  
   898    @iceberg
   899    Scenario: 016 Amended order trades with iceberg order triggering a refresh
   900      Given the parties deposit on asset's general account the following amount:
   901        | party  | asset | amount   |
   902        | party1 | BTC   | 10000    |
   903        | party2 | BTC   | 10000    |
   904        | party3 | BTC   | 10000    |
   905        | party4 | BTC   | 10000    |
   906        | aux    | BTC   | 100000   |
   907        | aux2   | BTC   | 100000   |
   908        | lpprov | BTC   | 90000000 |
   909  
   910      When the parties submit the following liquidity provision:
   911        | id  | party  | market id | commitment amount | fee | lp type    |
   912        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   913        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   914      And the parties place the following pegged iceberg orders:
   915        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   916        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   917        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   918      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   919      When the parties place the following orders:
   920        | party | market id | side | volume | price | resulting trades | type       | tif     |
   921        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   922        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   923        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   924        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   925      And the parties submit update margin mode:
   926        | party  | market    | margin_mode     | margin_factor | error |
   927        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   928  
   929      And the parties should have the following margin levels:
   930        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   931        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   932      Then the opening auction period ends for market "ETH/DEC19"
   933      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   934  
   935      Given the parties place the following iceberg orders:
   936        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size |
   937        | party1 | ETH/DEC19 | sell | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    |
   938      And the parties place the following orders:
   939        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   940        | party2 | ETH/DEC19 | buy  | 7      | 4     | 0                | TYPE_LIMIT | TIF_GTC | order-to-amend |
   941        | party3 | ETH/DEC19 | sell | 5      | 5     | 0                | TYPE_LIMIT | TIF_GTC |                |
   942      When the parties amend the following orders:
   943        | party  | reference      | price | size delta | tif     |
   944        | party2 | order-to-amend | 5     | 0          | TIF_GTC |
   945      Then the following trades should be executed:
   946        | buyer  | seller | price | size |
   947        | party2 | party1 | 5     | 2    |
   948        | party2 | party3 | 5     | 5    |
   949      And the iceberg orders should have the following states:
   950        | party  | market id | side | visible volume | price | status        | reserved volume |
   951        | party1 | ETH/DEC19 | sell | 2              | 5     | STATUS_ACTIVE | 6               |
   952  
   953    @iceberg
   954    Scenario: 017 Attempting to wash trade with iceberg orders
   955      # setup accounts
   956      Given the parties deposit on asset's general account the following amount:
   957        | party  | asset | amount   |
   958        | party1 | BTC   | 10000    |
   959        | party2 | BTC   | 10000    |
   960        | party3 | BTC   | 10000    |
   961        | party4 | BTC   | 10000    |
   962        | aux    | BTC   | 100000   |
   963        | aux2   | BTC   | 100000   |
   964        | lpprov | BTC   | 90000000 |
   965  
   966      When the parties submit the following liquidity provision:
   967        | id  | party  | market id | commitment amount | fee | lp type    |
   968        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   969        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
   970  
   971      And the parties place the following pegged iceberg orders:
   972        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   973        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
   974        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
   975      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
   976      When the parties place the following orders:
   977        | party | market id | side | volume | price | resulting trades | type       | tif     |
   978        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   979        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
   980        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   981        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
   982  
   983      And the parties submit update margin mode:
   984        | party  | market    | margin_mode     | margin_factor | error |
   985        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
   986  
   987      And the parties should have the following margin levels:
   988        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
   989        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
   990      Then the opening auction period ends for market "ETH/DEC19"
   991      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
   992  
   993      Given the parties place the following orders:
   994        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   995        | party2 | ETH/DEC19 | sell | 5      | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   996        | party3 | ETH/DEC19 | sell | 5      | 5     | 0                | TYPE_LIMIT | TIF_GTC |
   997      And the parties place the following iceberg orders:
   998        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | reference |
   999        | party1 | ETH/DEC19 | sell | 5      | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
  1000      When the parties place the following orders:
  1001        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error |
  1002        | party1 | ETH/DEC19 | buy  | 15     | 5     | 2                | TYPE_LIMIT | TIF_GTC | normal    |       |
  1003      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
  1004  
  1005      And the orders should have the following status:
  1006        | party  | reference | status                  |
  1007        | party1 | normal    | STATUS_PARTIALLY_FILLED |
  1008      And the iceberg orders should have the following states:
  1009        | party  | market id | reference | side | visible volume | price | status        | reserved volume |
  1010        | party1 | ETH/DEC19 | iceberg   | sell | 2              | 5     | STATUS_ACTIVE | 3               |
  1011      #wash trade order is stopped
  1012      And the order book should have the following volumes for market "ETH/DEC19":
  1013        | side | price | volume |
  1014        | buy  | 5     | 0      |
  1015  
  1016    @iceberg
  1017    Scenario: 018 An order matches multiple icebergs at the same level where the order volume < cumulative iceberg display volume
  1018      # setup accounts
  1019      Given the parties deposit on asset's general account the following amount:
  1020        | party  | asset | amount   |
  1021        | party1 | BTC   | 10000    |
  1022        | party2 | BTC   | 10000    |
  1023        | party3 | BTC   | 10000    |
  1024        | party4 | BTC   | 10000    |
  1025        | aux    | BTC   | 100000   |
  1026        | aux2   | BTC   | 100000   |
  1027        | lpprov | BTC   | 90000000 |
  1028  
  1029      When the parties submit the following liquidity provision:
  1030        | id  | party  | market id | commitment amount | fee | lp type    |
  1031        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1032        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1033  
  1034      And the parties place the following pegged iceberg orders:
  1035        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1036        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
  1037        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
  1038      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
  1039      When the parties place the following orders:
  1040        | party | market id | side | volume | price | resulting trades | type       | tif     |
  1041        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
  1042        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
  1043        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1044        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1045      And the parties submit update margin mode:
  1046        | party  | market    | margin_mode     | margin_factor | error |
  1047        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
  1048  
  1049      And the parties should have the following margin levels:
  1050        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
  1051        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
  1052      Then the opening auction period ends for market "ETH/DEC19"
  1053      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
  1054  
  1055      Given the parties place the following iceberg orders:
  1056        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | reference |
  1057        | party1 | ETH/DEC19 | sell | 200    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
  1058        | party2 | ETH/DEC19 | sell | 100    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg2  |
  1059        | party3 | ETH/DEC19 | sell | 100    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg3  |
  1060      When the parties place the following orders:
  1061        | party  | market id | side | volume | price | resulting trades | type       | tif     |
  1062        | party4 | ETH/DEC19 | buy  | 300    | 5     | 3                | TYPE_LIMIT | TIF_GTC |
  1063      Then the following trades should be executed:
  1064        | buyer  | seller | price | size |
  1065        | party4 | party1 | 5     | 150  |
  1066        | party4 | party2 | 5     | 75   |
  1067        | party4 | party3 | 5     | 75   |
  1068      And the iceberg orders should have the following states:
  1069        | party  | market id | side | visible volume | price | status        | reserved volume | reference |
  1070        | party1 | ETH/DEC19 | sell | 2              | 5     | STATUS_ACTIVE | 48              | iceberg   |
  1071        | party2 | ETH/DEC19 | sell | 2              | 5     | STATUS_ACTIVE | 23              | iceberg2  |
  1072        | party3 | ETH/DEC19 | sell | 2              | 5     | STATUS_ACTIVE | 23              | iceberg3  |
  1073  
  1074    @iceberg
  1075    Scenario: 019 An order matches multiple icebergs at the same level where the order volume > cumulative iceberg display volume
  1076      # setup accounts
  1077      Given the parties deposit on asset's general account the following amount:
  1078        | party  | asset | amount   |
  1079        | party1 | BTC   | 10000    |
  1080        | party2 | BTC   | 10000    |
  1081        | party3 | BTC   | 10000    |
  1082        | party4 | BTC   | 10000    |
  1083        | aux    | BTC   | 100000   |
  1084        | aux2   | BTC   | 100000   |
  1085        | lpprov | BTC   | 90000000 |
  1086  
  1087      When the parties submit the following liquidity provision:
  1088        | id  | party  | market id | commitment amount | fee | lp type    |
  1089        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1090        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1091  
  1092      And the parties place the following pegged iceberg orders:
  1093        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1094        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
  1095        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
  1096      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
  1097      When the parties place the following orders:
  1098        | party | market id | side | volume | price | resulting trades | type       | tif     |
  1099        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
  1100        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
  1101        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1102        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1103      And the parties submit update margin mode:
  1104        | party  | market    | margin_mode     | margin_factor | error |
  1105        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
  1106  
  1107      And the parties should have the following margin levels:
  1108        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
  1109        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
  1110      Then the opening auction period ends for market "ETH/DEC19"
  1111      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
  1112  
  1113      Given the parties place the following iceberg orders:
  1114        | party  | market id | side | volume | price | resulting trades | type       | tif     | peak size | minimum visible size | reference |
  1115        | party1 | ETH/DEC19 | sell | 200    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
  1116        | party2 | ETH/DEC19 | sell | 100    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
  1117        | party3 | ETH/DEC19 | sell | 100    | 5     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | iceberg   |
  1118      When the parties place the following orders:
  1119        | party  | market id | side | volume | price | resulting trades | type       | tif     |
  1120        | party4 | ETH/DEC19 | buy  | 600    | 5     | 3                | TYPE_LIMIT | TIF_GTC |
  1121      Then the following trades should be executed:
  1122        | buyer  | seller | price | size |
  1123        | party4 | party1 | 5     | 200  |
  1124        | party4 | party2 | 5     | 100  |
  1125        | party4 | party3 | 5     | 100  |
  1126  
  1127    @iceberg
  1128    Scenario: 020 Pegged orders are not re-priced as price-levels are consumed
  1129      # setup accounts
  1130      Given the parties deposit on asset's general account the following amount:
  1131        | party  | asset | amount   |
  1132        | party1 | BTC   | 10000    |
  1133        | party2 | BTC   | 10000    |
  1134        | party3 | BTC   | 10000    |
  1135        | aux    | BTC   | 100000   |
  1136        | aux2   | BTC   | 100000   |
  1137        | lpprov | BTC   | 90000000 |
  1138  
  1139      When the parties submit the following liquidity provision:
  1140        | id  | party  | market id | commitment amount | fee | lp type    |
  1141        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1142        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
  1143  
  1144      And the parties place the following pegged iceberg orders:
  1145        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1146        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50     | 100    |
  1147        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50     | 100    |
  1148      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
  1149      When the parties place the following orders:
  1150        | party | market id | side | volume | price | resulting trades | type       | tif     |
  1151        | aux   | ETH/DEC19 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC |
  1152        | aux   | ETH/DEC19 | sell | 1      | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
  1153        | aux2  | ETH/DEC19 | buy  | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1154        | aux   | ETH/DEC19 | sell | 1      | 2     | 0                | TYPE_LIMIT | TIF_GTC |
  1155      And the parties submit update margin mode:
  1156        | party  | market    | margin_mode     | margin_factor | error |
  1157        | party1 | ETH/DEC19 | isolated margin | 0.15          |       |
  1158  
  1159      And the parties should have the following margin levels:
  1160        | party  | market id | maintenance | search | initial | release | margin mode     | margin factor | order |
  1161        | party1 | ETH/DEC19 | 0           | 0      | 0       | 0       | isolated margin | 0.15          | 0     |
  1162      Then the opening auction period ends for market "ETH/DEC19"
  1163      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
  1164  
  1165      Given the parties place the following orders:
  1166        | party  | market id | side | volume | price | resulting trades | type       | tif     |
  1167        | party2 | ETH/DEC19 | buy  | 10     | 5     | 0                | TYPE_LIMIT | TIF_GTC |
  1168        | party2 | ETH/DEC19 | buy  | 1      | 10    | 0                | TYPE_LIMIT | TIF_GTC |
  1169        | party2 | ETH/DEC19 | sell | 1      | 20    | 0                | TYPE_LIMIT | TIF_GTC |
  1170        | party2 | ETH/DEC19 | sell | 10     | 25    | 0                | TYPE_LIMIT | TIF_GTC |
  1171      And the parties place the following pegged iceberg orders:
  1172        | party  | market id | side | volume | resulting trades | type       | tif     | peak size | minimum visible size | pegged reference | offset | error                                                         |
  1173        | party1 | ETH/DEC19 | buy  | 10     | 0                | TYPE_LIMIT | TIF_GTC | 2         | 1                    | BID              | 1      | OrderError: pegged orders not allowed in isolated margin mode |
  1174      And the parties place the following pegged orders:
  1175        | party  | market id | side | volume | pegged reference | offset | error                                                         |
  1176        | party1 | ETH/DEC19 | buy  | 1      | BID              | 2      | OrderError: pegged orders not allowed in isolated margin mode |
  1177      When the parties place the following orders:
  1178        | party  | market id | side | volume | price | resulting trades | type       | tif     |
  1179        | party3 | ETH/DEC19 | sell | 12     | 8     | 1                | TYPE_LIMIT | TIF_GTC |
  1180      # Check pegged ordinary and iceberg orders are not re-priced as the best-bid price-level is consumed
  1181      Then the following trades should be executed:
  1182        | buyer  | seller | price | size |
  1183        | party2 | party3 | 10    | 1    |
  1184