Skip to content

Commit

Permalink
Set status of non-persistent orders that triggered price monitoring t…
Browse files Browse the repository at this point in the history
…o STOPPED, add integration test to replace system test
  • Loading branch information
EVODelavega committed May 3, 2021
1 parent 431fcf8 commit cc60055
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,10 @@ func (m *Market) unregisterAndReject(ctx context.Context, order *types.Order, er
order.UpdatedAt = m.currentTime.UnixNano()
order.Status = types.Order_STATUS_REJECTED
if oerr, ok := types.IsOrderError(err); ok {
// the order wasn't invalid, so stopped is a better status, rather than rejected.
if oerr == types.OrderError_ORDER_ERROR_NON_PERSISTENT_ORDER_OUT_OF_PRICE_BOUNDS {
order.Status = types.Order_STATUS_STOPPED
}
order.Reason = oerr
} else {
// should not happened but still...
Expand Down
76 changes: 76 additions & 0 deletions integration/features/3362-failing-system-tests.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Feature: Replicate failing system tests after changes to price monitoring (not triggering with FOK orders, auction duration)

Background:
Given time is updated to "2020-10-16T00:00:00Z"
And the price monitoring updated every "4" seconds named "my-price-monitoring":
| horizon | probability | auction extension |
| 5 | 0.95 | 6 |
| 10 | 0.99 | 8 |
And the log normal risk model named "my-log-normal-risk-model":
| risk aversion | tau | mu | r | sigma |
| 0.000001 | 0.00011407711613050422 | 0 | 0.016 | 2.0 |
And the markets:
| id | quote name | asset | maturity date | risk model | margin calculator | auction duration | fees | price monitoring | oracle config |
| ETH/DEC20 | ETH | ETH | 2020-12-31T23:59:59Z | my-log-normal-risk-model | default-margin-calculator | 1 | default-none | my-price-monitoring | default-eth-for-future |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 1 |
And the oracles broadcast data signed with "0xDEADBEEF":
| name | value |
| prices.ETH.value | 42 |
And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC20"

Scenario: Replicate test called test_TriggerWithMarketOrder
Given the traders deposit on asset's general account the following amount:
| trader | asset | amount |
| trader1 | ETH | 100000000 |
| trader2 | ETH | 100000000 |
| trader3 | ETH | 100000000 |
| traderLP | ETH | 100000000 |
| aux | ETH | 100000000 |

When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif |
| trader1 | ETH/DEC20 | buy | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GFA |
| trader2 | ETH/DEC20 | sell | 1 | 100000 | 0 | TYPE_LIMIT | TIF_GFA |
| trader1 | ETH/DEC20 | buy | 5 | 95000 | 0 | TYPE_LIMIT | TIF_GTC |
| trader2 | ETH/DEC20 | sell | 5 | 107000 | 0 | TYPE_LIMIT | TIF_GTC |
And the traders submit the following liquidity provision:
| id | party | market id | commitment amount | fee | order side | order reference | order proportion | order offset |
| lp1 | trader1 | ETH/DEC20 | 16000000 | 0.3 | buy | BID | 2 | -10 |
| lp1 | trader1 | ETH/DEC20 | 16000000 | 0.3 | sell | ASK | 13 | 10 |
Then the mark price should be "0" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_OPENING_AUCTION" for the market "ETH/DEC20"

When the opening auction period ends for market "ETH/DEC20"
Then the mark price should be "100000" for the market "ETH/DEC20"
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"

## price bounds are 99771 to 100290
When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif |
| trader1 | ETH/DEC20 | buy | 1 | 100150 | 0 | TYPE_LIMIT | TIF_GTC |
| trader2 | ETH/DEC20 | sell | 1 | 100150 | 1 | TYPE_LIMIT | TIF_GTC |
# | trader1 | ETH/DEC20 | buy | 1 | 100448 | 0 | TYPE_LIMIT | TIF_GTC |
# | trader2 | ETH/DEC20 | sell | 1 | 100448 | 1 | TYPE_LIMIT | TIF_GTC |
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the mark price should be "100150" for the market "ETH/DEC20"

When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif |
| trader1 | ETH/DEC20 | buy | 2 | 100213 | 0 | TYPE_LIMIT | TIF_GTC |
| trader1 | ETH/DEC20 | buy | 1 | 100050 | 0 | TYPE_LIMIT | TIF_GTC |
# Now place a FOK order that would trigger a price auction (trader 1 has a buy at 95,000 on the book
And the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif |
| trader2 | ETH/DEC20 | sell | 3 | 0 | 0 | TYPE_MARKET | TIF_FOK |
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the mark price should be "100150" for the market "ETH/DEC20"

## Now place the order for the same volume again, but set price to 100,000 -> the buy at 95,000 doesn't uncross
## We'll see the mark price move as we've uncrossed with the orders at 100213 and 100050 we've just placed
When the traders place the following orders:
| trader | market id | side | volume | price | resulting trades | type | tif |
| trader2 | ETH/DEC20 | sell | 3 | 100000 | 2 | TYPE_LIMIT | TIF_GTC |
Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC20"
And the mark price should be "100050" for the market "ETH/DEC20"

0 comments on commit cc60055

Please sign in to comment.