Submit and confirm working spreader order
This commit is contained in:
1 parent
3171ae0afb
commit
6ad12e922c
3 files changed
+33
-7
No files matched your search
@@ -65,7 +65,24 @@ 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 order1 = await OrderUtilities.send_order(_order_service, order1_def, -0.30, 1);
|
||||
|
||||
var spreader_orders = await OrderUtilities.wait_for_filtered_orders(_order_service,
|
||||
o => o.Where(ordi => ordi.Key == order1.value.OrderKey).Count() > 0,
|
||||
ord => ord.Where(ordi => ordi.Key == order1.value.OrderKey));
|
||||
|
||||
Assert.IsTrue(spreader_orders.result.Count() > 0, "Can't find spreader order");
|
||||
|
||||
var order = spreader_orders.result.TryFirst();
|
||||
Assert.IsTrue(order.HasValue, "order not found");
|
||||
Assert.IsTrue(order.Value.State.Status == OrderStatus.Working, "Order is not Working");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using mbts;
|
||||
using mbts.tests;
|
||||
using bts.co2;
|
||||
using bts.tests.utils;
|
||||
using bts.spark;
|
||||
|
||||
namespace bts.tests
|
||||
{
|
||||
@@ -147,6 +148,12 @@ namespace bts.tests
|
||||
return def;
|
||||
}
|
||||
|
||||
public static OrderDefinition create_spreader_order_def(Security security, Side side, ExecutionStrategy strategy, (String name, uint id) account, (String name, uint id) user) {
|
||||
var def = create_base_order(security.Id, side, account, user);
|
||||
def.CustomDef = new CustomOrderDefinition { Spreader = new SpreaderOrderDefinition {Security = security, ExecutionStrategy = strategy} };
|
||||
return def;
|
||||
}
|
||||
|
||||
public static OrderDefinition create_iceberg_order_def(uint security_id, Side side, (String name, uint id) account, (String name, uint id) user, double show_quantity) {
|
||||
var def = create_base_order(security_id, side, account, user);
|
||||
def.CustomDef = new CustomOrderDefinition {
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace bts.tests
|
||||
|
||||
return (s1: sec1.Value, s2: sec2.Value);
|
||||
}
|
||||
public static async Task<(IEnumerable<OrderRecordImmutable> book, uint? synthetic_id)> common_setup_one(OrderService order_service, SyntheticSecurityService synthetic_service, (SecurityImmutable? s1, SecurityImmutable? s2) securities, (String name, uint id) account, (String name, uint id) user) {
|
||||
public static async Task<(IEnumerable<OrderRecordImmutable> book, (Security security, ExecutionStrategy strategy) synthetic)> common_setup_one(OrderService order_service, SyntheticSecurityService synthetic_service, (SecurityImmutable? s1, SecurityImmutable? s2) securities, (String name, uint id) account, (String name, uint id) user) {
|
||||
var order_defs = new (OrderDefinition order_def, double price, uint size)[10];
|
||||
|
||||
for (int i = 0; i < 4; i ++) {
|
||||
@@ -91,13 +91,13 @@ namespace bts.tests
|
||||
legs.Add(create_leg(securities.s1.Value.CloneToMutable(),1,1,false,1));
|
||||
legs.Add(create_leg(securities.s2.Value.CloneToMutable(),-1,-1,true,1));
|
||||
|
||||
uint? synthetic_id = await create_synthetic(synthetic_service, legs);
|
||||
(Security security, ExecutionStrategy strategy) synthetic = await create_synthetic(synthetic_service, legs);
|
||||
|
||||
return(book, synthetic_id);
|
||||
return(book, synthetic);
|
||||
|
||||
}
|
||||
|
||||
public static async Task<uint?> create_synthetic(SyntheticSecurityService service, IEnumerable<(ContractLeg contract, LegSpreaderParams parameters)> legs) {
|
||||
public static async Task<(Security, ExecutionStrategy)> create_synthetic(SyntheticSecurityService service, IEnumerable<(ContractLeg contract, LegSpreaderParams parameters)> legs) {
|
||||
var new_synth = new Security(){};
|
||||
new_synth.Synthetic = new SyntheticContract();
|
||||
new_synth.Synthetic.Legs.Add(legs.Select(l => l.contract));
|
||||
@@ -109,7 +109,7 @@ namespace bts.tests
|
||||
new_synth.ContractSpec.MainFraction = 1u;
|
||||
new_synth.ContractSpec.PriceDisplayFormat = 3u;
|
||||
new_synth.Exchange = Venue.Bts;
|
||||
new_synth.Synthetic.Name = "TEST_SYNTH";
|
||||
new_synth.Synthetic.Name = "TEST_SYNTH" + DateTime.Now.ToString();
|
||||
|
||||
var result = await service.create_synthetic_async(new_synth);
|
||||
Assert.IsTrue(result.success, "Unable to create synthetic");
|
||||
@@ -118,14 +118,16 @@ namespace bts.tests
|
||||
uint? id = result.value.Key;
|
||||
Assert.IsTrue(id.HasValue && id.Value != 0, "Failed to get synthetic security key");
|
||||
|
||||
new_synth.Id = result.value.Key;
|
||||
|
||||
ExecutionStrategy strategy = new ExecutionStrategy();
|
||||
foreach(var leg in legs){
|
||||
strategy.LegParamsMap.Add(leg.contract.Security.Id, leg.parameters);
|
||||
}
|
||||
bool success = await save_strategy(service, id.Value, new ExecutionStrategyImmutable(strategy));
|
||||
bool success = await save_strategy(service, new_synth.Id, new ExecutionStrategyImmutable(strategy));
|
||||
Assert.IsTrue(success, "Failed to save synthetic strategy");
|
||||
|
||||
return id;
|
||||
return (new_synth, strategy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user