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