From bf9a76cf01dc68780260e1b9b2ca1c2ba5c934ad Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Tue, 21 May 2024 12:38:08 +0100 Subject: [PATCH 1/3] feat: add test for AC 163 stop order in spot market --- .../spot/orders/0014-ORDT-163.feature | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 core/integration/features/spot/orders/0014-ORDT-163.feature diff --git a/core/integration/features/spot/orders/0014-ORDT-163.feature b/core/integration/features/spot/orders/0014-ORDT-163.feature new file mode 100644 index 00000000000..8d07d026470 --- /dev/null +++ b/core/integration/features/spot/orders/0014-ORDT-163.feature @@ -0,0 +1,90 @@ +Feature: Spot market + + Background: + Given time is updated to "2024-01-01T00:00:00Z" + + Given the following network parameters are set: + | name | value | + | network.markPriceUpdateMaximumFrequency | 1s | + | market.value.windowLength | 1h | + | spam.protection.max.stopOrdersPerMarket | 5 | + + Given the following assets are registered: + | id | decimal places | + | ETH | 2 | + | BTC | 2 | + + Given the fees configuration named "fees-config-1": + | maker fee | infrastructure fee | + | 0.01 | 0.03 | + Given the log normal risk model named "lognormal-risk-model-1": + | risk aversion | tau | mu | r | sigma | + | 0.001 | 0.01 | 0 | 0.0 | 1.2 | + And the price monitoring named "price-monitoring-1": + | horizon | probability | auction extension | + | 360000 | 0.999 | 1 | + + And the spot markets: + | id | name | base asset | quote asset | risk model | auction duration | fees | price monitoring | decimal places | position decimal places | sla params | + | BTC/ETH | BTC/ETH | BTC | ETH | lognormal-risk-model-1 | 1 | fees-config-1 | price-monitoring-1 | 2 | 2 | default-basic | + + # setup accounts + Given the parties deposit on asset's general account the following amount: + | party | asset | amount | + | party1 | ETH | 100 | + | party1 | BTC | 11 | + | party2 | ETH | 10000 | + | party2 | BTC | 1000 | + | party3 | ETH | 10000 | + | party3 | BTC | 1000 | + | party4 | BTC | 1000 | + | party5 | BTC | 1000 | + And the average block duration is "1" + + # Place some orders to get out of auction + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | BTC/ETH | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GFA | + | party4 | BTC/ETH | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + + And the opening auction period ends for market "BTC/ETH" + When the network moves ahead "1" blocks + Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "BTC/ETH" + And the mark price should be "1000" for the market "BTC/ETH" + + Scenario:0014-ORDT-163: A trader submitting a stop order wrapping a buy limit order will have the funds required to execute that order locked in the relevant holding account for the quote asset. + + Given the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party1 | BTC/ETH | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | + | party2 | BTC/ETH | buy | 10 | 1000 | 1 | TYPE_LIMIT | TIF_GTC | + # place an order to match with the limit order then check the stop is filled + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party4 | BTC/ETH | sell | 10 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | + + # create party1 stop order + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | + | party1 | BTC/ETH | buy | 50 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | reduce | 1005 | | stop1 | + + # now we trade at 1005, this will breach the trigger + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | BTC/ETH | buy | 1 | 1005 | 0 | TYPE_LIMIT | TIF_GTC | + | party4 | BTC/ETH | sell | 1 | 1005 | 1 | TYPE_LIMIT | TIF_GTC | + + # check that the order was triggered + Then the stop orders should have the following states + | party | market id | status | reference | + | party1 | BTC/ETH | STATUS_TRIGGERED | stop1 | + + +# Then "party1" should have general account balance of "201" for asset "ETH" +# Then "party1" should have general account balance of "1" for asset "BTC" +# Then "party1" should have holding account balance of "0" for asset "BTC" + +# Then "party4" should have general account balance of "18" for asset "ETH" +# Then "party4" should have general account balance of "988" for asset "BTC" +# Then "party4" should have holding account balance of "5" for asset "BTC" + From 920518d315179a2b602df6c86d267a8e5d5a5399 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Tue, 21 May 2024 12:50:24 +0100 Subject: [PATCH 2/3] feat: add test for AC 164 --- .../spot/orders/0014-ORDT-163.feature | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/core/integration/features/spot/orders/0014-ORDT-163.feature b/core/integration/features/spot/orders/0014-ORDT-163.feature index 8d07d026470..ba1df73a921 100644 --- a/core/integration/features/spot/orders/0014-ORDT-163.feature +++ b/core/integration/features/spot/orders/0014-ORDT-163.feature @@ -1,4 +1,4 @@ -Feature: Spot market +Feature: stop order in spot market Background: Given time is updated to "2024-01-01T00:00:00Z" @@ -16,7 +16,7 @@ Feature: Spot market Given the fees configuration named "fees-config-1": | maker fee | infrastructure fee | - | 0.01 | 0.03 | + | 0 | 0 | Given the log normal risk model named "lognormal-risk-model-1": | risk aversion | tau | mu | r | sigma | | 0.001 | 0.01 | 0 | 0.0 | 1.2 | @@ -34,7 +34,7 @@ Feature: Spot market | party1 | ETH | 100 | | party1 | BTC | 11 | | party2 | ETH | 10000 | - | party2 | BTC | 1000 | + | party2 | BTC | 10 | | party3 | ETH | 10000 | | party3 | BTC | 1000 | | party4 | BTC | 1000 | @@ -52,16 +52,15 @@ Feature: Spot market Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "BTC/ETH" And the mark price should be "1000" for the market "BTC/ETH" - Scenario:0014-ORDT-163: A trader submitting a stop order wrapping a buy limit order will have the funds required to execute that order locked in the relevant holding account for the quote asset. - + Scenario:0014-ORDT-163, 0014-ORDT-164: A wrapped buy/sell order will be rejected when triggered if the party doesn't have enough of the required quote asset to cover the order. Given the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | | party1 | BTC/ETH | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | | party2 | BTC/ETH | buy | 10 | 1000 | 1 | TYPE_LIMIT | TIF_GTC | # place an order to match with the limit order then check the stop is filled And the parties place the following orders: - | party | market id | side | volume | price | resulting trades | type | tif | - | party4 | BTC/ETH | sell | 10 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party4 | BTC/ETH | sell | 10 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | p4-sell | # create party1 stop order And the parties place the following orders: @@ -79,12 +78,31 @@ Feature: Spot market | party | market id | status | reference | | party1 | BTC/ETH | STATUS_TRIGGERED | stop1 | + Then "party1" should have general account balance of "200" for asset "ETH" + Then "party1" should have general account balance of "1" for asset "BTC" + Then "party1" should have holding account balance of "0" for asset "BTC" + + Then the parties amend the following orders: + | party | reference | price | size delta | tif | + | party4 | p4-sell | 1010 | -10 | TIF_GTC | + + # create party2 stop order + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | + | party2 | BTC/ETH | sell | 50 | 1015 | 0 | TYPE_LIMIT | TIF_GTC | reduce | 1020 | | stop2 | + + # now we trade at 1005, this will breach the trigger + When the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | + | party3 | BTC/ETH | buy | 1 | 1020 | 0 | TYPE_LIMIT | TIF_GTC | + | party4 | BTC/ETH | sell | 1 | 1020 | 1 | TYPE_LIMIT | TIF_GTC | + + # check that the order was triggered + Then the stop orders should have the following states + | party | market id | status | reference | + | party2 | BTC/ETH | STATUS_TRIGGERED | stop2 | -# Then "party1" should have general account balance of "201" for asset "ETH" -# Then "party1" should have general account balance of "1" for asset "BTC" -# Then "party1" should have holding account balance of "0" for asset "BTC" + Then "party2" should have general account balance of "9900" for asset "ETH" + Then "party2" should have general account balance of "20" for asset "BTC" -# Then "party4" should have general account balance of "18" for asset "ETH" -# Then "party4" should have general account balance of "988" for asset "BTC" -# Then "party4" should have holding account balance of "5" for asset "BTC" From 6127ab1867dc7c91f38e441d23ba1ff7da73d0a1 Mon Sep 17 00:00:00 2001 From: Jiajia-Cui Date: Tue, 21 May 2024 13:57:53 +0100 Subject: [PATCH 3/3] feat: add comments from Charlie --- .../spot/orders/0014-ORDT-163.feature | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/core/integration/features/spot/orders/0014-ORDT-163.feature b/core/integration/features/spot/orders/0014-ORDT-163.feature index ba1df73a921..7ec687b10ad 100644 --- a/core/integration/features/spot/orders/0014-ORDT-163.feature +++ b/core/integration/features/spot/orders/0014-ORDT-163.feature @@ -53,19 +53,16 @@ Feature: stop order in spot market And the mark price should be "1000" for the market "BTC/ETH" Scenario:0014-ORDT-163, 0014-ORDT-164: A wrapped buy/sell order will be rejected when triggered if the party doesn't have enough of the required quote asset to cover the order. - Given the parties place the following orders: - | party | market id | side | volume | price | resulting trades | type | tif | - | party1 | BTC/ETH | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | - | party2 | BTC/ETH | buy | 10 | 1000 | 1 | TYPE_LIMIT | TIF_GTC | + # place an order to match with the limit order then check the stop is filled And the parties place the following orders: | party | market id | side | volume | price | resulting trades | type | tif | reference | - | party4 | BTC/ETH | sell | 10 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | p4-sell | + | party4 | BTC/ETH | sell | 50 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | p4-sell | # create party1 stop order And the parties place the following orders: - | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | - | party1 | BTC/ETH | buy | 50 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | reduce | 1005 | | stop1 | + | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | + | party1 | BTC/ETH | buy | 50 | 1010 | 0 | TYPE_LIMIT | TIF_GTC | | 1005 | | stop1 | # now we trade at 1005, this will breach the trigger When the parties place the following orders: @@ -78,18 +75,22 @@ Feature: stop order in spot market | party | market id | status | reference | | party1 | BTC/ETH | STATUS_TRIGGERED | stop1 | - Then "party1" should have general account balance of "200" for asset "ETH" - Then "party1" should have general account balance of "1" for asset "BTC" - Then "party1" should have holding account balance of "0" for asset "BTC" + Then "party1" should have general account balance of "100" for asset "ETH" + Then "party1" should have general account balance of "11" for asset "BTC" + + And the parties cancel the following orders: + | party | reference | + | party4 | p4-sell | - Then the parties amend the following orders: - | party | reference | price | size delta | tif | - | party4 | p4-sell | 1010 | -10 | TIF_GTC | + # place an order to match with the limit order then check the stop is filled + And the parties place the following orders: + | party | market id | side | volume | price | resulting trades | type | tif | reference | + | party3 | BTC/ETH | buy | 50 | 1015 | 0 | TYPE_LIMIT | TIF_GTC | p4-sell | # create party2 stop order And the parties place the following orders: - | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | - | party2 | BTC/ETH | sell | 50 | 1015 | 0 | TYPE_LIMIT | TIF_GTC | reduce | 1020 | | stop2 | + | party | market id | side | volume | price | resulting trades | type | tif | only | ra price trigger | error | reference | + | party2 | BTC/ETH | sell | 50 | 1015 | 0 | TYPE_LIMIT | TIF_GTC | | 1020 | | stop2 | # now we trade at 1005, this will breach the trigger When the parties place the following orders: @@ -102,7 +103,7 @@ Feature: stop order in spot market | party | market id | status | reference | | party2 | BTC/ETH | STATUS_TRIGGERED | stop2 | - Then "party2" should have general account balance of "9900" for asset "ETH" - Then "party2" should have general account balance of "20" for asset "BTC" + Then "party2" should have general account balance of "10000" for asset "ETH" + Then "party2" should have general account balance of "10" for asset "BTC"