code.vegaprotocol.io/vega@v0.79.0/core/integration/features/fees/amend-fees.feature (about)

     1  Feature: Fees when amend trades
     2  
     3  
     4    Background:
     5      Given the fees configuration named "fees-config-1":
     6        | maker fee | infrastructure fee |
     7        | 0.005     | 0.002              |
     8      And the price monitoring named "price-monitoring":
     9        | horizon | probability | auction extension |
    10        | 1       | 0.99        | 3                 |
    11      And the simple risk model named "simple-risk-model-1":
    12        | long | short | max move up | min move down | probability of trading |
    13        | 0.2  | 0.1   | 100         | -100          | 0.1                    |
    14  
    15      And the markets:
    16        | id        | quote name | asset | risk model          | margin calculator         | auction duration | fees          | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    17        | ETH/DEC21 | ETH        | ETH   | simple-risk-model-1 | default-margin-calculator | 2                | fees-config-1 | price-monitoring | default-eth-for-future | 0.25                   | 0                         | default-futures |
    18      And the following network parameters are set:
    19        | name                                    | value |
    20        | network.markPriceUpdateMaximumFrequency | 0s    |
    21        | limits.markets.maxPeggedOrders          | 2     |
    22  
    23    # this test requires me to be a bit more fresh to fix
    24    @Fees
    25    Scenario: Testing fees in continuous trading with one trade
    26      # setup accounts
    27      Given the parties deposit on asset's general account the following amount:
    28        | party    | asset | amount    |
    29        | aux1     | ETH   | 100000000 |
    30        | aux2     | ETH   | 100000000 |
    31        | trader3a | ETH   | 10000     |
    32        | trader3b | ETH   | 10000     |
    33        | trader4  | ETH   | 10000     |
    34        | trader5  | ETH   | 100000000 |
    35  
    36      When the parties submit the following liquidity provision:
    37        | id  | party | market id | commitment amount | fee   | lp type    |
    38        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | submission |
    39        | lp1 | aux1  | ETH/DEC21 | 10000             | 0.001 | submission |
    40      And the parties place the following pegged iceberg orders:
    41        | party | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    42        | aux1 | ETH/DEC21 | 10 | 1 | buy  | BID | 10 | 10 |
    43        | aux1 | ETH/DEC21 | 10 | 1 | sell | ASK | 10 | 10 |
    44      And the parties place the following orders:
    45        | party | market id | side | volume | price | resulting trades | type       | tif     |
    46        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    47        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    48        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
    49        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
    50      Then the opening auction period ends for market "ETH/DEC21"
    51      And the market data for the market "ETH/DEC21" should be:
    52        | mark price | trading mode            |
    53        | 1000       | TRADING_MODE_CONTINUOUS |
    54  
    55      And the order book should have the following volumes for market "ETH/DEC21":
    56        | side | price | volume |
    57        | sell | 1080  | 1      |
    58        | buy  | 920   | 1      |
    59        | buy  | 910   | 10     |
    60        | sell | 1090  | 10     |
    61  
    62      When the parties place the following orders with ticks:
    63        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
    64        | trader3a | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | t3a-b3-02 |
    65        | trader3b | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | t3b-b1-02 |
    66        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 2                | TYPE_LIMIT | TIF_GTC | t4-s4-02  |
    67  #| trader5  | ETH/DEC21 | sell | 1      | 2002  | 0                | TYPE_LIMIT | TIF_GTC | t5-s4-02  |
    68  #| trader5  | ETH/DEC21 | buy  | 1      | 101   | 0                | TYPE_LIMIT | TIF_GTC | t5-b1-02  |
    69  
    70      Then the market data for the market "ETH/DEC21" should be:
    71        | mark price | trading mode            |
    72        | 1002       | TRADING_MODE_CONTINUOUS |
    73  
    74      And the following trades should be executed:
    75        | buyer    | price | size | seller  |
    76        | trader3a | 1002  | 2    | trader4 |
    77        | trader3b | 1002  | 1    | trader4 |
    78  
    79  # For trader3a-
    80  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 1002 = 2004
    81  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
    82  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 2004 = 10.02 = 11 (rounded up to nearest whole value)
    83  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3 (rounded up to nearest whole value)
    84  
    85      # For trader3b -
    86      # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
    87      # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
    88      # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
    89      # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 1002 = 1.002 = 2 (rounded up to nearest whole value)
    90      And the following transfers should happen:
    91        | from    | to       | from account            | to account                       | market id | amount | asset |
    92        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 11     | ETH   |
    93        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
    94        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 8      | ETH   |
    95        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 11     | ETH   |
    96        | market  | trader3b | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
    97  
    98      # total_fee = maker_fee + infrastructure_fee + liquidity_fee =  11 + 6 + 8 = 25
    99  
   100      When the parties place the following orders with ticks:
   101        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
   102        | trader3a | ETH/DEC21 | buy  | 2      | 1001  | 0                | TYPE_LIMIT | TIF_GTC | t3a-b2-01 |
   103        | trader4  | ETH/DEC21 | sell | 4      | 1003  | 0                | TYPE_LIMIT | TIF_GTC | t4-s4-03  |
   104  
   105      # ensure orders are on the book
   106      And the order book should have the following volumes for market "ETH/DEC21":
   107        | side | price | volume |
   108        | sell | 1080  | 1      |
   109        | buy  | 1001  | 2      |
   110        | buy  | 920   | 1      |
   111        | buy  | 991   | 10     |
   112        | sell | 1012  | 10     |
   113        | sell | 1002  | 1      |
   114        | sell | 1003  | 4      |
   115  
   116      When the parties amend the following orders:
   117        | party   | reference | price | size delta | tif     |
   118        | trader4 | t4-s4-03  | 1002  | 0          | TIF_GTC |
   119      Then the market data for the market "ETH/DEC21" should be:
   120        | mark price | trading mode            |
   121        | 1002       | TRADING_MODE_CONTINUOUS |
   122      And the order book should have the following volumes for market "ETH/DEC21":
   123        | side | price | volume |
   124        | sell | 1080  | 1      |
   125        | buy  | 1001  | 2      |
   126        | buy  | 920   | 1      |
   127        | buy  | 991   | 10     |
   128        | sell | 1012  | 10     |
   129        | sell | 1002  | 5      |
   130  
   131      When the parties amend the following orders:
   132        | party   | reference | price | size delta | tif     |
   133        | trader4 | t4-s4-03  | 1001  | 0          | TIF_GTC |
   134      Then the market data for the market "ETH/DEC21" should be:
   135        | mark price | last traded price | trading mode            |
   136        | 1002       | 1001              | TRADING_MODE_CONTINUOUS |
   137      And the following trades should be executed:
   138        | buyer    | price | size | seller  |
   139        | trader3a | 1001  | 2    | trader4 |
   140  
   141      When the parties place the following orders:
   142        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference |
   143        | trader3b | ETH/DEC21 | buy  | 3      | 1002  | 2                | TYPE_LIMIT | TIF_GTC | t3b-b3-02 |
   144      Then the market data for the market "ETH/DEC21" should be:
   145        | mark price | trading mode            |
   146        | 1002       | TRADING_MODE_CONTINUOUS |
   147      And the following trades should be executed:
   148        | buyer    | price | size | seller  |
   149        | trader3b | 1001  | 2    | trader4 |
   150        | trader3b | 1002  | 1    | trader4 |
   151  
   152    Scenario: Testing fees get collected when amended order trades
   153      Given the parties deposit on asset's general account the following amount:
   154        | party    | asset | amount    |
   155        | aux1     | ETH   | 100000000 |
   156        | aux2     | ETH   | 100000000 |
   157        | trader3a | ETH   | 10000     |
   158        | trader3b | ETH   | 10000     |
   159        | trader4  | ETH   | 1550      |
   160        | lpprov   | ETH   | 100000000 |
   161      And the markets are updated:
   162        | id          | linear slippage factor |
   163        | ETH/DEC21   | 0                      |
   164      When the parties place the following orders:
   165        | party | market id | side | volume | price | resulting trades | type       | tif     |
   166        | aux1  | ETH/DEC21 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   167        | aux2  | ETH/DEC21 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   168        | aux1  | ETH/DEC21 | buy  | 1      | 920   | 0                | TYPE_LIMIT | TIF_GTC |
   169        | aux2  | ETH/DEC21 | sell | 1      | 1080  | 0                | TYPE_LIMIT | TIF_GTC |
   170      And the parties submit the following liquidity provision:
   171        | id  | party  | market id | commitment amount | fee | lp type    |
   172        | lp1 | lpprov | ETH/DEC21 | 90000             | 0.1 | submission |
   173        | lp1 | lpprov | ETH/DEC21 | 90000             | 0.1 | submission |
   174      And the parties place the following pegged iceberg orders:
   175        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
   176        | lpprov | ETH/DEC21 | 2         | 1                    | buy  | BID              | 50     | 100    |
   177        | lpprov | ETH/DEC21 | 2         | 1                    | sell | ASK              | 50     | 100    |
   178      When the opening auction period ends for market "ETH/DEC21"
   179      Then the market data for the market "ETH/DEC21" should be:
   180        | mark price | trading mode            |
   181        | 1000       | TRADING_MODE_CONTINUOUS |
   182  
   183      When the parties place the following orders with ticks:
   184        | party    | market id | side | volume | price | resulting trades | type       | tif     |
   185        | trader3a | ETH/DEC21 | buy  | 2      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   186        | trader3b | ETH/DEC21 | buy  | 1      | 1002  | 0                | TYPE_LIMIT | TIF_GTC |
   187        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 2                | TYPE_LIMIT | TIF_GTC |
   188  
   189      Then the market data for the market "ETH/DEC21" should be:
   190        | mark price | trading mode            |
   191        | 1002       | TRADING_MODE_CONTINUOUS |
   192  
   193      And the following trades should be executed:
   194        | buyer    | price | size | seller  |
   195        | trader3a | 1002  | 2    | trader4 |
   196        | trader3b | 1002  | 1    | trader4 |
   197  
   198  # For trader3a-
   199  # trade_value_for_fee_purposes for trader3a = size_of_trade * price_of_trade = 2 * 1002 = 2004
   200  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 2004 = 4.008 = 5 (rounded up to nearest whole value)
   201  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 2004 = 10.02 = 11 (rounded up to nearest whole value)
   202  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 2004 = 2.004 = 3 (rounded up to nearest whole value)
   203  
   204  # For trader3b -
   205  # trade_value_for_fee_purposes = size_of_trade * price_of_trade = 1 * 1002 = 1002
   206  # infrastructure_fee = fee_factor[infrastructure] * trade_value_for_fee_purposes = 0.002 * 1002 = 2.004 = 3 (rounded up to nearest whole value)
   207  # maker_fee =  fee_factor[maker]  * trade_value_for_fee_purposes = 0.005 * 1002 = 5.01 = 6 (rounded up to nearest whole value)
   208  # liquidity_fee = fee_factor[liquidity] * trade_value_for_fee_purposes = 0.001 * 1002 = 1.002 = 2 (rounded up to nearest whole value)
   209  
   210      And the following transfers should happen:
   211        | from    | to       | from account            | to account                       | market id | amount | asset |
   212        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 11     | ETH   |
   213        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 6      | ETH   |
   214        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 8      | ETH   |
   215        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 11     | ETH   |
   216        | market  | trader3b | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 6      | ETH   |
   217  
   218  # total_fee = maker_fee + infrastructure_fee + liquidity_fee =  11 + 6 + 8 = 25
   219      # Placing second set of orders
   220      When the parties place the following orders with ticks:
   221        | party    | market id | side | volume | price | resulting trades | type       | tif     | reference      |
   222        | trader3a | ETH/DEC21 | buy  | 2      | 1000  | 0                | TYPE_LIMIT | TIF_GTC | trader3a-buy-1 |
   223        | trader4  | ETH/DEC21 | sell | 4      | 1002  | 0                | TYPE_LIMIT | TIF_GTC | trader4-sell-2 |
   224  
   225  
   226      # reducing size
   227      And the parties amend the following orders:
   228        | party   | reference      | price | size delta | tif     |
   229        | trader4 | trader4-sell-2 | 1000  | 0          | TIF_GTC |
   230      Then the network moves ahead "1" blocks
   231  
   232      # matching the order now
   233      And the following trades should be executed:
   234        | buyer    | price | size | seller  |
   235        | trader3a | 1000  | 2    | trader4 |
   236  
   237      # checking if continuous mode still exists
   238      And the market data for the market "ETH/DEC21" should be:
   239        | mark price | trading mode            |
   240        | 1000       | TRADING_MODE_CONTINUOUS |
   241  
   242  
   243      And the following transfers should happen:
   244        | from    | to       | from account            | to account                       | market id | amount | asset |
   245        | trader4 | market   | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC21 | 10     | ETH   |
   246        | trader4 |          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE |           | 4      | ETH   |
   247        | market  | trader3a | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC21 | 10     | ETH   |