code.vegaprotocol.io/vega@v0.79.0/core/integration/features/spot/orders/0080-SPOT-024.feature (about)

     1  Feature: Spot market bug (from the incentive) replication
     2  
     3    Scenario: 0080-SPOT-024, 0080-SPOT-025 market orders should be rejected when traders do not have enough collateral to cover the trades in spot market
     4    Background:
     5  
     6      Given the following network parameters are set:
     7        | name                                            | value |
     8        | network.markPriceUpdateMaximumFrequency         | 1s    |
     9        | market.value.windowLength                       | 1h    |
    10        | market.liquidity.maximumLiquidityFeeFactorLevel | 0.4   |
    11        | validators.epoch.length                         | 4s    |
    12  
    13      Given the following assets are registered:
    14        | id  | decimal places |
    15        | USD | 0              |
    16        | BTC | 0              |
    17  
    18      Given the fees configuration named "fees-config-1":
    19        | maker fee | infrastructure fee |
    20        | 0.01      | 0.03               |
    21      Given the log normal risk model named "lognormal-risk-model-1":
    22        | risk aversion | tau  | mu | r   | sigma |
    23        | 0.001         | 0.01 | 0  | 0.0 | 1.2   |
    24      And the price monitoring named "price-monitoring-1":
    25        | horizon | probability | auction extension |
    26        | 36000   | 0.999       | 1                 |
    27  
    28      And the spot markets:
    29        | id      | name    | base asset | quote asset | risk model             | auction duration | fees          | price monitoring   | decimal places | position decimal places | sla params    |
    30        | BTC/USD | BTC/USD | BTC        | USD         | lognormal-risk-model-1 | 1                | fees-config-1 | price-monitoring-1 | 0              | 0                       | default-basic |
    31  
    32      And the following network parameters are set:
    33        | name                                             | value |
    34        | limits.markets.maxPeggedOrders                   | 2     |
    35        | network.markPriceUpdateMaximumFrequency          | 0s    |
    36        | market.liquidity.providersFeeCalculationTimeStep | 1s    |
    37        | validators.epoch.length                          | 58s   |
    38        | market.liquidity.stakeToCcyVolume                | 1     |
    39  
    40      Given the parties deposit on asset's general account the following amount:
    41        | party  | asset | amount   |
    42        | party1 | USD   | 50000000 |
    43        | party1 | BTC   | 100      |
    44        | party2 | USD   | 1000     |
    45        | party3 | USD   | 1000     |
    46        | party5 | USD   | 70000    |
    47        | party2 | BTC   | 100      |
    48        | party4 | BTC   | 1        |
    49        | lp     | USD   | 1000     |
    50        | lp     | BTC   | 100      |
    51      And the average block duration is "1"
    52  
    53      Given the parties submit the following liquidity provision:
    54        | id  | party | market id | commitment amount | fee   | lp type    |
    55        | lp1 | lp    | BTC/USD   | 5                 | 0.025 | submission |
    56  
    57      Then "party2" should have general account balance of "1000" for asset "USD"
    58      Then "party2" should have general account balance of "100" for asset "BTC"
    59  
    60      And the parties place the following orders:
    61        | party  | market id | side | volume | price | resulting trades | type       | tif     |
    62        | party1 | BTC/USD   | buy  | 10     | 55000 | 0                | TYPE_LIMIT | TIF_GTC |
    63        | party1 | BTC/USD   | buy  | 3      | 58000 | 0                | TYPE_LIMIT | TIF_GTC |
    64        | party1 | BTC/USD   | buy  | 3      | 59000 | 0                | TYPE_LIMIT | TIF_GTC |
    65        | party1 | BTC/USD   | buy  | 1      | 60000 | 0                | TYPE_LIMIT | TIF_GTC |
    66        | party2 | BTC/USD   | sell | 1      | 60000 | 0                | TYPE_LIMIT | TIF_GTC |
    67        | party2 | BTC/USD   | sell | 3      | 61000 | 0                | TYPE_LIMIT | TIF_GTC |
    68        | party2 | BTC/USD   | sell | 3      | 62000 | 0                | TYPE_LIMIT | TIF_GTC |
    69        | party2 | BTC/USD   | sell | 4      | 63000 | 0                | TYPE_LIMIT | TIF_GTC |
    70        | party2 | BTC/USD   | sell | 10     | 64000 | 0                | TYPE_LIMIT | TIF_GTC |
    71        | party2 | BTC/USD   | sell | 5      | 65000 | 0                | TYPE_LIMIT | TIF_GTC |
    72  
    73      Then the network moves ahead "2" blocks
    74  
    75      Then the market data for the market "BTC/USD" should be:
    76        | mark price | trading mode            | auction trigger             | horizon | min bound | max bound | open interest |
    77        | 60000      | TRADING_MODE_CONTINUOUS | AUCTION_TRIGGER_UNSPECIFIED | 36000   | 52466     | 68503     | 0             |
    78  
    79      Then "party2" should have general account balance of "61000" for asset "USD"
    80      Then "party2" should have general account balance of "74" for asset "BTC"
    81  
    82      Then "party2" should have holding account balance of "25" for asset "BTC"
    83  
    84      And the parties place the following orders:
    85        | party  | market id | side | volume | price | resulting trades | type        | tif     | reference | error                        |
    86        | party3 | BTC/USD   | buy  | 20     | 0     | 0                | TYPE_MARKET | TIF_IOC | p3-b1     | insufficient funds for order |
    87  
    88      And the parties place the following orders:
    89        | party  | market id | side | volume | price | resulting trades | type        | tif     | reference | error                                                              |
    90        | party4 | BTC/USD   | sell | 10     | 0     | 0                | TYPE_MARKET | TIF_IOC | p4-s1     | party does not have sufficient balance to cover the trade and fees |
    91  
    92      Then the network moves ahead "1" blocks
    93  
    94      Then "party2" should have general account balance of "61000" for asset "USD"
    95      Then "party2" should have general account balance of "74" for asset "BTC"
    96  
    97      Then "party2" should have holding account balance of "25" for asset "BTC"
    98  
    99      Then "party3" should have general account balance of "1000" for asset "USD"
   100      Then "party4" should have general account balance of "1" for asset "BTC"
   101  
   102      And the parties place the following orders:
   103        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error |
   104        | party3 | BTC/USD   | buy  | 20     | 10    | 0                | TYPE_LIMIT | TIF_GTC | p3-b2     |       |
   105  
   106      And the parties place the following orders:
   107        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error |
   108        | party4 | BTC/USD   | sell | 1      | 66000 | 0                | TYPE_LIMIT | TIF_GTC | p4-s2     |       |
   109  
   110      #0080-SPOT-026: amend order - order is amended such that would trade immediately and the party can't afford none/some of the trades
   111      When the parties amend the following orders:
   112        | party  | reference | price | size delta | tif     | error                                                              |
   113        | party3 | p3-b2     | 66000 | -10        | TIF_GTC | party does not have sufficient balance to cover the trade and fees |
   114        | party4 | p4-s2     | 59000 | 2          | TIF_GTC | party does not have sufficient balance to cover the new size       |
   115  
   116      And the order book should have the following volumes for market "BTC/USD":
   117        | side | price | volume |
   118        | buy  | 10    | 20     |
   119        | sell | 66000 | 1      |
   120  
   121      #0080-SPOT-027:submit order - limit order, partly matched, party can't afford the trades
   122      And the parties place the following orders:
   123        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error                                                              |
   124        | party3 | BTC/USD   | buy  | 6      | 61000 | 0                | TYPE_LIMIT | TIF_GTC | p3-b3     | party does not have sufficient balance to cover the trade and fees |
   125        | party5 | BTC/USD   | buy  | 2      | 61000 | 0                | TYPE_LIMIT | TIF_GTC | p5-b1     | party does not have sufficient balance to cover the trade and fees |
   126  
   127      #0080-SPOT-028:submit order - limit order, no match, added to the book, party can't cover the amount that needs to be transfered to the holding
   128      And the parties place the following orders:
   129        | party  | market id | side | volume | price | resulting trades | type       | tif     | reference | error                                                              |
   130        | party4 | BTC/USD   | sell | 2      | 67000 | 0                | TYPE_LIMIT | TIF_GTC | p4-s3     | party does not have sufficient balance to cover the trade and fees |
   131