From 36d40dec70c254a2e9dfe05e69b0d2f26cd6d29b Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 12:59:49 -0400 Subject: [PATCH 01/12] spell check manual tests --- testing/manual/spreader_misc/fractional_hedging.txt | 8 ++++---- testing/manual/spreader_misc/implied_vs_direct.txt | 6 +++--- testing/manual/spreader_misc/n_legs.txt | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/testing/manual/spreader_misc/fractional_hedging.txt b/testing/manual/spreader_misc/fractional_hedging.txt index ea0798e65..c0f218383 100644 --- a/testing/manual/spreader_misc/fractional_hedging.txt +++ b/testing/manual/spreader_misc/fractional_hedging.txt @@ -2,9 +2,9 @@ This test verifies that fractional hedges work. That is, when a fill in a quotin not equate to one full contract in the hedging leg, we accumulate the unhedged delta, until we can send one or more hedging contracts. -1. Create a new synthetic spread. For the legs choose SIF9 and SIH9 (if you dont +1. Create a new synthetic spread. For the legs choose SIF9 and SIH9 (if you don't have these contracts, other contracts can be chosen too) and for the quantities choose 1 and -1.5 -respectively (and same for the Price multiplier). +respectively (and same for the Price multiplier). Enable quoting for SIH9, and disable all quoting, pre-hedge and post-hedge parameters. Name the synthetic SIF9-1.5SIH9. @@ -18,13 +18,13 @@ to enter orders). The quoting order will lean against this. 4. Verify that a 15 lot quoting order is sent for SIH9 at 19.935. 5. Now we will start filling the quoting order and verify the hedges. A 1 lot fill in the -quoting leg means a 2/3 contract in the hedging leg. Since we can not send 2/3 constracts, +quoting leg means a 2/3 contract in the hedging leg. Since we can not send 2/3 contracts, we will add it to the "unhedged delta" till the unhedged delta > 1, and then we will send one or more orders to get the unhedged delta < 1. Force quoting fills based on the left most column (by lifting the quoting offer) and verify that hedge orders of size "hedge_order_sent" (3rd column) are sent as a result. -The "unhedged_delta" column shows the unhedged delta immediatly after the quoting fill +The "unhedged_delta" column shows the unhedged delta immediately after the quoting fill and the "remaining_unhedged_delta" column is the unhedged delta after the hedge order has been sent. You can check the hedge orders being sent easily by looking at the order reduction diff --git a/testing/manual/spreader_misc/implied_vs_direct.txt b/testing/manual/spreader_misc/implied_vs_direct.txt index 6acf12cb2..74fbef376 100644 --- a/testing/manual/spreader_misc/implied_vs_direct.txt +++ b/testing/manual/spreader_misc/implied_vs_direct.txt @@ -10,7 +10,7 @@ ExchangeSim { } } -1. Open up the mview and find a security with with both direct and implied markets, on the ask side. +1. Open up the mview and find a security with with both direct and implied markets, on the ask side. Make sure those markets are stable and you can rely on them. 2. Create a synthetic with the security in 1. being the hedge leg (buy) and choose a quoting @@ -19,11 +19,11 @@ use "Merged" 3. Disable all spreader params. -4. Now enter a spreader order so that it doesnt get filled immediatly. Note the quoting order. +4. Now enter a spreader order so that it doesn't get filled immediately. Note the quoting order. quoting leg price = hedge_price - spreader_price. hedge_price is where it can buy the hedge order (which since its a buy will be on the ask side of the hedging market). -Make sure thta its correct and its using the merged book in the hedging market. +Make sure that its correct and its using the merged book in the hedging market. 5. Cancel the order and change the spreader so its using Direct prices. Repeat 4, and make sure its using direct price on the hedging market. \ No newline at end of file diff --git a/testing/manual/spreader_misc/n_legs.txt b/testing/manual/spreader_misc/n_legs.txt index dd596a8dd..edf10eab2 100644 --- a/testing/manual/spreader_misc/n_legs.txt +++ b/testing/manual/spreader_misc/n_legs.txt @@ -5,8 +5,8 @@ with 1 quoting leg. 1. Create a 4 legged synthetic spread with legs SIF9, SIH9, SIK9, SIN9, with leg quantities and price multipliers of 1,1,1 and -1 respectively. Leg SIN9 is the only quoting leg. -Disable all Quote, Pre-Hedge and Post-Hedge paramaters (leg contracts are arbitrary, so if you -dont have those contracts, choose any set of 4 contracts). +Disable all Quote, Pre-Hedge and Post-Hedge parameters (leg contracts are arbitrary, so if you +don't have those contracts, choose any set of 4 contracts). 2. Enter a synthetic buy order of 10 lots at 40.00. The ladders will most likely be empty, so use the market view to enter orders. @@ -16,7 +16,7 @@ Now enter: SIH9 10 lot sell @ 19.950 SIK9 10 lot sell @ 20.200 -There should still be no quoting order for SIN9 since the SIF9 hedge leg still doesnt have a market. +There should still be no quoting order for SIN9 since the SIF9 hedge leg still doesn't have a market. Now Enter: SIF9 1 lot sell @ 20.000 From 533e688d1a75f28c014f81b565a3c9b6cfe5d8f7 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 13:09:15 -0400 Subject: [PATCH 02/12] SPARK-2438: init spreader_lean_qty_factor test --- src/client/spark_test/System/SpreaderTests.cs | 5 +++ .../spreader_lean_qty_factor.sh | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh diff --git a/src/client/spark_test/System/SpreaderTests.cs b/src/client/spark_test/System/SpreaderTests.cs index 10a8a42d5..07462ed21 100644 --- a/src/client/spark_test/System/SpreaderTests.cs +++ b/src/client/spark_test/System/SpreaderTests.cs @@ -118,6 +118,11 @@ namespace bts.tests } + [Test(Timeout = 30)] + public async Task spreader_lean_qty_factor() { + + } + private async Task<(Boolean, OrderRecordImmutable?)> verify_child_order_status(uint parent_order_key, OrderStatus expected_status) { var order = await get_order(ordi => ordi.ParentKey == parent_order_key && ordi.State.Status == expected_status); return (order.HasValue && order.Value.State.Status == expected_status, order); diff --git a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh new file mode 100644 index 000000000..28913e469 --- /dev/null +++ b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +rm -r ~/sparkdata/data/databases/ > /dev/null + +mv ~/sparkdata/conf/spark.conf ~/sparkdata/conf/spark.conf.bak +cat << EOF > ~/sparkdata/conf/spark.conf + ExchangeSim { + value { + merge_with_md:false + } + } + Logging { + value { + console { default_level: "Error" } + syslog { default_level: "Error" } + file { default_level: "Error" } + } +} +EOF + + +nohup ./sparkd run & +pid=$! +echo "sparkd pid: " $pid + +echo "sleeping for 120 seconds..." +sleep 120 + +dotnet sparkcmd.dll test spreader_lean_qty_factor + +kill $pid +mv ~/sparkdata/conf/spark.conf.bak ~/sparkdata/conf/spark.conf \ No newline at end of file From c0d097cb40e6b6f6852ee416f70a30ba82c95661 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 13:26:53 -0400 Subject: [PATCH 03/12] SPARK-2438: spreader_lean_qty_factor test setup --- src/client/spark_test/System/SpreaderTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/client/spark_test/System/SpreaderTests.cs b/src/client/spark_test/System/SpreaderTests.cs index 07462ed21..92888b532 100644 --- a/src/client/spark_test/System/SpreaderTests.cs +++ b/src/client/spark_test/System/SpreaderTests.cs @@ -120,6 +120,16 @@ namespace bts.tests [Test(Timeout = 30)] public async Task spreader_lean_qty_factor() { + Assert.IsTrue(await TestUtils.test_for_system_ready(_context, TimeSpan.FromMinutes(5)), "System is not ready"); + + string test_symbol = "SI";// don't use ES, the prices will be rounded to the same number and the result will be off + var test_user = (name: "bts", id: 1u); + var test_account = (name: "ACC A", id: 1u); + + (SecurityImmutable s1, SecurityImmutable s2) test_securities = await SpreaderUtilities.get_securities_for_common_setup_one(_md_relay, test_symbol); + + var setup_product = await SpreaderUtilities.common_setup_one(_order_service, _synthetic_service, test_securities, test_account, test_user); + } From aef8e2dbb10ed09e118ce559c7e5ab0ac540b6be Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 12:59:49 -0400 Subject: [PATCH 04/12] spell check manual tests --- testing/manual/spreader_misc/fractional_hedging.txt | 8 ++++---- testing/manual/spreader_misc/implied_vs_direct.txt | 6 +++--- testing/manual/spreader_misc/n_legs.txt | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/testing/manual/spreader_misc/fractional_hedging.txt b/testing/manual/spreader_misc/fractional_hedging.txt index ea0798e65..c0f218383 100644 --- a/testing/manual/spreader_misc/fractional_hedging.txt +++ b/testing/manual/spreader_misc/fractional_hedging.txt @@ -2,9 +2,9 @@ This test verifies that fractional hedges work. That is, when a fill in a quotin not equate to one full contract in the hedging leg, we accumulate the unhedged delta, until we can send one or more hedging contracts. -1. Create a new synthetic spread. For the legs choose SIF9 and SIH9 (if you dont +1. Create a new synthetic spread. For the legs choose SIF9 and SIH9 (if you don't have these contracts, other contracts can be chosen too) and for the quantities choose 1 and -1.5 -respectively (and same for the Price multiplier). +respectively (and same for the Price multiplier). Enable quoting for SIH9, and disable all quoting, pre-hedge and post-hedge parameters. Name the synthetic SIF9-1.5SIH9. @@ -18,13 +18,13 @@ to enter orders). The quoting order will lean against this. 4. Verify that a 15 lot quoting order is sent for SIH9 at 19.935. 5. Now we will start filling the quoting order and verify the hedges. A 1 lot fill in the -quoting leg means a 2/3 contract in the hedging leg. Since we can not send 2/3 constracts, +quoting leg means a 2/3 contract in the hedging leg. Since we can not send 2/3 contracts, we will add it to the "unhedged delta" till the unhedged delta > 1, and then we will send one or more orders to get the unhedged delta < 1. Force quoting fills based on the left most column (by lifting the quoting offer) and verify that hedge orders of size "hedge_order_sent" (3rd column) are sent as a result. -The "unhedged_delta" column shows the unhedged delta immediatly after the quoting fill +The "unhedged_delta" column shows the unhedged delta immediately after the quoting fill and the "remaining_unhedged_delta" column is the unhedged delta after the hedge order has been sent. You can check the hedge orders being sent easily by looking at the order reduction diff --git a/testing/manual/spreader_misc/implied_vs_direct.txt b/testing/manual/spreader_misc/implied_vs_direct.txt index 6acf12cb2..74fbef376 100644 --- a/testing/manual/spreader_misc/implied_vs_direct.txt +++ b/testing/manual/spreader_misc/implied_vs_direct.txt @@ -10,7 +10,7 @@ ExchangeSim { } } -1. Open up the mview and find a security with with both direct and implied markets, on the ask side. +1. Open up the mview and find a security with with both direct and implied markets, on the ask side. Make sure those markets are stable and you can rely on them. 2. Create a synthetic with the security in 1. being the hedge leg (buy) and choose a quoting @@ -19,11 +19,11 @@ use "Merged" 3. Disable all spreader params. -4. Now enter a spreader order so that it doesnt get filled immediatly. Note the quoting order. +4. Now enter a spreader order so that it doesn't get filled immediately. Note the quoting order. quoting leg price = hedge_price - spreader_price. hedge_price is where it can buy the hedge order (which since its a buy will be on the ask side of the hedging market). -Make sure thta its correct and its using the merged book in the hedging market. +Make sure that its correct and its using the merged book in the hedging market. 5. Cancel the order and change the spreader so its using Direct prices. Repeat 4, and make sure its using direct price on the hedging market. \ No newline at end of file diff --git a/testing/manual/spreader_misc/n_legs.txt b/testing/manual/spreader_misc/n_legs.txt index dd596a8dd..edf10eab2 100644 --- a/testing/manual/spreader_misc/n_legs.txt +++ b/testing/manual/spreader_misc/n_legs.txt @@ -5,8 +5,8 @@ with 1 quoting leg. 1. Create a 4 legged synthetic spread with legs SIF9, SIH9, SIK9, SIN9, with leg quantities and price multipliers of 1,1,1 and -1 respectively. Leg SIN9 is the only quoting leg. -Disable all Quote, Pre-Hedge and Post-Hedge paramaters (leg contracts are arbitrary, so if you -dont have those contracts, choose any set of 4 contracts). +Disable all Quote, Pre-Hedge and Post-Hedge parameters (leg contracts are arbitrary, so if you +don't have those contracts, choose any set of 4 contracts). 2. Enter a synthetic buy order of 10 lots at 40.00. The ladders will most likely be empty, so use the market view to enter orders. @@ -16,7 +16,7 @@ Now enter: SIH9 10 lot sell @ 19.950 SIK9 10 lot sell @ 20.200 -There should still be no quoting order for SIN9 since the SIF9 hedge leg still doesnt have a market. +There should still be no quoting order for SIN9 since the SIF9 hedge leg still doesn't have a market. Now Enter: SIF9 1 lot sell @ 20.000 From a07bc152d1d59df30f3cdd541ec3efa83af496b6 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 13:09:15 -0400 Subject: [PATCH 05/12] SPARK-2438: init spreader_lean_qty_factor test --- src/client/spark_test/System/SpreaderTests.cs | 5 +++ .../spreader_lean_qty_factor.sh | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh diff --git a/src/client/spark_test/System/SpreaderTests.cs b/src/client/spark_test/System/SpreaderTests.cs index 0fe39194f..394fc46c1 100644 --- a/src/client/spark_test/System/SpreaderTests.cs +++ b/src/client/spark_test/System/SpreaderTests.cs @@ -120,6 +120,11 @@ namespace bts.tests } + [Test(Timeout = 30)] + public async Task spreader_lean_qty_factor() { + + } + private async Task<(Boolean, OrderRecordImmutable?)> verify_child_order_status(uint parent_order_key, OrderStatus expected_status) { var order = await get_order(ordi => ordi.ParentKey == parent_order_key && ordi.State.Status == expected_status); return (order.HasValue && order.Value.State.Status == expected_status, order); diff --git a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh new file mode 100644 index 000000000..28913e469 --- /dev/null +++ b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +rm -r ~/sparkdata/data/databases/ > /dev/null + +mv ~/sparkdata/conf/spark.conf ~/sparkdata/conf/spark.conf.bak +cat << EOF > ~/sparkdata/conf/spark.conf + ExchangeSim { + value { + merge_with_md:false + } + } + Logging { + value { + console { default_level: "Error" } + syslog { default_level: "Error" } + file { default_level: "Error" } + } +} +EOF + + +nohup ./sparkd run & +pid=$! +echo "sparkd pid: " $pid + +echo "sleeping for 120 seconds..." +sleep 120 + +dotnet sparkcmd.dll test spreader_lean_qty_factor + +kill $pid +mv ~/sparkdata/conf/spark.conf.bak ~/sparkdata/conf/spark.conf \ No newline at end of file From eb97fd045aacee1090f78204bc40847b36c080e2 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 13 May 2019 13:26:53 -0400 Subject: [PATCH 06/12] SPARK-2438: spreader_lean_qty_factor test setup --- src/client/spark_test/System/SpreaderTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/client/spark_test/System/SpreaderTests.cs b/src/client/spark_test/System/SpreaderTests.cs index 394fc46c1..af23a7fed 100644 --- a/src/client/spark_test/System/SpreaderTests.cs +++ b/src/client/spark_test/System/SpreaderTests.cs @@ -122,6 +122,16 @@ namespace bts.tests [Test(Timeout = 30)] public async Task spreader_lean_qty_factor() { + Assert.IsTrue(await TestUtils.test_for_system_ready(_context, TimeSpan.FromMinutes(5)), "System is not ready"); + + string test_symbol = "SI";// don't use ES, the prices will be rounded to the same number and the result will be off + var test_user = (name: "bts", id: 1u); + var test_account = (name: "ACC A", id: 1u); + + (SecurityImmutable s1, SecurityImmutable s2) test_securities = await SpreaderUtilities.get_securities_for_common_setup_one(_md_relay, test_symbol); + + var setup_product = await SpreaderUtilities.common_setup_one(_order_service, _synthetic_service, test_securities, test_account, test_user); + } From 4490ac303e594e25bb03c2c419f9d8c0bc00a337 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Wed, 12 Jun 2019 15:41:16 -0400 Subject: [PATCH 07/12] SPARK-2438: Lean Qty test --- src/client/spark_test/System/SpreaderTests.cs | 158 +++++++++++++++++- src/client/spark_test/Utils/OrderUtilities.cs | 6 +- .../spark_test/Utils/SpreaderUtilities.cs | 28 +++- 3 files changed, 179 insertions(+), 13 deletions(-) diff --git a/src/client/spark_test/System/SpreaderTests.cs b/src/client/spark_test/System/SpreaderTests.cs index af23a7fed..4116f9b4a 100644 --- a/src/client/spark_test/System/SpreaderTests.cs +++ b/src/client/spark_test/System/SpreaderTests.cs @@ -76,7 +76,7 @@ namespace bts.tests ); var spreader_order1_response = await OrderUtilities.send_order(_order_service, order1_def, -0.30, 1); - Assert.IsTrue(spreader_order1_response.success, "Failed to send first spreader order"); + Assert.IsTrue(spreader_order1_response.success, "Failed to send spreader order"); var (spreader_order_is_working, working_spreader_order1) = await verify_order_status(spreader_order1_response.value.OrderKey, OrderStatus.Working); Assert.IsTrue(spreader_order_is_working, "Spreader order is not Working"); @@ -120,11 +120,11 @@ namespace bts.tests } - [Test(Timeout = 30)] + [Test(Timeout = 300000)] public async Task spreader_lean_qty_factor() { - Assert.IsTrue(await TestUtils.test_for_system_ready(_context, TimeSpan.FromMinutes(5)), "System is not ready"); + await setup_spreader_tests(); - string test_symbol = "SI";// don't use ES, the prices will be rounded to the same number and the result will be off + string test_symbol = "SI"; var test_user = (name: "bts", id: 1u); var test_account = (name: "ACC A", id: 1u); @@ -132,6 +132,141 @@ namespace bts.tests var setup_product = await SpreaderUtilities.common_setup_one(_order_service, _synthetic_service, test_securities, test_account, test_user); + var order1_def = OrderDefinitionUtilities.create_spreader_order_def( + setup_product.synthetic.security, + Side.Buy, + setup_product.synthetic.strategy, + test_account, + test_user + ); + + var spreader_order1_response = await OrderUtilities.send_order(_order_service, order1_def, -0.30, 1); + Assert.IsTrue(spreader_order1_response.success, "Failed to send spreader order"); + + var (spreader_order_is_working, working_spreader_order1) = await verify_order_status(spreader_order1_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(spreader_order_is_working, "Spreader order is not Working"); + + var (quoting_order_is_working, working_quoting_order) = await verify_child_order_status(spreader_order1_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(quoting_order_is_working, "Order is not Working"); + Assert.IsTrue(working_quoting_order.Value.State.Price == 18.6, "Quoting order has the wrong price"); + + Assert.IsTrue(await OrderUtilities.cancel_orders(_order_service, new List {working_spreader_order1.Value}), "Failed to cancel order"); + + var (quoting_order_is_canceled, canceled_quoting_order) = await verify_child_order_status(spreader_order1_response.value.OrderKey, OrderStatus.Canceled); + Assert.IsTrue(quoting_order_is_canceled, "Quoting order may not have been canceled"); + + // change the synthetic + var hedge_leg = setup_product.synthetic.strategy.LegParamsMap.Where(m => !m.Value.IsActiveQuoting).TryFirst(); + Assert.IsTrue(hedge_leg.HasValue, "you need more legs"); + + foreach(var key in setup_product.synthetic.strategy.LegParamsMap.Keys) { + if(!setup_product.synthetic.strategy.LegParamsMap[key].IsActiveQuoting) { + setup_product.synthetic.strategy.LegParamsMap[key].QuoteParams.LeanQuantityRatio = 2d; + break; + } + } + + Assert.IsTrue(await SpreaderUtilities.save_strategy(_synthetic_service, setup_product.synthetic.security.Id, (ExecutionStrategyImmutable) setup_product.synthetic.strategy), "Failed to save strategy"); + + var order2_def = OrderDefinitionUtilities.create_spreader_order_def( + setup_product.synthetic.security, + Side.Buy, + setup_product.synthetic.strategy, + test_account, + test_user + ); + + var spreader_order2_response = await OrderUtilities.send_order(_order_service, order2_def, -0.30, 1); + Assert.IsTrue(spreader_order2_response.success, "Failed to send spreader order"); + + var (spreader_order2_is_working, working_spreader_order2) = await verify_order_status(spreader_order2_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(spreader_order2_is_working, "Spreader order is not Working"); + + var (quoting_order2_is_working, working_quoting_order2) = await verify_child_order_status(spreader_order2_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(quoting_order2_is_working, "Order is not Working"); + Assert.IsTrue(working_quoting_order2.Value.State.Price == 18.61, "Quoting order has the wrong price"); + + Assert.IsTrue(await OrderUtilities.cancel_orders(_order_service, new List {working_spreader_order2.Value}), "Failed to cancel order"); + + var (quoting_order2_is_canceled, canceled_quoting_order2) = await verify_child_order_status(spreader_order2_response.value.OrderKey, OrderStatus.Canceled); + Assert.IsTrue(quoting_order2_is_canceled, "Quoting order may not have been canceled"); + + + // Order 3 + foreach(var key in setup_product.synthetic.strategy.LegParamsMap.Keys) { + if(!setup_product.synthetic.strategy.LegParamsMap[key].IsActiveQuoting) { + setup_product.synthetic.strategy.LegParamsMap[key].QuoteParams.LeanQuantityRatio = 4d; + break; + } + } + + Assert.IsTrue(await SpreaderUtilities.save_strategy(_synthetic_service, setup_product.synthetic.security.Id, (ExecutionStrategyImmutable) setup_product.synthetic.strategy), "Failed to save strategy"); + + var order3_def = OrderDefinitionUtilities.create_spreader_order_def( + setup_product.synthetic.security, + Side.Buy, + setup_product.synthetic.strategy, + test_account, + test_user + ); + + var spreader_order3_response = await OrderUtilities.send_order(_order_service, order3_def, -0.30, 1); + Assert.IsTrue(spreader_order3_response.success, "Failed to send spreader order"); + + var (spreader_order3_is_working, working_spreader_order3) = await verify_order_status(spreader_order3_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(spreader_order3_is_working, "Spreader order is not Working"); + + var (quoting_order3_is_working, working_quoting_order3) = await verify_child_order_status(spreader_order3_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(quoting_order3_is_working, "Order is not Working"); + Assert.IsTrue(working_quoting_order3.Value.State.Price == 18.63, "Quoting order has the wrong price"); + + Assert.IsTrue(await OrderUtilities.cancel_orders(_order_service, new List {working_spreader_order3.Value}), "Failed to cancel order"); + + var (quoting_order3_is_canceled, canceled_quoting_order3) = await verify_child_order_status(spreader_order3_response.value.OrderKey, OrderStatus.Canceled); + Assert.IsTrue(quoting_order3_is_canceled, "Quoting order may not have been canceled"); + + // Order 4 + foreach(var key in setup_product.synthetic.strategy.LegParamsMap.Keys) { + if(!setup_product.synthetic.strategy.LegParamsMap[key].IsActiveQuoting) { + setup_product.synthetic.strategy.LegParamsMap[key].QuoteParams.LeanQuantityRatio = 5d; + break; + } + } + + Assert.IsTrue(await SpreaderUtilities.save_strategy(_synthetic_service, setup_product.synthetic.security.Id, (ExecutionStrategyImmutable) setup_product.synthetic.strategy), "Failed to save strategy"); + + var order4_def = OrderDefinitionUtilities.create_spreader_order_def( + setup_product.synthetic.security, + Side.Buy, + setup_product.synthetic.strategy, + test_account, + test_user + ); + + var spreader_order4_response = await OrderUtilities.send_order(_order_service, order4_def, -0.30, 1); + Assert.IsTrue(spreader_order4_response.success, "Failed to send spreader order"); + + var (spreader_order4_is_working, working_spreader_order4) = await verify_order_status(spreader_order4_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(spreader_order4_is_working, "Spreader order is not Working"); + + var no_quoting_order4 = await get_order(ord => ord.ParentKey == spreader_order4_response.value.OrderKey, TimeSpan.FromSeconds(10)); + Assert.IsFalse(no_quoting_order4.HasValue, "There should not have been a quoting order here..."); + + OrderRecordImmutable order_from_book = setup_product.book.Where(ordi => ordi.State.Price == 18.30).First(); + var mod_resp = await OrderUtilities.modify_order(_order_service, order_from_book, 2); + Assert.IsTrue(mod_resp.success, "Order size was not changed"); + + var (quoting_order4_is_working, working_quoting_order4) = await verify_child_order_status(spreader_order4_response.value.OrderKey, OrderStatus.Working); + Assert.IsTrue(quoting_order4_is_working, "Order is not Working"); + Assert.IsTrue(working_quoting_order4.Value.State.Price == 18.63, "Quoting order has the wrong price"); + + var mod_resp2 = await OrderUtilities.modify_order(_order_service, order_from_book, 1); + Assert.IsTrue(mod_resp.success, "Order size was not changed"); + + var (quoting_order5_is_canceled, canceled_quoting_order5) = await verify_child_order_status(spreader_order4_response.value.OrderKey, OrderStatus.Canceled); + Assert.IsTrue(quoting_order5_is_canceled, "Order was not canceld"); + + Assert.IsTrue(await OrderUtilities.cancel_orders(_order_service, new List {working_spreader_order4.Value}), "Failed to cancel order"); } @@ -155,13 +290,22 @@ namespace bts.tests return order.HasValue && (Math.Truncate(order.Value.State.Price * precision) == precision * expected_price); } - private async Task get_order(Func predicate) + private async Task get_order(Func predicate, TimeSpan? timeout = null) { + if(timeout == null){ + timeout = TimeSpan.FromSeconds(60); + } var orders = await OrderUtilities.wait_for_filtered_orders(_order_service, o => o.Where(predicate).Count() > 0, ord => ord.Where(predicate), - TimeSpan.FromSeconds(30)); - return orders.result.TryFirst(); + timeout); + if(orders.result != null) { + return orders.result.TryFirst(); + } + else { + return null; + } + } diff --git a/src/client/spark_test/Utils/OrderUtilities.cs b/src/client/spark_test/Utils/OrderUtilities.cs index 031484a5c..ab89a0f83 100644 --- a/src/client/spark_test/Utils/OrderUtilities.cs +++ b/src/client/spark_test/Utils/OrderUtilities.cs @@ -75,6 +75,10 @@ namespace bts.tests }); var tr = await tcs.Task.timeout(timeout.Value); sub.Dispose(); + if(tr.result == null) { + Console.WriteLine("Timed out while retreving orders."); + } + return tr; } @@ -124,7 +128,7 @@ namespace bts.tests } /// - /// We should replace with something like the OrderDataHeler from the Spark project. + /// We should replace with something like the OrderDataHelper from the Spark project. /// public static class OrderDefinitionUtilities { diff --git a/src/client/spark_test/Utils/SpreaderUtilities.cs b/src/client/spark_test/Utils/SpreaderUtilities.cs index db2f830f6..5de24e9a6 100644 --- a/src/client/spark_test/Utils/SpreaderUtilities.cs +++ b/src/client/spark_test/Utils/SpreaderUtilities.cs @@ -27,8 +27,24 @@ namespace bts.tests Assert.IsNotNull(exps); Assert.IsTrue(exps.Count() > 2, "Need at least two expirations"); - var exp1 = exps[0]; - var exp2 = exps[1]; + (uint, uint) preferred_expirations = (07,12); + + FutureContract exp1; + FutureContract exp2; + + if(exps.Exists(expir => expir.ExpirationMonth == preferred_expirations.Item1)) { + exp1 = exps.Where(ex => ex.ExpirationMonth == preferred_expirations.Item1).First(); + } + else { + exp1 = exps[0]; + } + + if(exps.Exists(expir => expir.ExpirationMonth == preferred_expirations.Item2 && expir.ExpirationYear == exp1.ExpirationYear)) { + exp2 = exps.Where(ex => ex.ExpirationMonth == preferred_expirations.Item2 && ex.ExpirationYear == exp1.ExpirationYear).First(); + } + else { + exp2 = exps[1]; + } Func sec1_match = ch => ch.Security.Future.ExpirationYear == exp1.ExpirationYear && @@ -103,13 +119,15 @@ namespace bts.tests new_synth.Synthetic.Legs.Add(legs.Select(l => l.contract)); new_synth.Symbol = deduce_symbol(new_synth); new_synth.ContractSpec = new ContractSpecification(); - new_synth.ContractSpec.LowTick = 0.01; - new_synth.ContractSpec.HighTick = 0.01; + new_synth.ContractSpec.LowTick = 0.005; + new_synth.ContractSpec.HighTick = 0.005; new_synth.ContractSpec.PriceBreak = double.MaxValue; new_synth.ContractSpec.MainFraction = 1u; new_synth.ContractSpec.PriceDisplayFormat = 3u; + new_synth.ContractSpec.CashPerPoint = 1u; + new_synth.ContractSpec.PriceMultiplier = 1u; new_synth.Exchange = Venue.Bts; - new_synth.Synthetic.Name = "TEST_SYNTH" + DateTime.Now.ToString(); + new_synth.Synthetic.Name = "TEST_SYNTH" + DateTime.Now.TimeOfDay.ToString(); var result = await service.create_synthetic_async(new_synth); Assert.IsTrue(result.success, "Unable to create synthetic"); From 64fd8addb2261e9ffc2ee52f37364e65b0234dd6 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Thu, 13 Jun 2019 09:38:11 -0400 Subject: [PATCH 08/12] Update Lean qty factor shell script --- .../spreader_lean_qty_factor.sh | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh index 28913e469..afe9e1e5f 100644 --- a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh +++ b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh @@ -1,9 +1,21 @@ #!/bin/bash -rm -r ~/sparkdata/data/databases/ > /dev/null +if [ -d ~/sparkdata/ ] +then + sparkdata_dir=~/sparkdata +else + sparkdata_dir=/sparkdata +fi -mv ~/sparkdata/conf/spark.conf ~/sparkdata/conf/spark.conf.bak -cat << EOF > ~/sparkdata/conf/spark.conf +./delete_dbs.sh + +config=$sparkdata_dir/conf/spark.conf +bak=$sparkdata_dir/conf/spark.conf.bak + +[ ! -d "$sparkdata_dir/conf" ] && mkdir $sparkdata_dir/conf/ +[ -f "$conf" ] && mv $conf $bak + +cat << EOF > $sparkdata_dir/conf/spark.conf ExchangeSim { value { merge_with_md:false @@ -15,7 +27,13 @@ cat << EOF > ~/sparkdata/conf/spark.conf syslog { default_level: "Error" } file { default_level: "Error" } } -} + } + + SymbolList { + value { + symbol: "SI" + } + } EOF @@ -23,10 +41,12 @@ nohup ./sparkd run & pid=$! echo "sparkd pid: " $pid -echo "sleeping for 120 seconds..." -sleep 120 - dotnet sparkcmd.dll test spreader_lean_qty_factor -kill $pid -mv ~/sparkdata/conf/spark.conf.bak ~/sparkdata/conf/spark.conf \ No newline at end of file +exit_status=$? + +pkill -P $$ + +[ -f "$bak" ] && mv $bak $conf +[ $exit_status -eq 0 ] && echo "Test Finished" || echo "Test failed" +exit $exit_status \ No newline at end of file From e5d31d3c891e8ba817b98d3c56c22955e9d2f4ae Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 17 Jun 2019 12:58:21 -0400 Subject: [PATCH 09/12] match sparkdata discovery, remove use_onixs: false --- src/client/spark_test/system_test_scripts/delete_dbs.sh | 6 +++--- .../system_test_scripts/spreader_lean_qty_factor.sh | 6 +++--- .../system_test_scripts/spreader_simple_sanity.sh | 7 +++---- .../spark_test/system_test_scripts/test_join_algo.sh | 5 ----- .../spark_test/system_test_scripts/test_position_limits.sh | 7 +++---- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/client/spark_test/system_test_scripts/delete_dbs.sh b/src/client/spark_test/system_test_scripts/delete_dbs.sh index dce0fd4f8..423cb3f23 100644 --- a/src/client/spark_test/system_test_scripts/delete_dbs.sh +++ b/src/client/spark_test/system_test_scripts/delete_dbs.sh @@ -1,10 +1,10 @@ #!/bin/bash -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata/ ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi if [ -d "$sparkdata_dir/data" ] diff --git a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh index afe9e1e5f..dab656a08 100644 --- a/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh +++ b/src/client/spark_test/system_test_scripts/spreader_lean_qty_factor.sh @@ -1,10 +1,10 @@ #!/bin/bash -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi ./delete_dbs.sh diff --git a/src/client/spark_test/system_test_scripts/spreader_simple_sanity.sh b/src/client/spark_test/system_test_scripts/spreader_simple_sanity.sh index 2ca201c44..a79760e29 100644 --- a/src/client/spark_test/system_test_scripts/spreader_simple_sanity.sh +++ b/src/client/spark_test/system_test_scripts/spreader_simple_sanity.sh @@ -1,10 +1,10 @@ #!/bin/bash -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi ./delete_dbs.sh @@ -28,7 +28,6 @@ cat << EOF > $sparkdata_dir/conf/spark.conf file { default_level: "Error" } } } - MarketDataConfig { value { use_onixs: false; } } EOF diff --git a/src/client/spark_test/system_test_scripts/test_join_algo.sh b/src/client/spark_test/system_test_scripts/test_join_algo.sh index 6eeb35b96..3f47db564 100644 --- a/src/client/spark_test/system_test_scripts/test_join_algo.sh +++ b/src/client/spark_test/system_test_scripts/test_join_algo.sh @@ -130,11 +130,6 @@ ExchangeSim { merge_with_md: false } } -MarketDataConfig { - value { - use_onixs: false; - } -} END_HEREDOC ) diff --git a/src/client/spark_test/system_test_scripts/test_position_limits.sh b/src/client/spark_test/system_test_scripts/test_position_limits.sh index edd0b1295..45837eab0 100644 --- a/src/client/spark_test/system_test_scripts/test_position_limits.sh +++ b/src/client/spark_test/system_test_scripts/test_position_limits.sh @@ -1,10 +1,10 @@ #!/bin/bash -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi ./delete_dbs.sh @@ -28,7 +28,6 @@ cat << EOF > $sparkdata_dir/conf/spark.conf file { default_level: "Error" } } } - MarketDataConfig { value { use_onixs: false; } } EOF From cb0ec5f3b955679e53dff246ec55bffaf7bc7916 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Mon, 17 Jun 2019 13:08:59 -0400 Subject: [PATCH 10/12] match sparkdata discovery --- .../spark_test/system_test_scripts/test_clip_limits.sh | 7 +++---- .../spark_test/system_test_scripts/test_join_algo.sh | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/spark_test/system_test_scripts/test_clip_limits.sh b/src/client/spark_test/system_test_scripts/test_clip_limits.sh index f2f440124..542cbb399 100644 --- a/src/client/spark_test/system_test_scripts/test_clip_limits.sh +++ b/src/client/spark_test/system_test_scripts/test_clip_limits.sh @@ -1,10 +1,10 @@ #!/bin/bash -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata/ ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi ./delete_dbs.sh @@ -28,7 +28,6 @@ cat << EOF > $sparkdata_dir/conf/spark.conf file { default_level: "Error" } } } - MarketDataConfig { value { use_onixs: false; } } EOF nohup ./sparkd run & diff --git a/src/client/spark_test/system_test_scripts/test_join_algo.sh b/src/client/spark_test/system_test_scripts/test_join_algo.sh index 3f47db564..0aa24331e 100644 --- a/src/client/spark_test/system_test_scripts/test_join_algo.sh +++ b/src/client/spark_test/system_test_scripts/test_join_algo.sh @@ -5,11 +5,11 @@ # Stop script if unbound variable found (use ${var:-} if intentional) set -u -if [ -d ~/sparkdata/ ] +if [ -d /sparkdata/ ] then - sparkdata_dir=~/sparkdata -else sparkdata_dir=/sparkdata +else + sparkdata_dir=~/sparkdata fi # Use in the the functions: eval $invocation From 0b5d2bd4dc0911b53f962190b99e3cce418fc249 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Tue, 18 Jun 2019 09:58:08 -0400 Subject: [PATCH 11/12] Fix null security Id --- src/client/spark_test/System/LimitsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/spark_test/System/LimitsTests.cs b/src/client/spark_test/System/LimitsTests.cs index 72d19b9cf..53465d4d6 100644 --- a/src/client/spark_test/System/LimitsTests.cs +++ b/src/client/spark_test/System/LimitsTests.cs @@ -234,8 +234,8 @@ namespace bts.tests //create Orders Here var all = await all_futures(test_symbol); - SecurityImmutable? sec = all.FirstOrDefault(); - Assert.IsTrue(sec.HasValue); + SecurityImmutable? sec = all.TryFirst(); + Assert.IsTrue(sec.HasValue, "No Futures?"); uint under_limit_order_key; uint over_limit_order_key; From c2788e4d615422b4d56bbf26637253e279551dc3 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Tue, 18 Jun 2019 09:58:54 -0400 Subject: [PATCH 12/12] Harden wait_for_orders_service_ready --- src/client/spark_test/Utils/TestUtils.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/client/spark_test/Utils/TestUtils.cs b/src/client/spark_test/Utils/TestUtils.cs index 1901f67dd..c0d099b97 100644 --- a/src/client/spark_test/Utils/TestUtils.cs +++ b/src/client/spark_test/Utils/TestUtils.cs @@ -131,7 +131,27 @@ namespace bts.tests.utils { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); - var odef = OrderDefinitionUtilities.create_limit_order_def(1, Side.Buy, ("bts", 1), ("ACC A", 1)); + var ctx = new ServiceContext(); + var mdrelay = ctx.locate(); + + bts.co2.ProductListReply products = null; + + for(int i = 0; i < 10; i++) { + var tmpp = await mdrelay.request_products_async(null); + if( tmpp.value != null) { + Console.WriteLine(i); + products = tmpp.value; + break; + } + } + + bts.test.Assert.IsTrue(products != null, "No products found"); + var filtered_products = products.Products.Where(z => z.Exchange == Venue.Sim && z.Type == SecurityType.Future); + bts.test.Assert.IsTrue(filtered_products.Count() > 0, "No suitable products found"); + var test_security = await MarketDataUtilities.get_security(mdrelay, filtered_products.First().Symbol, SecurityType.Future, f => true); + bts.test.Assert.IsTrue(test_security.HasValue, "No suitable security found"); + + var odef = OrderDefinitionUtilities.create_limit_order_def(test_security.Value.Id, Side.Buy, ("ACC A", 1), ("bts", 1)); Update service_value = null; while(service_value == null && watch.Elapsed < timeout) {