code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0029-FEES-trading_fees.feature (about)

     1  Feature: Fees calculations
     2  
     3    Background:
     4      Given the following network parameters are set:
     5        | name                                               | value |
     6        | network.markPriceUpdateMaximumFrequency            | 0s    |
     7        | limits.markets.maxPeggedOrders                     | 4     |
     8        | market.liquidity.providersFeeCalculationTimeStep | 10s   |
     9  
    10      Given the fees configuration named "fees-config-1":
    11        | maker fee | infrastructure fee |
    12        | 0.005     | 0.002              |
    13  
    14      And the price monitoring named "price-monitoring":
    15        | horizon | probability | auction extension |
    16        | 1       | 0.99        | 3                 |
    17  
    18      And the price monitoring named "price-monitoring-1":
    19        | horizon | probability | auction extension |
    20        | 1       | 0.99        | 300               |
    21  
    22      And the simple risk model named "simple-risk-model-1":
    23        | long | short | max move up | min move down | probability of trading |
    24        | 0.2  | 0.1   | 100         | -100          | 0.1                    |
    25  
    26      And the log normal risk model named "log-normal-risk-model-1":
    27        | risk aversion | tau | mu | r   | sigma |
    28        | 0.000001      | 0.1 | 0  | 1.4 | -1    |
    29  
    30      Given the liquidity monitoring parameters:
    31        | name       | triggering ratio | time window | scaling factor |
    32        | lqm-params | 1.0              | 24h         | 1.0            |
    33  
    34      And the liquidity sla params named "SLA":
    35        | price range | commitment min time fraction | performance hysteresis epochs | sla competition factor |
    36        | 1.0         | 0.5                          | 1                             | 1.0                    |
    37  
    38  
    39    Scenario: S001, Testing fees in continuous trading with one trade and no liquidity providers (0029-FEES-001)
    40  
    41      And the markets:
    42        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    43        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
    44      Given the parties deposit on asset's general account the following amount:
    45        | party   | asset | amount    |
    46        | aux1    | ETH   | 100000000 |
    47        | aux2    | ETH   | 100000000 |
    48        | trader3 | ETH   | 10000     |
    49        | trader4 | ETH   | 10000     |
    50        | lpprov  | ETH   | 100000000 |
    51  
    52      When the parties submit the following liquidity provision:
    53        | id  | party  | market id | commitment amount | fee | lp type    |
    54        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
    55        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
    56      When the parties place the following orders:
    57        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
    58        | lpprov | ETH/DEC21 | buy  | 100    | 890   | 0                | TYPE_LIMIT | TIF_GTC | peg-1     |
    59        | lpprov | ETH/DEC21 | sell | 100    | 1110  | 0                | TYPE_LIMIT | TIF_GTC | peg-2     |
    60      Then the parties place the following orders:
    61        | party | market id | side | volume | price | resulting trades | type       | tif     |
    62        | aux1  | ETH/DEC21 | buy  | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    63        | aux2  | ETH/DEC21 | sell | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    64        | aux1  | ETH/DEC21 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
    65        | aux2  | ETH/DEC21 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
    66  
    67      Then the opening auction period ends for market "ETH/DEC21"
    68      And the market data for the market "ETH/DEC21" should be:
    69        | mark price | trading mode            |
    70        | 1000       | TRADING_MODE_CONTINUOUS |
    71      When the parties place the following orders with ticks:
    72        | party   | market id | side | volume | price | resulting trades | type       | tif     |
    73        | trader3 | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
    74  
    75      # margin_maitenance_trader3 = 3*1000*0.2=600
    76      # margin_initial_trader3 = 600*1.2=720
    77  
    78      Then the parties should have the following account balances:
    79        | party   | asset | market id | margin | general |
    80        | trader3 | ETH   | ETH/DEC21 | 720    | 9280    |
    81  
    82      And the accumulated infrastructure fees should be "0" for the asset "ETH"
    83      And the accumulated liquidity fees should be "0" for the market "ETH/DEC21"
    84  
    85      Then the parties place the following orders with ticks:
    86        | party   | market id | side | volume | price | resulting trades | type       | tif     |
    87        | trader4 | ETH/DEC21 | sell | 4      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
    88  
    89      And the market data for the market "ETH/DEC21" should be:
    90        | mark price | trading mode            |
    91        | 1002       | TRADING_MODE_CONTINUOUS |
    92  
    93      Then the following trades should be executed:
    94        | buyer   | price | size | seller  | aggressor side |
    95        | trader3 | 1002  | 3    | trader4 | sell           |
    96  
    97      Then the order book should have the following volumes for market "ETH/DEC21":
    98        | side | price | volume |
    99        | buy | 890 | 100 |
   100        | buy  | 900   | 1      |
   101        | sell | 1100  | 1      |
   102        | sell | 1110 | 100 |
   103  
   104  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 3 *1002 = 3006
   105  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 3006 = 6.012 = 7 (rounded up to nearest whole value)
   106  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 3006 = 15.030 = 16 (rounded up to nearest whole value)
   107  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.1 * 3006 = 301
   108  
   109      And the following transfers should happen:
   110        | from    | to      | from account            | to account                       | market id | amount | asset |
   111        | trader4 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 16     | ETH   |
   112        | trader4 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 7      | ETH   |
   113        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 301 | ETH |
   114        | market  | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 16     | ETH   |
   115  
   116  # total_fee = infrastructure_fee + maker_fee + liquidity_fee = 7 + 16 + 0 = 23
   117      And the accumulated infrastructure fees should be "7" for the asset "ETH"
   118      And the accumulated liquidity fees should be "301" for the market "ETH/DEC21"
   119  
   120    Scenario: S002, Testing fees in continuous trading with two trades and no liquidity providers (0029-FEES-001, 0029-FEES-003, 0029-FEES-006)
   121      And the markets:
   122        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   123        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
   124      Given the parties deposit on asset's general account the following amount:
   125        | party    | asset | amount    |
   126        | aux1     | ETH   | 100000000 |
   127        | aux2     | ETH   | 100000000 |
   128        | trader3a | ETH   | 10000     |
   129        | trader3b | ETH   | 10000     |
   130        | trader4  | ETH   | 10000     |
   131        | lpprov   | ETH   | 100000000 |
   132  
   133      When the parties submit the following liquidity provision:
   134        | id  | party  | market id | commitment amount | fee | lp type    |
   135        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   136        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   137      When the parties place the following orders:
   138        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference |
   139        | lpprov | ETH/DEC21 | buy  | 100    | 890   | 0                | TYPE_LIMIT | TIF_GTC | peg-1     |
   140        | lpprov | ETH/DEC21 | sell | 100    | 1110  | 0                | TYPE_LIMIT | TIF_GTC | peg-2     |
   141  
   142      Then the parties place the following orders:
   143        | party | market id | side | volume | price | resulting trades | type       | tif     |
   144        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   145        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   146        | aux1  | ETH/DEC21 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   147        | aux2  | ETH/DEC21 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
   148  
   149      Then the opening auction period ends for market "ETH/DEC21"
   150      And the market data for the market "ETH/DEC21" should be:
   151        | mark price | trading mode            |
   152        | 1000       | TRADING_MODE_CONTINUOUS |
   153      When the parties place the following orders with ticks:
   154        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   155        | trader3a | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   156        | trader3b | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   157  
   158      Then the parties should have the following account balances:
   159        | party    | asset | market id | margin | general |
   160        | trader3a | ETH   | ETH/DEC21 | 480    | 9520    |
   161        | trader3b | ETH   | ETH/DEC21 | 240    | 9760    |
   162  
   163      And the accumulated liquidity fees should be "0" for the market "ETH/DEC21"
   164      And the accumulated infrastructure fees should be "0" for the asset "ETH"
   165  
   166      Then the parties place the following orders with ticks:
   167        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   168        | trader4 | ETH/DEC21 | sell | 4      | 1002  | 2                | TYPE_LIMIT | TIF_GTC |
   169  
   170      Then the market data for the market "ETH/DEC21" should be:
   171        | mark price | trading mode            |
   172        | 1002       | TRADING_MODE_CONTINUOUS |
   173  
   174      Then the following trades should be executed:
   175        | buyer    | price | size | seller  | aggressor side |
   176        | trader3a | 1002  | 2    | trader4 | sell           |
   177        | trader3b | 1002  | 1    | trader4 | sell           |
   178  
   179  # For trader3a-
   180  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 1002 = 2004
   181  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
   182  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 2004 = 10.02 = 11 (rounded up to nearest whole value)
   183  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0 * 3006 = 0
   184  
   185  # For trader3b -
   186  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
   187  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
   188  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
   189  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.1 * 3006 = 302
   190  
   191      And the following transfers should happen:
   192        | from    | to       | from account            | to account                       | market id | amount | asset |
   193        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 11     | ETH   |
   194        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   195        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 8      | ETH   |
   196        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 302 | ETH |
   197        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 11     | ETH   |
   198        | market  | trader3b | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   199  
   200      And the accumulated infrastructure fees should be "8" for the asset "ETH"
   201      And the accumulated liquidity fees should be "302" for the market "ETH/DEC21"
   202  
   203    @WhutBug
   204    Scenario: S003, Testing fees in continuous trading with two trades and one liquidity providers with 10 and 0 s liquidity fee distribution timestep (0029-FEES-004,0029-FEES-006)
   205  
   206      And the markets:
   207        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   208        | ETH/DEC21 | ETH        | ETH   | simple-risk-model-1 | default-margin-calculator | 2                | fees-config-1 | price-monitoring | default-eth-for-future | 1e0                    | 0                         | default-futures |
   209  
   210      Given the parties deposit on asset's general account the following amount:
   211        | party    | asset | amount    |
   212        | aux1     | ETH   | 100000000 |
   213        | aux2     | ETH   | 100000000 |
   214        | trader3a | ETH   | 10000     |
   215        | trader3b | ETH   | 10000     |
   216        | trader4  | ETH   | 10000     |
   217  
   218      Then the parties place the following orders:
   219        | party | market id | side | volume | price | resulting trades | type       | tif     |
   220        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   221        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   222        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   223        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   224  
   225      Given the parties submit the following liquidity provision:
   226        | id  | party | market id | commitment amount | fee   | lp type    |
   227        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | submission |
   228        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment  |
   229      When the parties place the following orders:
   230        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   231        | aux1  | ETH/DEC21 | buy  | 10     | 910   | 0                | TYPE_LIMIT | TIF_GTC | peg-1     |
   232        | aux1  | ETH/DEC21 | sell | 10     | 1090  | 0                | TYPE_LIMIT | TIF_GTC | peg-2     |
   233      Then the opening auction period ends for market "ETH/DEC21"
   234      And the market data for the market "ETH/DEC21" should be:
   235        | mark price | trading mode            |
   236        | 1000       | TRADING_MODE_CONTINUOUS |
   237  
   238      And the order book should have the following volumes for market "ETH/DEC21":
   239        | side | price | volume |
   240        | buy  | 910   | 10     |
   241        | buy  | 920   | 1      |
   242        | sell | 1080  | 1      |
   243        | sell | 1090  | 10     |
   244  
   245      When the parties place the following orders with ticks:
   246        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   247        | trader3a | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   248        | trader3b | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   249        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 2                | TYPE_LIMIT | TIF_GTC |
   250  
   251      And the liquidity fee factor should be "0.001" for the market "ETH/DEC21"
   252      And the accumulated liquidity fees should be "5" for the market "ETH/DEC21"
   253  
   254      Then the market data for the market "ETH/DEC21" should be:
   255        | mark price | trading mode            |
   256        | 1002       | TRADING_MODE_CONTINUOUS |
   257  
   258  # For trader3a-
   259  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 1002 = 2004
   260  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
   261  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 2004 = 10.02 = 11 (rounded up to nearest whole value)
   262  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3 (rounded up to nearest whole value)
   263  
   264  # For trader3b -
   265  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
   266  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
   267  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
   268  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 1002 = 1.002 = 2 (rounded up to nearest whole value)
   269  
   270      Then the following trades should be executed:
   271        | buyer    | price | size | seller  | aggressor side | buyer fee | seller fee | seller infrastructure fee | seller maker fee | seller liquidity fee |
   272        | trader3a | 1002  | 2    | trader4 | sell           | 0         | 19         | 5                  | 11        | 3             |
   273        | trader3b | 1002  | 1    | trader4 | sell           | 0         | 11         | 3                  | 6         | 2             |
   274  
   275      And the following transfers should happen:
   276        | from    | to       | from account            | to account                       | market id | amount | asset |
   277        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 11     | ETH   |
   278        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   279        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 8      | ETH   |
   280        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 5      | ETH   |
   281        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 11     | ETH   |
   282        | market  | trader3b | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   283  
   284  # total_fee = infrastructure_fee + maker_fee + liquidity_fee = 8 + 11 + 6 + 0 = 25
   285  
   286      And the accumulated infrastructure fees should be "8" for the asset "ETH"
   287      And the accumulated liquidity fees should be "5" for the market "ETH/DEC21"
   288  
   289      When the network moves ahead "11" blocks
   290  
   291      And the following transfers should happen:
   292        | from   | to   | from account                | to account           | market id | amount | asset |
   293        | market | aux1 | ACCOUNT_TYPE_FEES_LIQUIDITY | ACCOUNT_TYPE_LP_LIQUIDITY_FEES | ETH/DEC21 | 5 | ETH |
   294  
   295  
   296    @WhutMargin
   297    Scenario: S005, Testing fees get collected when amended order trades (0029-FEES-005)
   298      And the markets:
   299        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   300        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
   301  
   302      Given the parties deposit on asset's general account the following amount:
   303        | party    | asset | amount    |
   304        | aux1     | ETH   | 100000000 |
   305        | aux2     | ETH   | 100000000 |
   306        | trader3a | ETH   | 10000     |
   307        | trader3b | ETH   | 10000     |
   308        | trader4  | ETH   | 5000      |
   309        | lpprov   | ETH   | 100000000 |
   310  
   311      When the parties submit the following liquidity provision:
   312        | id  | party  | market id | commitment amount | fee | lp type    |
   313        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   314        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   315      And the parties place the following pegged iceberg orders:
   316        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   317        | lpprov | ETH/DEC21 | 50        | 1                    | buy  | BID              | 50     | 10     |
   318        | lpprov | ETH/DEC21 | 50        | 1                    | sell | ASK              | 50     | 10     |
   319  
   320      Then the parties place the following orders:
   321        | party | market id | side | volume | price | resulting trades | type       | tif     |
   322        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   323        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   324        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   325        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   326  
   327      Then the opening auction period ends for market "ETH/DEC21"
   328      And the market data for the market "ETH/DEC21" should be:
   329        | mark price | trading mode            |
   330        | 1000       | TRADING_MODE_CONTINUOUS |
   331  
   332      When the parties place the following orders with ticks:
   333        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   334        | trader3a | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   335        | trader3b | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   336        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 2                | TYPE_LIMIT | TIF_GTC |
   337  
   338      Then the market data for the market "ETH/DEC21" should be:
   339        | mark price | trading mode            |
   340        | 1002       | TRADING_MODE_CONTINUOUS |
   341  
   342      Then the following trades should be executed:
   343        | buyer    | price | size | seller  |
   344        | trader3a | 1002  | 2    | trader4 |
   345        | trader3b | 1002  | 1    | trader4 |
   346  
   347  # For trader3a-
   348  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 1002 = 2004
   349  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
   350  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 2004 = 10.02 = 11 (rounded up to nearest whole value)
   351  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3 (rounded up to nearest whole value)
   352  
   353  # For trader3b -
   354  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
   355  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
   356  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
   357  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 1002 = 1.002 = 2 (rounded up to nearest whole value)
   358  
   359      And the following transfers should happen:
   360        | from    | to       | from account            | to account                       | market id | amount | asset |
   361        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 11     | ETH   |
   362        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   363        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 8      | ETH   |
   364        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 11     | ETH   |
   365        | market  | trader3b | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   366  
   367  # total_fee = maker_fee + infrastructure_fee + liquidity_fee =  11 + 6 + 8 = 25
   368  
   369      # Placing second set of orders
   370      When the parties place the following orders with ticks:
   371        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   372        | trader3a | ETH/DEC21 | buy  | 2      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | trader3a-buy-1 |
   373        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | trader4-sell-2 |
   374  
   375      # reducing size
   376      And the parties amend the following orders:
   377        | party   | reference      | price | size delta | tif     |
   378        | trader4 | trader4-sell-2 | 1000  | 0          | TIF_GTC |
   379  
   380      # matching the order now
   381      Then the following trades should be executed:
   382        | buyer    | price | size | seller  |
   383        | trader3a | 1000  | 2    | trader4 |
   384  
   385      # checking if continuous mode still exists
   386      Then the market data for the market "ETH/DEC21" should be:
   387        | mark price | last traded price | trading mode            |
   388        | 1002       | 1000              | TRADING_MODE_CONTINUOUS |
   389  
   390      And the following transfers should happen:
   391        | from    | to       | from account            | to account                       | market id | amount | asset |
   392        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 10     | ETH   |
   393        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 4      | ETH   |
   394        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 10     | ETH   |
   395  
   396    @WhutMargin
   397    Scenario: S006, Testing fees in continuous trading with insufficient balance in their general account but margin covers the fees (0029-FEES-008)
   398  
   399      And the markets:
   400        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   401        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
   402      Given the parties deposit on asset's general account the following amount:
   403        | party   | asset | amount    |
   404        | aux1    | ETH   | 100000000 |
   405        | aux2    | ETH   | 100000000 |
   406        | trader3 | ETH   | 10000000  |
   407        | trader4 | ETH   | 30000     |
   408        | lpprov  | ETH   | 100000000 |
   409  
   410      When the parties submit the following liquidity provision:
   411        | id  | party  | market id | commitment amount | fee | lp type    |
   412        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   413        | lp1 | lpprov | ETH/DEC21 | 90000000 | 0.1 | submission |
   414  
   415      Then the parties place the following orders:
   416        | party | market id | side | volume | price | resulting trades | type       | tif     |
   417        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   418        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   419        | aux1  | ETH/DEC21 | buy  | 300    | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   420        | aux2  | ETH/DEC21 | sell | 300    | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   421  
   422      Then the opening auction period ends for market "ETH/DEC21"
   423      And the market data for the market "ETH/DEC21" should be:
   424        | mark price | trading mode            | target stake | supplied stake |
   425        | 1000       | TRADING_MODE_CONTINUOUS | 2000         | 90000000       |
   426  
   427      Then the order book should have the following volumes for market "ETH/DEC21":
   428        | side | price | volume |
   429        | buy  | 910   | 0      |
   430        | buy  | 920   | 300    |
   431        | sell | 1080  | 300    |
   432        | sell | 1090  | 0      |
   433  
   434      When the parties place the following orders with ticks:
   435        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   436        | trader3 | ETH/DEC21 | buy  | 100    | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   437        | trader4 | ETH/DEC21 | sell | 100    | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   438  
   439      Then the market data for the market "ETH/DEC21" should be:
   440        | mark price | trading mode            |
   441        | 1002       | TRADING_MODE_CONTINUOUS |
   442  
   443  #fee paid by trader4: 100*1002*(0.1+0.005+0.002)=10722
   444      Then the following trades should be executed:
   445        | buyer   | price | size | seller  |
   446        | trader3 | 1002  | 100  | trader4 |
   447  
   448      When the parties place the following orders with ticks:
   449        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference     |
   450        | trader3 | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | trader3-buy-1 |
   451        | aux1    | ETH/DEC21 | sell | 1      | 1002  | 1                | TYPE_LIMIT | TIF_GTC | aux1-sell-2   |
   452  
   453      And the following transfers should happen:
   454        | from    | to     | from account         | to account                       | market id | amount | asset |
   455        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 501    | ETH   |
   456        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 10020  | ETH   |
   457        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 201    | ETH   |
   458        | aux1    | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   459        | aux1    | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 101    | ETH   |
   460        | aux1    | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 3      | ETH   |
   461  
   462  # For axu1 -
   463  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
   464  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
   465  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
   466  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.1 * 1002 = 101 (rounded up to nearest whole value)
   467  
   468      Then the market data for the market "ETH/DEC21" should be:
   469        | mark price | last traded price | trading mode            |
   470        | 1002       | 1002              | TRADING_MODE_CONTINUOUS |
   471      And the following trades should be executed:
   472        | buyer   | price | size | seller |
   473        | trader3 | 1002  | 1    | aux1   |
   474  
   475    Scenario: S007, Testing fees to confirm fees are collected first and then margin (0029-FEES-002, 0029-FEES-008)
   476      And the markets:
   477        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   478        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
   479  
   480      Given the parties deposit on asset's general account the following amount:
   481        | party   | asset | amount    |
   482        | aux1    | ETH   | 100000000 |
   483        | aux2    | ETH   | 100000000 |
   484        | trader3 | ETH   | 10000000  |
   485        | trader4 | ETH   | 214       |
   486        | lpprov  | ETH   | 100000000 |
   487  
   488      When the parties submit the following liquidity provision:
   489        | id  | party  | market id | commitment amount | fee | lp type    |
   490        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   491        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
   492  
   493      And the parties place the following pegged iceberg orders:
   494        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   495        | lpprov | ETH/DEC21 | 50        | 1                    | buy  | BID              | 50     | 10     |
   496        | lpprov | ETH/DEC21 | 50        | 1                    | sell | ASK              | 50     | 10     |
   497  
   498      Then the parties place the following orders:
   499        | party | market id | side | volume | price | resulting trades | type       | tif     |
   500        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   501        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   502        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   503        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   504  
   505      Then the opening auction period ends for market "ETH/DEC21"
   506      And the market data for the market "ETH/DEC21" should be:
   507        | mark price | trading mode            |
   508        | 1000       | TRADING_MODE_CONTINUOUS |
   509  
   510      When the parties place the following orders with ticks:
   511        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   512        | trader3 | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | trader3-buy-1  |
   513        | trader4 | ETH/DEC21 | sell | 1      | 1002  | 1                | TYPE_LIMIT | TIF_GTC | trader4-sell-2 |
   514  
   515      And the following transfers should happen:
   516        | from    | to      | from account            | to account                       | market id | amount | asset |
   517        | trader4 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   518        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 85 | ETH |
   519        | trader4 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 3      | ETH   |
   520        | market  | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   521  #trader4 got closed out after paying liquidity fee
   522      Then the parties should have the following margin levels:
   523        | party   | market id | maintenance | search | initial | release |
   524        | trader4 | ETH/DEC21 | 0 | 0 | 0 | 0 |
   525  
   526    Scenario: S008, Testing fees in continuous trading when insufficient balance in their general and margin account with LP, then the trade does not execute (0029-FEES-007,0029-FEES-008)
   527      And the markets:
   528        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
   529        | ETH/DEC21 | ETH        | ETH   | simple-risk-model-1 | default-margin-calculator | 2                | fees-config-1 | price-monitoring | default-eth-for-future | 1e0                    | 0                         | default-futures |
   530  
   531      Given the average block duration is "1"
   532  
   533      Given the parties deposit on asset's general account the following amount:
   534        | party   | asset | amount    |
   535        | aux1    | ETH   | 100000000 |
   536        | aux2    | ETH   | 100000000 |
   537        | trader3 | ETH   | 10000000  |
   538        | trader4 | ETH   | 189       |
   539  
   540      When the parties submit the following liquidity provision:
   541        | id  | party | market id | commitment amount | fee | lp type    |
   542        | lp1 | aux1  | ETH/DEC21 | 9000              | 0.1 | submission |
   543        | lp1 | aux1  | ETH/DEC21 | 9000              | 0.1 | amendment  |
   544      When the parties place the following orders:
   545        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   546        | aux1  | ETH/DEC21 | buy  | 1      | 910   | 0                | TYPE_LIMIT | TIF_GTC | peg-1     |
   547        | aux1  | ETH/DEC21 | sell | 10     | 1090  | 0                | TYPE_LIMIT | TIF_GTC | peg-2     |
   548  
   549      Then the parties place the following orders:
   550        | party | market id | side | volume | price | resulting trades | type       | tif     |
   551        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   552        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   553        | aux1  | ETH/DEC21 | buy  | 10     | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   554        | aux2  | ETH/DEC21 | sell | 10     | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   555  
   556      Then the opening auction period ends for market "ETH/DEC21"
   557      And the market data for the market "ETH/DEC21" should be:
   558        | mark price | trading mode            |
   559        | 1000       | TRADING_MODE_CONTINUOUS |
   560  
   561      And the order book should have the following volumes for market "ETH/DEC21":
   562        | side | price | volume |
   563        | buy  | 910   | 1      |
   564        | buy  | 920   | 10     |
   565        | sell | 1080  | 10     |
   566        | sell | 1090  | 10     |
   567  
   568      When the parties place the following orders with ticks:
   569        | party   | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   570        | trader3 | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | trader3-buy-1  |
   571        | trader4 | ETH/DEC21 | sell | 1      | 1002  | 1                | TYPE_LIMIT | TIF_GTC | trader4-sell-2 |
   572  
   573      Then the market data for the market "ETH/DEC21" should be:
   574        | mark price | trading mode            |
   575        | 1002       | TRADING_MODE_CONTINUOUS |
   576  
   577      Then the following trades should be executed:
   578        | buyer   | price | size | seller  |
   579        | trader3 | 1002  | 1    | trader4 |
   580  
   581      And the following transfers should happen:
   582        | from    | to      | from account            | to account                       | market id | amount | asset |
   583        | trader4 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   584        | trader4 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 3      | ETH   |
   585        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 60 | ETH |
   586        | trader4 | market | ACCOUNT_TYPE_MARGIN  | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 41 | ETH |
   587        | market  | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   588  
   589      Then the parties should have the following margin levels:
   590        | party   | market id | maintenance | search | initial | release |
   591        | trader4 | ETH/DEC21 | 0           | 0      | 0       | 0       |
   592  
   593      And the liquidity fee factor should be "0.1" for the market "ETH/DEC21"
   594      And the accumulated liquidity fees should be "171" for the market "ETH/DEC21"
   595  
   596      When the network moves ahead "11" blocks
   597  
   598      And the following transfers should happen:
   599        | from   | to   | from account                | to account           | market id | amount | asset |
   600        | market | aux1 | ACCOUNT_TYPE_FEES_LIQUIDITY | ACCOUNT_TYPE_LP_LIQUIDITY_FEES | ETH/DEC21 | 171 | ETH |
   601  
   602    Scenario:S009, Testing fees in auctions session with each side of a trade debited 1/2 IF & LP (0029-FEES-006, 0029-FEES-008)
   603  
   604      And the markets:
   605        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
   606        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25                   | 0                         | SLA        |
   607  
   608      # setup accounts
   609      When the parties deposit on asset's general account the following amount:
   610        | party    | asset | amount    |
   611        | aux1     | ETH   | 100000000 |
   612        | aux2     | ETH   | 100000000 |
   613        | trader3a | ETH   | 10000     |
   614        | trader4  | ETH   | 10000     |
   615  
   616      Then the parties place the following orders:
   617        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   618        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
   619        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   620        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   621        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   622  
   623      Given the parties submit the following liquidity provision:
   624        | id  | party | market id | commitment amount | fee   | lp type    |
   625        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
   626        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | amendment  |
   627      And the parties place the following pegged iceberg orders:
   628        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   629        | aux1  | ETH/DEC21 | 50        | 1                    | buy  | BID              | 50     | 10     |
   630        | aux1  | ETH/DEC21 | 50        | 1                    | sell | ASK              | 50     | 10     |
   631  
   632      Then the opening auction period ends for market "ETH/DEC21"
   633      And the market data for the market "ETH/DEC21" should be:
   634        | mark price | trading mode            | target stake | supplied stake |
   635        | 1002       | TRADING_MODE_CONTINUOUS | 200          | 200            |
   636      Then the following trades should be executed:
   637        | buyer    | price | size | seller  |
   638        | trader3a | 1002  | 1    | trader4 |
   639  
   640  #Scenario:S010, Triggering Liquidity auction (0029-FEES-006)
   641  
   642      When the parties place the following orders with ticks:
   643        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   644        | trader3a | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   645        | trader4  | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   646  
   647      Then the following trades should be executed:
   648        | buyer    | price | size | seller  |
   649        | trader3a | 1002  | 3    | trader4 |
   650  
   651      # fees during normal trading
   652      And the following transfers should happen:
   653        | from    | to     | from account         | to account                       | market id | amount | asset |
   654        | trader4 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 7      | ETH   |
   655        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 4      | ETH   |
   656  
   657      # now place orders during auction
   658      When the parties place the following orders with ticks:
   659        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   660        | trader3a | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   661        | trader4  | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   662  
   663      Given the parties submit the following liquidity provision:
   664        | id  | party | market id | commitment amount | fee   | lp type   |
   665        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   666        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   667      And the parties place the following pegged iceberg orders:
   668        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   669        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   670        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   671  
   672      # leave auction
   673      When the network moves ahead "2" blocks
   674      Then the following trades should be executed:
   675        | buyer    | price | size | seller  |
   676        | trader3a | 1002  | 3    | trader4 |
   677  
   678      # For trader3a & 4- Sharing IF and LP
   679      # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 3 * 1002= 3006
   680      # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 3006 = 6.012 = 7(rounded up)
   681      # maker_fee =  0 in auction
   682      # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 3006 = 3.006 = 4 (rounded up)
   683      And the following transfers should happen:
   684        | from     | to     | from account         | to account                       | market id | amount | asset |
   685        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 7      | ETH   |
   686        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 4      | ETH   |
   687  
   688      And the market data for the market "ETH/DEC21" should be:
   689        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   690        | 1002       | TRADING_MODE_CONTINUOUS | 1       | 903       | 1101      | 1402         | 10000          | 7             |
   691  
   692      Then the parties place the following orders with ticks:
   693        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   694        | trader3a | ETH/DEC21 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   695        | trader4  | ETH/DEC21 | sell | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   696  
   697      Then the market data for the market "ETH/DEC21" should be:
   698        | trading mode                    | auction trigger       |
   699        | TRADING_MODE_MONITORING_AUCTION | AUCTION_TRIGGER_PRICE |
   700  
   701      Then the network moves ahead "301" blocks
   702  
   703      Then the following trades should be executed:
   704        | buyer    | price | size | seller  |
   705        | trader3a | 900   | 1    | trader4 |
   706  
   707  # For trader3a & 4- Sharing IF and LP
   708  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 1 * 900 = 900
   709  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 900 = 1.800 = 2(rounded up)
   710  # maker_fee =  0 in auction
   711  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 900 = 0.900 = 1 (rounded up)
   712  
   713      And the following transfers should happen:
   714        | from     | to     | from account         | to account                       | market id | amount | asset |
   715        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1      | ETH   |
   716        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
   717        | trader3a |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1      | ETH   |
   718        | trader3a | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
   719  
   720      Then the market data for the market "ETH/DEC21" should be:
   721        | trading mode            | auction trigger             |
   722        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
   723  
   724    Scenario: S011, Testing fees in Liquidity auction session trading with insufficient balance in their general account but margin covers the fees (0029-FEES-006)
   725  
   726      Given the average block duration is "1"
   727  
   728      And the markets:
   729        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
   730        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 1e0                    | 0                         | SLA        |
   731  
   732      # setup accounts
   733      When the parties deposit on asset's general account the following amount:
   734        | party    | asset | amount    |
   735        | aux1     | ETH   | 100000000 |
   736        | aux2     | ETH   | 100000000 |
   737        | trader3a | ETH   | 5000      |
   738        | trader4  | ETH   | 5261      |
   739        | tradera3 | ETH   | 100000000 |
   740        | tradera4 | ETH   | 100000000 |
   741  
   742      Then the parties place the following orders:
   743        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   744        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
   745        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   746        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   747        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   748  
   749      Given the parties submit the following liquidity provision:
   750        | id  | party | market id | commitment amount | fee   | lp type    |
   751        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
   752        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | amendment  |
   753      And the parties place the following pegged iceberg orders:
   754        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   755        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   756        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   757  
   758      And the opening auction period ends for market "ETH/DEC21"
   759  
   760  # Scenario: S012, Triggering Liquidity auction (0029-FEES-006)
   761  
   762      When the parties place the following orders with ticks:
   763        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   764        | tradera3 | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   765        | tradera4 | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   766      Then the following trades should be executed:
   767        | buyer    | price | size | seller   |
   768        | tradera3 | 1002  | 3    | tradera4 |
   769  
   770      When the network moves ahead "1" blocks
   771  
   772      When the parties place the following orders with ticks:
   773        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   774        | trader3a | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   775        | trader4  | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   776  
   777      And the parties submit the following liquidity provision:
   778        | id  | party | market id | commitment amount | fee   | lp type   |
   779        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   780        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   781      And the parties place the following pegged iceberg orders:
   782        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   783        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   784        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   785  
   786      Then the network moves ahead "2" blocks
   787  
   788  
   789  # For trader3a & 4- Sharing IF and LP
   790  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 3 * 1002= 3006
   791  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 3006 = 6.012 = 7(rounded up)
   792  # maker_fee =  0 in auction
   793  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 3006 = 3.006 = 4 (rounded up)
   794  
   795      And the following transfers should happen:
   796        | from     | to     | from account         | to account                       | market id | amount | asset |
   797        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 7      | ETH   |
   798        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 4      | ETH   |
   799  
   800      Then the parties should have the following margin levels:
   801        | party   | market id | maintenance | initial |
   802        | trader4 | ETH/DEC21 | 4409        | 5290    |
   803  
   804      Then the parties should have the following account balances:
   805        | party    | asset | market id | margin | general |
   806        | trader3a | ETH   | ETH/DEC21 | 5016   | 0       |
   807        | trader4  | ETH   | ETH/DEC21 | 5234   | 0       |
   808  
   809      Then the market data for the market "ETH/DEC21" should be:
   810        | trading mode            | auction trigger             |
   811        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
   812  
   813    Scenario: S013, Testing fees in Price auction session trading with insufficient balance in their general account but margin covers the fees (0029-FEES-008)
   814  
   815      And the average block duration is "1"
   816  
   817      And the markets:
   818        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
   819        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 1e0                    | 0                         | SLA        |
   820  
   821      # setup accounts
   822      When the parties deposit on asset's general account the following amount:
   823        | party    | asset | amount    |
   824        | aux1     | ETH   | 100000000 |
   825        | aux2     | ETH   | 100000000 |
   826        | trader3a | ETH   | 5000      |
   827        | trader4  | ETH   | 2656      |
   828  
   829      Then the parties place the following orders:
   830        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   831        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
   832        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   833        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   834        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   835  
   836      Given the parties submit the following liquidity provision:
   837        | id  | party | market id | commitment amount | fee   | lp type    |
   838        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
   839        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | amendment  |
   840      And the parties place the following pegged iceberg orders:
   841        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   842        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   843        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   844      Then the opening auction period ends for market "ETH/DEC21"
   845  
   846      Given the parties submit the following liquidity provision:
   847        | id  | party | market id | commitment amount | fee   | lp type   |
   848        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   849        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
   850      And the parties place the following pegged iceberg orders:
   851        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   852        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   853        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   854      And the market data for the market "ETH/DEC21" should be:
   855        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
   856        | 1002       | TRADING_MODE_CONTINUOUS | 1       | 903       | 1101      | 200          | 10000          | 1             |
   857  
   858      Then the parties place the following orders with ticks:
   859        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   860        | trader3a | ETH/DEC21 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   861        | trader4  | ETH/DEC21 | sell | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
   862  
   863      Then the market data for the market "ETH/DEC21" should be:
   864        | trading mode                    | auction trigger       |
   865        | TRADING_MODE_MONITORING_AUCTION | AUCTION_TRIGGER_PRICE |
   866  
   867      Then the network moves ahead "301" blocks
   868  
   869      Then the following trades should be executed:
   870        | buyer    | price | size | seller  |
   871        | trader3a | 900   | 1    | trader4 |
   872  
   873  # For trader3a & 4- Sharing IF and LP
   874  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 1 * 900 = 900
   875  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 900 = 1.800 = 2(rounded up)
   876  # maker_fee =  0 in auction
   877  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 900 = 0.900 = 1 (rounded up)
   878  
   879      And the following transfers should happen:
   880        | from     | to     | from account         | to account                       | market id | amount | asset |
   881        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1      | ETH   |
   882        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
   883        | trader3a |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1      | ETH   |
   884        | trader3a | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
   885  
   886      Then the market data for the market "ETH/DEC21" should be:
   887        | trading mode            | auction trigger             |
   888        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
   889  
   890    @Liquidation
   891    Scenario: S014, Testing fees in Liquidity auction session trading with insufficient balance in their general and margin account, then the trade still goes ahead, (0029-FEES-008)
   892  
   893      Given the average block duration is "1"
   894  
   895      And the fees configuration named "fees-config-1":
   896        | maker fee | infrastructure fee |
   897        | 0.005 | 2 |
   898  
   899      And the markets:
   900        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
   901        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.996                  | 0                         | SLA        |
   902  
   903      # setup accounts
   904      When the parties deposit on asset's general account the following amount:
   905        | party    | asset | amount    |
   906        | aux1     | ETH   | 100000000 |
   907        | aux2     | ETH   | 100000000 |
   908        | trader3a | ETH   | 5273      |
   909        | trader4  | ETH   | 6032      |
   910        | trader5  | ETH   | 100000000 |
   911        | trader6  | ETH   | 100000000 |
   912  
   913      Then the parties place the following orders:
   914        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   915        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
   916        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
   917        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   918        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   919  
   920      Given the parties submit the following liquidity provision:
   921        | id  | party | market id | commitment amount | fee   | lp type    |
   922        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
   923      And the parties place the following pegged iceberg orders:
   924        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   925        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
   926        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
   927  
   928      When the opening auction period ends for market "ETH/DEC21"
   929  
   930  #Scenario: S015, Triggering Liquidity auction (0029-FEES-008)
   931  
   932      Then the parties place the following orders:
   933        | party   | market id | side | volume | price | resulting trades | type       | tif     |
   934        | trader5 | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   935        | trader6 | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
   936      And the following trades should be executed:
   937        | buyer   | price | size | seller  |
   938        | trader5 | 1002  | 3    | trader6 |
   939  
   940      When the network moves ahead "1" blocks
   941      And the parties submit the following liquidity provision:
   942        | id  | party | market id | commitment amount | fee   | lp type   |
   943        | lp1 | aux1  | ETH/DEC21 | 20000             | 0.001 | amendment |
   944      And the parties place the following orders:
   945        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
   946        | trader3a | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | t3a-buy   |
   947        | trader4  | ETH/DEC21 | sell | 3      | 1002  | 1                | TYPE_LIMIT | TIF_GTC | t4-sell   |
   948  
   949      When the network moves ahead "2" blocks
   950      Then the market data for the market "ETH/DEC21" should be:
   951        | trading mode            | auction trigger             |
   952        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
   953  
   954      And the following trades should be executed:
   955        | buyer    | price | size | seller  |
   956        | trader3a | 1002  | 3    | trader4 |
   957  
   958  # For trader3a & 4- Sharing IF and LP
   959  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 3 * 1002= 3006
   960  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 2 * 3006
   961  # maker_fee =  0 in auction
   962  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 3006 = 3.006 = 4 (rounded up)
   963  
   964      And the following transfers should happen:
   965        | from    | to     | from account         | to account                       | market id | amount | asset |
   966        | trader4 | market | ACCOUNT_TYPE_MARGIN  | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 4      | ETH   |
   967        | trader4 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 4338   | ETH   |
   968  
   969      Then the parties should have the following margin levels:
   970        | party   | market id | maintenance | initial |
   971        | trader4 | ETH/DEC21 | 0           | 0       |
   972  
   973      Then the parties should have the following account balances:
   974        | party    | asset | market id | margin | general |
   975        | trader3a | ETH   | ETH/DEC21 | 5289   | 0       |
   976        | trader4  | ETH   | ETH/DEC21 | 0      | 0       |
   977  
   978      Then the market data for the market "ETH/DEC21" should be:
   979        | trading mode            | auction trigger             |
   980        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
   981  
   982    @Liquidation
   983    Scenario:S016,  Testing fees in Price auction session trading with insufficient balance in their general and margin account, then the trade still goes ahead (0029-FEES-008)
   984  
   985      And the average block duration is "1"
   986  
   987      And the fees configuration named "fees-config-1":
   988        | maker fee | infrastructure fee |
   989        | 0.005 | 2 |
   990  
   991      And the markets:
   992        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
   993        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future |  0.5                   | 0                         | SLA        |
   994  
   995      # setup accounts
   996      When the parties deposit on asset's general account the following amount:
   997        | party    | asset | amount    |
   998        | aux1     | ETH   | 100000000 |
   999        | aux2     | ETH   | 100000000 |
  1000        | trader3a | ETH   | 3500      |
  1001        | trader4  | ETH   | 5500      |
  1002  
  1003      Then the parties place the following orders:
  1004        | party    | market id | side | volume | price | resulting trades | type       | tif     |
  1005        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
  1006        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
  1007        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
  1008        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
  1009  
  1010      Given the parties submit the following liquidity provision:
  1011        | id  | party | market id | commitment amount | fee   | lp type    |
  1012        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
  1013        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | amendment  |
  1014      And the parties place the following pegged iceberg orders:
  1015        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1016        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 2      | 10     |
  1017        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 2      | 10     |
  1018      Then the opening auction period ends for market "ETH/DEC21"
  1019  
  1020      Given the parties submit the following liquidity provision:
  1021        | id  | party | market id | commitment amount | fee   | lp type   |
  1022        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
  1023        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
  1024      And the parties place the following pegged iceberg orders:
  1025        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1026        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
  1027        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
  1028  
  1029      And the market data for the market "ETH/DEC21" should be:
  1030        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
  1031        | 1002       | TRADING_MODE_CONTINUOUS | 1       | 903       | 1101      | 200          | 10000          | 1             |
  1032  
  1033      Then the parties place the following orders:
  1034        | party    | market id | side | volume | price | resulting trades | type       | tif     |
  1035        | trader3a | ETH/DEC21 | buy  | 2      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
  1036        | trader4  | ETH/DEC21 | sell | 2      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
  1037  
  1038      Then the market data for the market "ETH/DEC21" should be:
  1039        | trading mode                    | auction trigger       |
  1040        | TRADING_MODE_MONITORING_AUCTION | AUCTION_TRIGGER_PRICE |
  1041  
  1042      # Leave auction + close network position
  1043      Then the network moves ahead "301" blocks
  1044  
  1045      Then debug trades
  1046      Then the following trades should be executed:
  1047        | buyer    | price | size | seller   |
  1048        | trader3a | 1002  | 1    | trader4  |
  1049        | trader3a | 900   | 2    | trader4  |
  1050        | network  | 900   | 3    | trader3a |
  1051  
  1052  # For trader3a & 4- Sharing IF and LP
  1053  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 900 = 1800
  1054  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 2 * 900
  1055  # maker_fee =  0 in auction
  1056  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 1800 = 1.8 = 2/2 = 1
  1057  
  1058      And the following transfers should happen:
  1059        | from     | to     | from account         | to account                       | market id | amount | asset |
  1060        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1800   | ETH   |
  1061        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
  1062        | trader3a |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 1800   | ETH   |
  1063        | trader3a | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 1      | ETH   |
  1064  
  1065      Then the market data for the market "ETH/DEC21" should be:
  1066        | trading mode            | auction trigger             |
  1067        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
  1068  
  1069    Scenario:S017, Testing fees in Price auction session trading with insufficient balance in their general and margin account, then the trade does not go ahead (0029-FEES-008)
  1070  
  1071      And the average block duration is "1"
  1072  
  1073      And the fees configuration named "fees-config-1":
  1074        | maker fee | infrastructure fee |
  1075        | 0.005 | 2 |
  1076  
  1077      And the markets:
  1078        | id        | quote name | asset | liquidity monitoring | risk model          | margin calculator         | auction duration | fees          | price monitoring   | data source config     | linear slippage factor | quadratic slippage factor | sla params |
  1079        | ETH/DEC21 | ETH        | ETH   | lqm-params           | simple-risk-model-1 | default-margin-calculator | 1                | fees-config-1 | price-monitoring-1 | default-eth-for-future | 1e0                    | 0                         | SLA        |
  1080  
  1081      # setup accounts
  1082      When the parties deposit on asset's general account the following amount:
  1083        | party    | asset | amount    |
  1084        | aux1     | ETH   | 100000000 |
  1085        | aux2     | ETH   | 100000000 |
  1086        | trader3a | ETH   | 5000      |
  1087        | trader4  | ETH   | 7261      |
  1088  # If the trader4 balance is changed to from 7261 to 7465 then the trade goes ahead as the account balance goes above maintenance level after paying fees.
  1089  # | trader4  | ETH   | 7465       |
  1090  
  1091      Then the parties place the following orders:
  1092        | party    | market id | side | volume | price | resulting trades | type       | tif     |
  1093        | aux1     | ETH/DEC21 | buy  | 1      | 500   | 0                | TYPE_LIMIT | TIF_GTC |
  1094        | aux2     | ETH/DEC21 | sell | 1      | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
  1095        | trader3a | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
  1096        | trader4  | ETH/DEC21 | sell | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
  1097  
  1098      Given the parties submit the following liquidity provision:
  1099        | id  | party | market id | commitment amount | fee   | lp type    |
  1100        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | submission |
  1101        | lp1 | aux1  | ETH/DEC21 | 200               | 0.001 | amendment  |
  1102      And the parties place the following pegged iceberg orders:
  1103        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1104        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 1      | 10     |
  1105        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 1      | 10     |
  1106      Then the opening auction period ends for market "ETH/DEC21"
  1107  
  1108      Given the parties submit the following liquidity provision:
  1109        | id  | party | market id | commitment amount | fee   | lp type   |
  1110        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
  1111        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment |
  1112      And the parties place the following pegged iceberg orders:
  1113        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1114        | aux1  | ETH/DEC21 | 2         | 1                    | buy  | BID              | 2      | 10     |
  1115        | aux1  | ETH/DEC21 | 2         | 1                    | sell | ASK              | 2      | 10     |
  1116  
  1117      And the market data for the market "ETH/DEC21" should be:
  1118        | mark price | trading mode            | horizon | min bound | max bound | target stake | supplied stake | open interest |
  1119        | 1002       | TRADING_MODE_CONTINUOUS | 1       | 903       | 1101      | 200          | 10000          | 1             |
  1120  
  1121      Then the parties place the following orders:
  1122        | party    | market id | side | volume | price | resulting trades | type       | tif     |
  1123        | trader3a | ETH/DEC21 | buy  | 3      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
  1124        | trader4  | ETH/DEC21 | sell | 3      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
  1125  
  1126      Then the market data for the market "ETH/DEC21" should be:
  1127        | trading mode                    | auction trigger       |
  1128        | TRADING_MODE_MONITORING_AUCTION | AUCTION_TRIGGER_PRICE |
  1129  
  1130      Then the network moves ahead "301" blocks
  1131  
  1132      Then the following trades should be executed:
  1133        | buyer    | price | size | seller  |
  1134        | trader3a | 900   | 3    | trader4 |
  1135  
  1136  # For trader3a & 4- Sharing IF and LP
  1137  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 3 * 900 = 2700
  1138  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 2 * 2700
  1139  # maker_fee =  0 in auction
  1140  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 2700 = 2.7 = 3/2 = 1.5 = 2 (rounded up)
  1141  
  1142      And the following transfers should happen:
  1143        | from     | to     | from account         | to account                       | market id | amount | asset |
  1144        | trader4  |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 2700   | ETH   |
  1145        | trader4  | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 2      | ETH   |
  1146        | trader3a |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 2700   | ETH   |
  1147        | trader3a | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 2      | ETH   |
  1148  
  1149      Then the parties should have the following margin levels:
  1150        | party   | market id | maintenance | initial |
  1151        | trader4 | ETH/DEC21 | 3960        | 4752    |
  1152  
  1153      Then the parties should have the following account balances:
  1154        | party    | asset | market id | margin | general |
  1155        | trader3a | ETH   | ETH/DEC21 | 0      | 0       |
  1156        | trader4  | ETH   | ETH/DEC21 | 4661   | 0       |
  1157  
  1158      Then the market data for the market "ETH/DEC21" should be:
  1159        | trading mode            | auction trigger             |
  1160        | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED |
  1161  
  1162    @now @Liquidation
  1163    Scenario: S018, Testing fees in continuous trading during position resolution (0029-FEES-001)
  1164  
  1165      Given the fees configuration named "fees-config-1":
  1166        | maker fee | infrastructure fee |
  1167        | 0.005     | 0.002              |
  1168  
  1169      And the markets:
  1170        | id        | quote name | asset | risk model                  | margin calculator                  | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
  1171        | ETH/DEC21 | ETH        | ETH   | default-simple-risk-model-2 | default-overkill-margin-calculator | 2                | fees-config-1 | default-none     | default-eth-for-future | 0.55                    | 0                         | default-futures |
  1172  
  1173      And the parties deposit on asset's general account the following amount:
  1174        | party    | asset | amount        |
  1175        | aux1     | ETH   | 1000000000000 |
  1176        | aux2     | ETH   | 1000000000000 |
  1177        | trader3a | ETH   | 10000         |
  1178        | trader3b | ETH   | 30000         |
  1179  
  1180      Then the parties place the following orders:
  1181        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1182        | aux1  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1   |
  1183        | aux2  | ETH/DEC21 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1   |
  1184        | aux1  | ETH/DEC21 | sell | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-2   |
  1185        | aux2  | ETH/DEC21 | buy  | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-2   |
  1186  
  1187      Then the opening auction period ends for market "ETH/DEC21"
  1188      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
  1189      And the mark price should be "180" for the market "ETH/DEC21"
  1190  
  1191      When the parties place the following orders with ticks:
  1192        | party | market id | side | volume | price | resulting trades | type       | tif     | reference       |
  1193        | aux1  | ETH/DEC21 | sell | 150    | 200   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
  1194        | aux2  | ETH/DEC21 | buy  | 50     | 190   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
  1195        | aux2  | ETH/DEC21 | buy  | 350    | 180   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2  |
  1196  
  1197      When the parties place the following orders with ticks:
  1198        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1199        | trader3a | ETH/DEC21 | sell | 100    | 180   | 2                | TYPE_LIMIT | TIF_GTC | ref-1     |
  1200        | trader3b | ETH/DEC21 | sell | 300    | 180   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
  1201      And the network moves ahead "1" blocks
  1202  
  1203      Then the following trades should be executed:
  1204        | buyer | price | size | seller   |
  1205        | aux2  | 190   | 50   | trader3a |
  1206        | aux2  | 180   | 50   | trader3a |
  1207        | aux2  | 180   | 300  | trader3b |
  1208  
  1209      Then the parties should have the following margin levels:
  1210        | party    | market id | maintenance |
  1211        | trader3b | ETH/DEC21 | 0           |
  1212        | trader3a | ETH/DEC21 | 9900        |
  1213  
  1214      When the parties place the following orders with ticks:
  1215        | party | market id | side | volume | price | resulting trades | type       | tif     | reference       |
  1216        | aux1  | ETH/DEC21 | sell | 500    | 350   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-2 |
  1217  
  1218      And the parties place the following orders with ticks:
  1219        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1220        | aux2  | ETH/DEC21 | buy  | 1      | 300   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
  1221        | aux1  | ETH/DEC21 | sell | 1      | 300   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
  1222  
  1223      And the mark price should be "300" for the market "ETH/DEC21"
  1224  
  1225      Then the parties should have the following profit and loss:
  1226        | party    | volume | unrealised pnl | realised pnl |
  1227        | trader3a | 0      | 0              | -9870        |
  1228        | trader3b | 0      | 0              | -29622       |
  1229  
  1230  # trade_value_for_fee_purposes for party 3a = size_of_trade * price_of_trade = 50 *190 = 9500 And 50 * 180 = 9000
  1231  # maker_fee for party 3a = fee_factor[maker] * trade_value_for_fee_purposes = 0.005 * 9500 = 47.5 = 48 (rounded up to nearest whole value) And 0.005 * 9000 = 45
  1232  # infrastructure_fee for party 3a = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 9500 = 19 And 0.002 * 9000 = 18 + 19 = 37
  1233  # trade_value_for_fee_purposes for party 3b = size_of_trade * price_of_trade = 300 *180 = 54000
  1234  # maker_fee for party 3b =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 54000 = 270
  1235  # infrastructure_fee for party 3b = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 54000 = 108
  1236  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0
  1237  
  1238      And the following transfers should happen:
  1239        | from     | to     | from account            | to account                       | market id | amount | asset |
  1240        | trader3a | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 48     | ETH   |
  1241        | trader3a | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 45     | ETH   |
  1242        | trader3a |        | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 37     | ETH   |
  1243        | trader3b | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 270    | ETH   |
  1244        | trader3b |        | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 108    | ETH   |
  1245        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 48     | ETH   |
  1246        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 45     | ETH   |
  1247        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 270    | ETH   |
  1248  
  1249      Then the parties should have the following account balances:
  1250        | party    | asset | market id | margin | general |
  1251        | trader3a | ETH   | ETH/DEC21 | 0      | 0       |
  1252        | trader3b | ETH   | ETH/DEC21 | 0      | 0       |
  1253  
  1254      And the insurance pool balance should be "0" for the market "ETH/DEC21"
  1255  
  1256    @Liquidation
  1257    Scenario: S019, Testing fees in continuous trading during position resolution with insufficient balance in their general and margin account, partial or full fees does not get paid (0029-FEES-008)
  1258  
  1259      Given the fees configuration named "fees-config-1":
  1260        | maker fee | infrastructure fee |
  1261        | 0.005     | 0.003              |
  1262  
  1263      And the markets:
  1264        | id        | quote name | asset | risk model                  | margin calculator                  | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
  1265        | ETH/DEC21 | ETH        | ETH   | default-simple-risk-model-2 | default-overkill-margin-calculator | 2                | fees-config-1 | default-none     | default-eth-for-future | 0.55                   | 0                         | default-futures |
  1266  
  1267      And the parties deposit on asset's general account the following amount:
  1268        | party    | asset | amount        |
  1269        | aux1     | ETH   | 1000000000000 |
  1270        | aux2     | ETH   | 1000000000000 |
  1271        | trader3a | ETH   | 10000         |
  1272        | trader3b | ETH   | 30000         |
  1273  
  1274      Then the parties place the following orders:
  1275        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1276        | aux1  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | aux-s-1   |
  1277        | aux2  | ETH/DEC21 | buy  | 1      | 1     | 0                | TYPE_LIMIT | TIF_GTC | aux-b-1   |
  1278        | aux1  | ETH/DEC21 | sell | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-s-2   |
  1279        | aux2  | ETH/DEC21 | buy  | 10     | 180   | 0                | TYPE_LIMIT | TIF_GTC | aux-b-2   |
  1280  
  1281      Then the opening auction period ends for market "ETH/DEC21"
  1282      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21"
  1283      And the mark price should be "180" for the market "ETH/DEC21"
  1284  
  1285      When the parties place the following orders with ticks:
  1286        | party | market id | side | volume | price | resulting trades | type       | tif     | reference       |
  1287        | aux1  | ETH/DEC21 | sell | 150    | 200   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
  1288        | aux2  | ETH/DEC21 | buy  | 50     | 190   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
  1289        | aux2  | ETH/DEC21 | buy  | 350    | 180   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-2  |
  1290  
  1291      When the parties place the following orders with ticks:
  1292        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1293        | trader3a | ETH/DEC21 | sell | 100    | 180   | 2                | TYPE_LIMIT | TIF_GTC | ref-1     |
  1294        | trader3b | ETH/DEC21 | sell | 300    | 180   | 1                | TYPE_LIMIT | TIF_GTC | ref-2     |
  1295      And the network moves ahead "1" blocks
  1296  
  1297      Then the following trades should be executed:
  1298        | buyer | price | size | seller   |
  1299        | aux2  | 190   | 50   | trader3a |
  1300        | aux2  | 180   | 50   | trader3a |
  1301        | aux2  | 180   | 300  | trader3b |
  1302  
  1303      Then the parties should have the following margin levels:
  1304        | party    | market id | maintenance |
  1305        | trader3a | ETH/DEC21 | 9900        |
  1306        | trader3b | ETH/DEC21 | 0           |
  1307  
  1308      When the parties place the following orders with ticks:
  1309        | party | market id | side | volume | price | resulting trades | type       | tif     | reference       |
  1310        | aux1  | ETH/DEC21 | sell | 500    | 350   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-2 |
  1311  
  1312      And the parties place the following orders with ticks:
  1313        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
  1314        | aux2  | ETH/DEC21 | buy  | 1      | 300   | 0                | TYPE_LIMIT | TIF_GTC | ref-2     |
  1315        | aux1  | ETH/DEC21 | sell | 1      | 300   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
  1316  
  1317      And the mark price should be "300" for the market "ETH/DEC21"
  1318  
  1319      Then the parties should have the following profit and loss:
  1320        | party    | volume | unrealised pnl | realised pnl |
  1321        | trader3a | 0      | 0              | -9851        |
  1322        | trader3b | 0      | 0              | -29568       |
  1323  
  1324  # trade_value_for_fee_purposes for party 3a = size_of_trade * price_of_trade = 50 *190 = 9500 And 50 * 180 = 9000
  1325  # maker_fee for party 3a = fee_factor[maker] * trade_value_for_fee_purposes = 0.005 * 9500 = 47.5 = 48 (rounded up to nearest whole value) And 0.005 * 9000 = 45
  1326  # infrastructure_fee for party 3a = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 9500 = 19 And 0.002 * 9000 = 18 + 19 = 37
  1327  # trade_value_for_fee_purposes for party 3b = size_of_trade * price_of_trade = 300 *180 = 54000
  1328  # maker_fee for party 3b =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 54000 = 270
  1329  # infrastructure_fee for party 3b = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 54000 = 108
  1330  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0
  1331  
  1332      And the following transfers should happen:
  1333        | from     | to     | from account            | to account                       | market id | amount | asset |
  1334        | trader3a | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 48     | ETH   |
  1335        | trader3a | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 45     | ETH   |
  1336        | trader3a |        | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 56     | ETH   |
  1337        | trader3b | market | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 270    | ETH   |
  1338        | trader3b |        | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC21 | 162    | ETH   |
  1339        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 48     | ETH   |
  1340        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 45     | ETH   |
  1341        | market   | aux2   | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 270    | ETH   |
  1342  
  1343      Then the parties should have the following account balances:
  1344        | party    | asset | market id | margin | general |
  1345        | trader3a | ETH   | ETH/DEC21 | 0      | 0       |
  1346        | trader3b | ETH   | ETH/DEC21 | 0      | 0       |
  1347  
  1348      And the insurance pool balance should be "0" for the market "ETH/DEC21"
  1349  
  1350    Scenario: S020, Testing fees in continuous trading with two pegged trades and one liquidity providers (0029-FEES-002)
  1351  
  1352      Given the average block duration is "1"
  1353      And the fees configuration named "fees-config-1":
  1354        | maker fee | infrastructure fee |
  1355        | 0.005 | 0.002 |
  1356  
  1357      And the markets:
  1358        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params |
  1359        | ETH/DEC21 | ETH        | ETH   | simple-risk-model-1 | default-margin-calculator | 2                | fees-config-1 | price-monitoring | default-eth-for-future | 0.1                    | 0                         | SLA        |
  1360  
  1361      # setup accounts
  1362      Given the parties deposit on asset's general account the following amount:
  1363        | party    | asset | amount    |
  1364        | aux1     | ETH   | 100000000 |
  1365        | aux2     | ETH   | 100000000 |
  1366        | trader3a | ETH   | 100000    |
  1367        | trader4  | ETH   | 100000    |
  1368  
  1369      Then the parties place the following orders:
  1370        | party | market id | side | volume | price | resulting trades | type       | tif     |
  1371        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
  1372        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
  1373        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
  1374        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
  1375  
  1376      Given the parties submit the following liquidity provision:
  1377        | id  | party | market id | commitment amount | fee   | lp type    |
  1378        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | submission |
  1379        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | amendment  |
  1380      And the parties place the following pegged iceberg orders:
  1381        | party | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1382        | aux1  | ETH/DEC21 | 10        | 1                    | buy  | MID              | 10     | 10     |
  1383        | aux1  | ETH/DEC21 | 10        | 1                    | sell | MID              | 10     | 10     |
  1384  
  1385      Then the opening auction period ends for market "ETH/DEC21"
  1386      And the market data for the market "ETH/DEC21" should be:
  1387        | mark price | trading mode            |
  1388        | 1000       | TRADING_MODE_CONTINUOUS |
  1389  
  1390      And the order book should have the following volumes for market "ETH/DEC21":
  1391        | side | price | volume |
  1392        | buy  | 920   | 1      |
  1393        | buy  | 990  | 10 |
  1394        | sell | 1010 | 10 |
  1395        | sell | 1080  | 1      |
  1396  
  1397      Then the parties place the following orders with ticks:
  1398        | party    | market id | side | volume | price | resulting trades | type       | tif     |
  1399        | trader3a | ETH/DEC21 | buy  | 10     | 990   | 0                | TYPE_LIMIT | TIF_GTC |
  1400  
  1401      And the market data for the market "ETH/DEC21" should be:
  1402        | mark price | trading mode            |
  1403        | 1000       | TRADING_MODE_CONTINUOUS |
  1404  
  1405      And the order book should have the following volumes for market "ETH/DEC21":
  1406        | side | price | volume |
  1407        | buy  | 920   | 1      |
  1408        | buy  | 990  | 10 |
  1409        | buy  | 1025 | 10 |
  1410        | sell | 1045 | 10 |
  1411        | sell | 1080  | 1      |
  1412  
  1413      Then the parties place the following orders with ticks:
  1414        | party   | market id | side | volume | price | resulting trades | type       | tif     |
  1415        | trader4 | ETH/DEC21 | sell | 30     | 990   | 2                | TYPE_LIMIT | TIF_GTC |
  1416  
  1417      Then the following trades should be executed:
  1418        | buyer    | price | size | seller  |
  1419        | trader3a | 990   | 10   | trader4 |
  1420        | aux1 | 1025 | 10 | trader4 |
  1421  
  1422      And the liquidity fee factor should be "0.001" for the market "ETH/DEC21"
  1423      And the accumulated liquidity fees should be "21" for the market "ETH/DEC21"
  1424  
  1425      Then the market data for the market "ETH/DEC21" should be:
  1426        | mark price | trading mode            |
  1427        | 990        | TRADING_MODE_CONTINUOUS |
  1428  
  1429  # For trader4 -
  1430  
  1431  # trade_value_for_fee_purposes with trader3a = size_of_trade * price_of_trade = 10 * 990 = 9900
  1432  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 9900 = 19.8 = 20 (rounded up to nearest whole value)
  1433  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 9900 = 49.5 = 50 (rounded up to nearest whole value)
  1434  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 9900 = 9.9 = 10 (rounded up to nearest whole value)
  1435  
  1436  # trade_value_for_fee_purposes with trader4 = size_of_trade * price_of_trade = 9 * 1025 = 9225
  1437  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 9255 = 18.45 = 19 (rounded up to nearest whole value)
  1438  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 9255 = 46.125 = 47 (rounded up to nearest whole value)
  1439  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 9255 = 9.225 = 10 (rounded up to nearest whole value)
  1440  
  1441      And the following transfers should happen:
  1442        | from    | to       | from account            | to account                       | market id | amount | asset |
  1443        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 50     | ETH   |
  1444        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC21 | 21 | ETH |
  1445        | trader4 |        | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 41 | ETH |
  1446        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 50     | ETH   |
  1447        | market | aux1 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL | ETH/DEC21 | 52 | ETH |
  1448  
  1449      # And the accumulated infrastructure fee should be "20" for the market "ETH/DEC21"
  1450      And the accumulated liquidity fees should be "21" for the market "ETH/DEC21"
  1451  
  1452      When the network moves ahead "11" blocks
  1453      And the following transfers should happen:
  1454        | from   | to   | from account                | to account                     | market id | amount | asset |
  1455        | market | aux1 | ACCOUNT_TYPE_FEES_LIQUIDITY | ACCOUNT_TYPE_LP_LIQUIDITY_FEES | ETH/DEC21 | 21     | ETH   |
  1456  
  1457    Scenario: S021, Testing fees when network parameters are changed (in continuous trading with one trade and no liquidity providers) (0029-FEES-002, 0029-FEES-009)
  1458  Description : Changing net params does change the fees being collected appropriately even if the market is already running
  1459  
  1460      Given the fees configuration named "fees-config-1":
  1461        | maker fee | infrastructure fee |
  1462        | 0.005 | 0.002 |
  1463  
  1464      And the markets:
  1465        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
  1466        | ETH/DEC21 | ETH | ETH | simple-risk-model-1 | default-margin-calculator | 2 | fees-config-1 | price-monitoring | default-eth-for-future | 0.1 | 0 | default-futures |
  1467      Given the parties deposit on asset's general account the following amount:
  1468        | party   | asset | amount    |
  1469        | aux1    | ETH   | 100000000 |
  1470        | aux2    | ETH   | 100000000 |
  1471        | trader3 | ETH   | 10000     |
  1472        | trader4 | ETH   | 10000     |
  1473        | lpprov  | ETH   | 100000000 |
  1474  
  1475      When the parties submit the following liquidity provision:
  1476        | id  | party  | market id | commitment amount | fee | lp type    |
  1477        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
  1478        | lp1 | lpprov | ETH/DEC21 | 90000000          | 0.1 | submission |
  1479      And the parties place the following pegged iceberg orders:
  1480        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
  1481        | lpprov | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50     | 10     |
  1482        | lpprov | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50     | 10     |
  1483   
  1484      Then the parties place the following orders:
  1485        | party | market id | side | volume | price | resulting trades | type       | tif     |
  1486        | aux1  | ETH/DEC21 | buy  | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
  1487        | aux2  | ETH/DEC21 | sell | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
  1488        | aux1  | ETH/DEC21 | buy  | 1      | 900   | 0                | TYPE_LIMIT | TIF_GTC |
  1489        | aux2  | ETH/DEC21 | sell | 1      | 1100  | 0                | TYPE_LIMIT | TIF_GTC |
  1490  
  1491      Then the opening auction period ends for market "ETH/DEC21"
  1492      And the market data for the market "ETH/DEC21" should be:
  1493        | mark price | trading mode            |
  1494        | 1000       | TRADING_MODE_CONTINUOUS |
  1495      When the parties place the following orders with ticks:
  1496        | party   | market id | side | volume | price | resulting trades | type       | tif     |
  1497        | trader3 | ETH/DEC21 | buy  | 3      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
  1498  
  1499      Then the parties should have the following account balances:
  1500        | party   | asset | market id | margin | general |
  1501        | trader3 | ETH   | ETH/DEC21 | 720    | 9280    |
  1502  
  1503      And the accumulated liquidity fees should be "0" for the market "ETH/DEC21"
  1504      And the accumulated infrastructure fees should be "0" for the asset "ETH"
  1505  
  1506      #  Changing net params fees factors
  1507      And the following network parameters are set:
  1508        | name                                 | value |
  1509        | market.fee.factors.makerFee          | 0.05  |
  1510        | market.fee.factors.infrastructureFee | 0.02  |
  1511  
  1512      Then the parties place the following orders with ticks:
  1513        | party   | market id | side | volume | price | resulting trades | type       | tif     |
  1514        | trader4 | ETH/DEC21 | sell | 4      | 1002  | 1                | TYPE_LIMIT | TIF_GTC |
  1515  
  1516      And the market data for the market "ETH/DEC21" should be:
  1517        | mark price | trading mode            |
  1518        | 1002       | TRADING_MODE_CONTINUOUS |
  1519  
  1520      Then the following trades should be executed:
  1521        | buyer   | price | size | seller  |
  1522        | trader3 | 1002  | 3    | trader4 |
  1523  
  1524  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 3 *1002 = 3006
  1525  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.02 * 3006 = 60.12 = 61 (rounded up to nearest whole value)
  1526  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.05 * 3006 = 150.30 = 151 (rounded up to nearest whole value)
  1527  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0 * 3006 = 0
  1528  
  1529      And the following transfers should happen:
  1530        | from    | to      | from account            | to account                       | market id | amount | asset |
  1531        | trader4 | market  | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 151    | ETH   |
  1532        | trader4 |         | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 61     | ETH   |
  1533        | trader4 | market | ACCOUNT_TYPE_GENERAL | ACCOUNT_TYPE_FEES_LIQUIDITY | ETH/DEC21 | 301 | ETH |
  1534        | market  | trader3 | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 151    | ETH   |
  1535  
  1536  # total_fee = infrastructure_fee + maker_fee + liquidity_fee = 61 + 151 + 0 = 212
  1537  
  1538      And the accumulated infrastructure fees should be "61" for the asset "ETH"
  1539      And the accumulated liquidity fees should be "301" for the market "ETH/DEC21"