code.vegaprotocol.io/vega@v0.79.0/core/integration/features/orders/stop-orders-linked.feature (about)

     1  Feature: linked stop orders
     2  
     3    Background:
     4      Given the markets:
     5        | id        | quote name | asset | risk model                    | margin calculator         | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
     6        | ETH/DEC19 | BTC        | BTC   | default-simple-risk-model-3   | default-margin-calculator | 1                | default-none | default-none     | default-eth-for-future | 0.25                   | 0                         | default-futures |
     7        | ETH/DEC20 | BTC        | BTC   | default-log-normal-risk-model | default-margin-calculator | 1                | default-none | default-basic    | default-eth-for-future | 1e-3                   | 0                         | default-futures |
     8      And the following network parameters are set:
     9        | name                                    | value |
    10        | market.auction.minimumDuration          | 1     |
    11        | network.markPriceUpdateMaximumFrequency | 0s    |
    12        | limits.markets.maxPeggedOrders          | 1500  |
    13        | spam.protection.max.stopOrdersPerMarket | 5     |
    14  
    15      # setup accounts
    16      Given time is updated to "2019-11-30T00:00:00Z"
    17      Given the parties deposit on asset's general account the following amount:
    18        | party  | asset | amount   |
    19        | party1 | BTC   | 1000000  |
    20        | party2 | BTC   | 1000000  |
    21        | party3 | BTC   | 1000000  |
    22        | aux    | BTC   | 1000000  |
    23        | aux2   | BTC   | 1000000  |
    24        | aux3   | BTC   | 1000000  |
    25        | lpprov | BTC   | 90000000 |
    26  
    27      When the parties submit the following liquidity provision:
    28        | id  | party  | market id | commitment amount | fee | lp type    |
    29        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    30        | lp1 | lpprov | ETH/DEC19 | 90000000          | 0.1 | submission |
    31      And the parties place the following pegged iceberg orders:
    32        | party  | market id | peak size | minimum visible size | side | pegged reference | volume     | offset |
    33        | lpprov | ETH/DEC19 | 2         | 1                    | buy  | BID              | 50         | 10     |
    34        | lpprov | ETH/DEC19 | 2         | 1                    | sell | ASK              | 50         | 10     |
    35   
    36      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    37      When the parties place the following orders:
    38        | party | market id | side | volume | price | resulting trades | type       | tif     |
    39        | aux   | ETH/DEC19 | buy  | 20     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    40        | aux   | ETH/DEC19 | sell | 20     | 10001 | 0                | TYPE_LIMIT | TIF_GTC |
    41        | aux2  | ETH/DEC19 | buy  | 5      | 50    | 0                | TYPE_LIMIT | TIF_GTC |
    42        | aux3  | ETH/DEC19 | sell | 5      | 50    | 0                | TYPE_LIMIT | TIF_GTC |
    43  
    44      Then the opening auction period ends for market "ETH/DEC19"
    45      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    46  
    47    
    48  
    49    Scenario: A linked stop order with position size override will be cancelled if the position flips short to long (0014-ORDT-128)
    50  
    51      # party1 will start 10 short
    52      When the parties place the following orders:
    53        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    54        | party1| ETH/DEC19 | sell | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | sellorder |
    55        | party2| ETH/DEC19 | buy  | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | buyorder  |
    56  
    57      # Place a buy position linked stop order
    58      When the parties place the following orders:
    59        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | ra price trigger | reference | ra size override setting | ra size override percentage |
    60        | party1| ETH/DEC19 | buy  | 10     |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 52               | stop1     | POSITION                 | 1.0                         |
    61  
    62      Then the stop orders should have the following states
    63        | party  | market id | status          | reference |
    64        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
    65  
    66      # Now let party1 change their position to be long so we can trigger the stop order to be cancelled
    67      When the parties place the following orders:
    68        | party | market id | side | volume | price | resulting trades | type       | tif     | 
    69        | party1| ETH/DEC19 | buy  | 11     | 51    | 0                | TYPE_LIMIT | TIF_GTC | 
    70        | party2| ETH/DEC19 | sell | 11     | 51    | 1                | TYPE_LIMIT | TIF_GTC | 
    71  
    72      # Stop order should have been cancelled
    73      Then the stop orders should have the following states
    74        | party  | market id | status           | reference |
    75        | party1 | ETH/DEC19 | STATUS_CANCELLED | stop1     |
    76  
    77  
    78  
    79    Scenario: A linked stop order with position size override will be cancelled if the position flips long to short (0014-ORDT-128)
    80  
    81      # party1 will start 10 long
    82      When the parties place the following orders:
    83        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
    84        | party1| ETH/DEC19 | buy  | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | buyorder  |
    85        | party2| ETH/DEC19 | sell | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | sellorder |
    86  
    87      # Place a sell position linked stop order
    88      When the parties place the following orders:
    89        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage |
    90        | party1| ETH/DEC19 | sell | 10     |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 1.0                         | 
    91  
    92      Then the stop orders should have the following states
    93        | party  | market id | status          | reference |
    94        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
    95  
    96      # Now let party1 change their position to be short so we can trigger the stop order to be cancelled
    97      When the parties place the following orders:
    98        | party | market id | side | volume | price | resulting trades | type       | tif     | 
    99        | party2| ETH/DEC19 | buy  | 11     | 49    | 0                | TYPE_LIMIT | TIF_GTC | 
   100        | party1| ETH/DEC19 | sell | 11     | 49    | 1                | TYPE_LIMIT | TIF_GTC | 
   101  
   102      # Stop order should have been cancelled
   103      Then the stop orders should have the following states
   104        | party  | market id | status           | reference |
   105        | party1 | ETH/DEC19 | STATUS_CANCELLED | stop1     |
   106  
   107  
   108    Scenario: A linked stop order with position size override will not be cancelled if the position is flat (0014-ORDT-128)
   109  
   110      # party1 will start 10 short
   111      When the parties place the following orders:
   112        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   113        | party1| ETH/DEC19 | sell | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | sellorder |
   114        | party2| ETH/DEC19 | buy  | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | buyorder  |
   115  
   116      # Place a buy position linked stop order
   117      When the parties place the following orders:
   118        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | ra price trigger | reference | ra size override setting | ra size override percentage |
   119        | party1| ETH/DEC19 | buy  | 10     |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 52               | stop1     | POSITION                 | 1.0                         |
   120  
   121      Then the stop orders should have the following states
   122        | party  | market id | status          | reference |
   123        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   124  
   125      # Now let party1 change their position to be flat and check the stop[ order is not cancelled]
   126      When the parties place the following orders:
   127        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   128        | party1| ETH/DEC19 | buy  | 10     | 51    | 0                | TYPE_LIMIT | TIF_GTC | 
   129        | party2| ETH/DEC19 | sell | 10     | 51    | 1                | TYPE_LIMIT | TIF_GTC | 
   130  
   131      # Stop order should not have triggered
   132      Then the stop orders should have the following states
   133        | party  | market id | status           | reference |
   134        | party1 | ETH/DEC19 | STATUS_PENDING   | stop1     |
   135  
   136  
   137  
   138    Scenario: A linked stop order with position size override will not be cancelled if the position is flat (0014-ORDT-128)
   139  
   140      # party1 will start 10 long
   141      When the parties place the following orders:
   142        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   143        | party1| ETH/DEC19 | buy  | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | buyorder  |
   144        | party2| ETH/DEC19 | sell | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | sellorder |
   145  
   146      # Place a sell position linked stop order
   147      When the parties place the following orders:
   148        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage |
   149        | party1| ETH/DEC19 | sell | 10     |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 1.0                         |
   150  
   151      Then the stop orders should have the following states
   152        | party  | market id | status          | reference |
   153        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   154  
   155      # Now let party1 change their position to be flat and make sure the stop order is not cancelled
   156      When the parties place the following orders:
   157        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   158        | party2| ETH/DEC19 | buy  | 10     | 49    | 0                | TYPE_LIMIT | TIF_GTC | 
   159        | party1| ETH/DEC19 | sell | 10     | 49    | 1                | TYPE_LIMIT | TIF_GTC | 
   160  
   161      # Stop order should not have triggered
   162      Then the stop orders should have the following states
   163        | party  | market id | status           | reference |
   164        | party1 | ETH/DEC19 | STATUS_PENDING   | stop1     |
   165  
   166  
   167  
   168    Scenario: A linked stop order with position size override will flatten the position after being triggered (0014-ORDT-127)
   169  
   170      # party1 will start 10 short
   171      When the parties place the following orders:
   172        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   173        | party1| ETH/DEC19 | sell | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | sellorder |
   174        | party2| ETH/DEC19 | buy  | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | buyorder  |
   175  
   176      # Place a buy position linked stop order
   177      When the parties place the following orders:
   178        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | ra price trigger | reference | ra size override setting | ra size override percentage |
   179        | party1| ETH/DEC19 | buy  | 2      | 0     | 0                | TYPE_MARKET| TIF_IOC | reduce | 52               | stop1     | POSITION                 | 1.0                         |
   180  
   181      Then the stop orders should have the following states
   182        | party  | market id | status          | reference |
   183        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   184  
   185      # Place some orders on the book to give liquidity and to move the last price to trigger the stop order
   186      When the parties place the following orders:
   187        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   188        | party3| ETH/DEC19 | sell | 30     | 52    | 0                | TYPE_LIMIT | TIF_GTC | 
   189        | party2| ETH/DEC19 | buy  | 1      | 52    | 1                | TYPE_LIMIT | TIF_GTC | 
   190  
   191      # Stop order should have triggered
   192      Then the stop orders should have the following states
   193        | party  | market id | status           | reference |
   194        | party1 | ETH/DEC19 | STATUS_TRIGGERED | stop1     |
   195  
   196  
   197  
   198    Scenario: A linked stop order with position size override will be flattened when the stop order is triggered (0014-ORDT-127)
   199  
   200      # party1 will start 10 long
   201      When the parties place the following orders:
   202        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   203        | party1| ETH/DEC19 | buy  | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | buyorder  |
   204        | party2| ETH/DEC19 | sell | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | sellorder |
   205  
   206      # Place a sell position linked stop order
   207      When the parties place the following orders:
   208        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage |
   209        | party1| ETH/DEC19 | sell | 10     |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 1.0                         |
   210  
   211      Then the stop orders should have the following states
   212        | party  | market id | status          | reference |
   213        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   214  
   215      # Now let add some liquidity to the book and move the last price to trigger the stop order
   216      When the parties place the following orders:
   217        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   218        | party2| ETH/DEC19 | buy  | 30     | 48    | 0                | TYPE_LIMIT | TIF_GTC | 
   219        | party3| ETH/DEC19 | sell | 1      | 48    | 1                | TYPE_LIMIT | TIF_GTC | 
   220  
   221      # Stop order should have been triggered
   222      Then the stop orders should have the following states
   223        | party  | market id | status           | reference |
   224        | party1 | ETH/DEC19 | STATUS_TRIGGERED | stop1     |
   225  
   226  
   227    Scenario: A linked stop order with position size override and scaling will partially flatten the position after being triggered (0014-ORDT-129)
   228  
   229      # party1 will start 20 short
   230      When the parties place the following orders:
   231        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   232        | party1| ETH/DEC19 | sell | 20     | 50    | 0                | TYPE_LIMIT | TIF_GTC | sellorder |
   233        | party2| ETH/DEC19 | buy  | 21     | 50    | 1                | TYPE_LIMIT | TIF_GTC | buyorder  |
   234  
   235      # Place a buy position linked stop order with a size scaling
   236      When the parties place the following orders:
   237        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | ra price trigger | reference | ra size override setting | ra size override percentage |
   238        | party1| ETH/DEC19 | buy  | 2      | 0     | 0                | TYPE_MARKET| TIF_IOC | reduce | 52               | stop1     | POSITION                 | 0.75                        |
   239  
   240      Then the stop orders should have the following states
   241        | party  | market id | status          | reference |
   242        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   243  
   244      # Place some orders on the book to give liquidity and to move the last price to trigger the stop order
   245      When the parties place the following orders:
   246        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   247        | party3| ETH/DEC19 | sell | 30     | 52    | 0                | TYPE_LIMIT | TIF_GTC | 
   248        | party2| ETH/DEC19 | buy  | 1      | 52    | 1                | TYPE_LIMIT | TIF_GTC | 
   249  
   250      # Stop order should have triggered
   251      Then the stop orders should have the following states
   252        | party  | market id | status           | reference |
   253        | party1 | ETH/DEC19 | STATUS_TRIGGERED | stop1     |
   254  
   255      # Check we have created a trade matching the scaled size of the position
   256      And the following trades should be executed:
   257        | buyer   | seller  | price  | size |
   258        | party1  | party3  | 52     | 15    |
   259  
   260  
   261    Scenario: A linked stop order with position size override and scaling will partially flattened the position when the stop order is triggered (0014-ORDT-129)
   262  
   263      # party1 will start 20 long
   264      When the parties place the following orders:
   265        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   266        | party1| ETH/DEC19 | buy  | 20     | 50    | 0                | TYPE_LIMIT | TIF_GTC | buyorder  |
   267        | party2| ETH/DEC19 | sell | 21     | 50    | 1                | TYPE_LIMIT | TIF_GTC | sellorder |
   268  
   269      # Place a sell position linked stop order with size scaling
   270      When the parties place the following orders:
   271        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage |
   272        | party1| ETH/DEC19 | sell | 2      |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 0.75                        |
   273  
   274      Then the stop orders should have the following states
   275        | party  | market id | status          | reference |
   276        | party1 | ETH/DEC19 | STATUS_PENDING  | stop1     |
   277  
   278      # Now let add some liquidity to the book and move the last price to trigger the stop order
   279      When the parties place the following orders:
   280        | party | market id | side | volume | price | resulting trades | type       | tif     | 
   281        | party2| ETH/DEC19 | buy  | 30     | 48    | 0                | TYPE_LIMIT | TIF_GTC | 
   282        | party3| ETH/DEC19 | sell | 1      | 48    | 1                | TYPE_LIMIT | TIF_GTC | 
   283  
   284      # Stop order should have been triggered
   285      Then the stop orders should have the following states
   286        | party  | market id | status           | reference |
   287        | party1 | ETH/DEC19 | STATUS_TRIGGERED | stop1     |
   288  
   289      # Check we have created a trade matching the scaled size of the position
   290      And the following trades should be executed:
   291        | buyer   | seller  | price  | size |
   292        | party2  | party1  | 48     | 15    |
   293  
   294  
   295    Scenario: A linked stop order with position size override and scaling will be validated for correct scaling value
   296  
   297      # party1 will start 10 long
   298      When the parties place the following orders:
   299        | party | market id | side | volume | price | resulting trades | type       | tif     | reference |
   300        | party1| ETH/DEC19 | buy  | 10     | 50    | 0                | TYPE_LIMIT | TIF_GTC | buyorder  |
   301        | party2| ETH/DEC19 | sell | 11     | 50    | 1                | TYPE_LIMIT | TIF_GTC | sellorder |
   302  
   303      # Place a stop order with invalid size scaling
   304      When the parties place the following orders:
   305        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage | error                                                |
   306        | party1| ETH/DEC19 | sell | 2      |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 0.0                         | stop order size override percentage value is invalid |
   307  
   308      # Place a stop order with invalid size scaling
   309      When the parties place the following orders:
   310        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage | error                                                |
   311        | party1| ETH/DEC19 | sell | 2      |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | 1.000001                    | stop order size override percentage value is invalid |
   312  
   313      # Place a stop order with invalid size scaling
   314      When the parties place the following orders:
   315        | party | market id | side | volume | price | resulting trades | type       | tif     | only   | fb price trigger | reference | fb size override setting | fb size override percentage | error                                                |
   316        | party1| ETH/DEC19 | sell | 2      |  0    | 0                | TYPE_MARKET| TIF_IOC | reduce | 48               | stop1     | POSITION                 | -0.000001                   | stop order size override percentage value is invalid |