code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/fees_from_margin.feature (about)

     1  Feature: Over leveraged trader can pay fees with released margin
     2  
     3      Ticket #2010 (https://github.com/vegaprotocol/specs/issues/2010)
     4      states a party should be able to cover any expected fees when
     5      reducing their position with a zero balance in their general
     6      account.
     7  
     8      Test checks this is true for the following combinations:
     9      - long and shorts positions
    10      - market and limit orders
    11      - exit price above and below the mark price at exit
    12  
    13  
    14    Background:
    15  
    16      # Initialise the network
    17      And the average block duration is "1"
    18      And the following network parameters are set:
    19        | name                                    | value |
    20        | market.fee.factors.makerFee             | 0.00  |
    21        | market.fee.factors.infrastructureFee    | 0.01  |
    22        | network.markPriceUpdateMaximumFrequency | 0s    |
    23  
    24      # Initialise the market
    25      And the following assets are registered:
    26        | id       | decimal places | quantum |
    27        | USD-1-10 | 0              | 1       |
    28      And the simple risk model named "simple-risk-model":
    29        | long | short | max move up | min move down | probability of trading |
    30        | 0.1  | 0.1   | 100         | -100          | 0.1                    |
    31      And the markets:
    32        | id           | quote name | asset    | risk model        | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      | decimal places | position decimal places |
    33        | ETH/USD-1-10 | ETH        | USD-1-10 | simple-risk-model | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0                      | 0                         | default-futures | 0              | 0                       |
    34  
    35      # Initialise the parties
    36      Given the parties deposit on asset's general account the following amount:
    37        | party  | asset    | amount  |
    38        | aux1   | USD-1-10 | 1000000 |
    39        | aux2   | USD-1-10 | 1000000 |
    40        | trader | USD-1-10 | 1250    |
    41  
    42      # Exit opening auctions
    43      When the parties place the following orders:
    44        | party | market id    | side | volume | price | resulting trades | type       | tif     |
    45        | aux1  | ETH/USD-1-10 | buy  | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    46        | aux2  | ETH/USD-1-10 | sell | 1      | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    47      And the opening auction period ends for market "ETH/USD-1-10"
    48      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/USD-1-10"
    49  
    50  
    51    Scenario Outline: With no funds in the general account, reducing long position with a limit order at various prices
    52  
    53      # Open a position
    54      Given the parties place the following orders:
    55        | party  | market id    | side | volume | price | resulting trades | type       | tif     |
    56        | trader | ETH/USD-1-10 | buy  | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
    57        | aux2   | ETH/USD-1-10 | sell | 10     | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
    58      When the network moves ahead "1" blocks
    59      Then the parties should have the following profit and loss:
    60        | party  | volume | unrealised pnl | realised pnl |
    61        | trader | 10     | 0              | 0            |
    62      And the parties should have the following account balances:
    63        | party  | asset    | market id    | margin | general |
    64        | trader | USD-1-10 | ETH/USD-1-10 | 1200   | 50      |
    65      And the parties should have the following margin levels:
    66        | party  | market id    | maintenance | search | initial | release |
    67        | trader | ETH/USD-1-10 | 1000        | 1100   | 1200    | 1400    |
    68  
    69      # Empty general account
    70      Given the parties place the following orders:
    71        | party | market id    | side | volume | price | resulting trades | type       | tif     |
    72        | aux1  | ETH/USD-1-10 | buy  | 1      | 975   | 0                | TYPE_LIMIT | TIF_GTC |
    73        | aux2  | ETH/USD-1-10 | sell | 1      | 975   | 1                | TYPE_LIMIT | TIF_GTC |
    74      When the network moves ahead "1" blocks
    75      And the parties should have the following account balances:
    76        | party  | asset    | market id    | margin | general |
    77        | trader | USD-1-10 | ETH/USD-1-10 | 1000   | 0       |
    78      And the parties should have the following margin levels:
    79        | party  | market id    | maintenance | search | initial | release |
    80        | trader | ETH/USD-1-10 | 975         | 1072   | 1170    | 1365    |
    81  
    82      # Attempt to reduce position
    83      Given the parties place the following orders:
    84        | party  | market id    | side | volume | price   | resulting trades | type       | tif     |
    85        | aux2   | ETH/USD-1-10 | buy  | <size> | <price> | 0                | TYPE_LIMIT | TIF_GTC |
    86        | trader | ETH/USD-1-10 | sell | <size> | <price> | 1                | <type>     | TIF_IOC |
    87      When the network moves ahead "1" blocks
    88      And the following trades should be executed:
    89        | buyer | price   | size   | seller | seller fee |
    90        | aux2  | <price> | <size> | trader | <fee>      |
    91      And the parties should have the following account balances:
    92        | party  | asset    | market id    | margin   | general   |
    93        | trader | USD-1-10 | ETH/USD-1-10 | <margin> | <general> |
    94  
    95    Examples:
    96      # Table contains inputs for the trade reducing the over leveraged
    97      # position and the resulting account balances.
    98        | size | price | fee | margin | general | type        |
    99        | 1    | 950   | 10  | 0      | 0       | TYPE_LIMIT  |
   100        | 9    | 950   | 86  | 114    | 550     | TYPE_LIMIT  |
   101        | 10   | 970   | 97  | 0      | 853     | TYPE_LIMIT  |
   102        | 1    | 975   | 10  | 990    | 0       | TYPE_LIMIT  |
   103        | 9    | 975   | 88  | 117    | 795     | TYPE_LIMIT  |
   104        | 10   | 975   | 98  | 0      | 902     | TYPE_LIMIT  |
   105        | 1    | 1000  | 10  | 1240   | 0       | TYPE_LIMIT  |
   106        | 9    | 1000  | 90  | 120    | 1040    | TYPE_LIMIT  |
   107        | 10   | 1000  | 100 | 0      | 1150    | TYPE_LIMIT  |
   108        | 1    | 950   | 10  | 0      | 0       | TYPE_MARKET |
   109        | 9    | 950   | 86  | 114    | 550     | TYPE_MARKET |
   110        | 10   | 970   | 97  | 0      | 853     | TYPE_MARKET |
   111        | 1    | 975   | 10  | 990    | 0       | TYPE_MARKET |
   112        | 9    | 975   | 88  | 117    | 795     | TYPE_MARKET |
   113        | 10   | 975   | 98  | 0      | 902     | TYPE_MARKET |
   114        | 1    | 1000  | 10  | 1240   | 0       | TYPE_MARKET |
   115        | 9    | 1000  | 90  | 120    | 1040    | TYPE_MARKET |
   116        | 10   | 1000  | 100 | 0      | 1150    | TYPE_MARKET |
   117  
   118  
   119    Scenario Outline: With no funds in the general account, reducing short position with a limit order at various prices
   120  
   121      # Open a position
   122      Given the parties place the following orders:
   123        | party  | market id    | side | volume | price | resulting trades | type       | tif     |
   124        | trader | ETH/USD-1-10 | sell | 10     | 1000  | 0                | TYPE_LIMIT | TIF_GTC |
   125        | aux2   | ETH/USD-1-10 | buy  | 10     | 1000  | 1                | TYPE_LIMIT | TIF_GTC |
   126      When the network moves ahead "1" blocks
   127      Then the parties should have the following profit and loss:
   128        | party  | volume | unrealised pnl | realised pnl |
   129        | trader | -10    | 0              | 0            |
   130      And the parties should have the following account balances:
   131        | party  | asset    | market id    | margin | general |e
   132        | trader | USD-1-10 | ETH/USD-1-10 | 1200   | 50      |
   133      And the parties should have the following margin levels:
   134        | party  | market id    | maintenance | search | initial | release |
   135        | trader | ETH/USD-1-10 | 1000        | 1100   | 1200    | 1400    |
   136  
   137      # Empty general account
   138      Given the parties place the following orders:
   139        | party | market id    | side | volume | price | resulting trades | type       | tif     |
   140        | aux1  | ETH/USD-1-10 | buy  | 1      | 1020  | 0                | TYPE_LIMIT | TIF_GTC |
   141        | aux2  | ETH/USD-1-10 | sell | 1      | 1020  | 1                | TYPE_LIMIT | TIF_GTC |
   142      When the network moves ahead "1" blocks
   143      And the parties should have the following account balances:
   144        | party  | asset    | market id    | margin | general |
   145        | trader | USD-1-10 | ETH/USD-1-10 | 1050   | 0       |
   146      And the parties should have the following margin levels:
   147        | party  | market id    | maintenance | search | initial | release |
   148        | trader | ETH/USD-1-10 | 1020        | 1122   | 1224    | 1428    |
   149  
   150      # Attempt to reduce position
   151      Given the parties place the following orders:
   152        | party  | market id    | side | volume | price   | resulting trades | type       | tif     |
   153        | aux2   | ETH/USD-1-10 | sell | <size> | <price> | 0                | TYPE_LIMIT | TIF_GTC |
   154        | trader | ETH/USD-1-10 | buy  | <size> | <price> | 1                | <type>     | TIF_IOC |
   155      When the network moves ahead "1" blocks
   156      Then debug trades
   157      And the following trades should be executed:
   158        | buyer  | price   | size   | seller | buyer fee |
   159        | trader | <price> | <size> | aux2   | <fee>     |
   160      And the parties should have the following account balances:
   161        | party  | asset    | market id    | margin   | general   |
   162        | trader | USD-1-10 | ETH/USD-1-10 | <margin> | <general> |
   163  
   164    Examples:
   165      # Table contains inputs for the trade reducing the over leveraged
   166      # position and the resulting account balances.
   167        | size | price | fee | margin | general | type        |
   168        | 1    | 1040  | 11  | 0      | 0       | TYPE_LIMIT  |
   169        | 9    | 1040  | 94  | 124    | 632     | TYPE_LIMIT  |
   170        | 10   | 1040  | 104 | 0      | 746     | TYPE_LIMIT  |
   171        | 1    | 1020  | 11  | 1039   | 0       | TYPE_LIMIT  |
   172        | 9    | 1020  | 92  | 122    | 836     | TYPE_LIMIT  |
   173        | 10   | 1020  | 102 | 0      | 948     | TYPE_LIMIT  |
   174        | 1    | 1000  | 10  | 1240   | 0       | TYPE_LIMIT  |
   175        | 9    | 1000  | 90  | 120    | 1040    | TYPE_LIMIT  |
   176        | 10   | 1000  | 100 | 0      | 1150    | TYPE_LIMIT  |
   177        | 1    | 1040  | 11  | 0      | 0       | TYPE_MARKET |
   178        | 9    | 1040  | 94  | 124    | 632     | TYPE_MARKET |
   179        | 10   | 1040  | 104 | 0      | 746     | TYPE_MARKET |
   180        | 1    | 1020  | 11  | 1039   | 0       | TYPE_MARKET |
   181        | 9    | 1020  | 92  | 122    | 836     | TYPE_MARKET |
   182        | 10   | 1020  | 102 | 0      | 948     | TYPE_MARKET |
   183        | 1    | 1000  | 10  | 1240   | 0       | TYPE_MARKET |
   184        | 9    | 1000  | 90  | 120    | 1040    | TYPE_MARKET |
   185        | 10   | 1000  | 100 | 0      | 1150    | TYPE_MARKET |