Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiusgreat committed Dec 16, 2024
1 parent 9b747e5 commit 190902f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 53 deletions.
9 changes: 4 additions & 5 deletions Core/Domains/Gateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ OrderModel merge(OrderModel subOrder, OrderModel group)
var groupOrders = group
?.Orders
?.Where(o => o.Instruction is InstructionEnum.Brace)
?.Where(o => Equals(o.Name, nextOrder.Name)) ?? [];
?.Where(o => Equals(o.Name, nextOrder.Name))
?.Select(o => { o.Descriptor = group.Descriptor; return o; }) ?? [];

nextOrder.Price ??= nextOrder.GetOpenEstimate();
nextOrder.Type ??= group.Type ?? OrderTypeEnum.Market;
Expand All @@ -264,14 +265,14 @@ OrderModel merge(OrderModel subOrder, OrderModel group)
nextOrder.Transaction.Time ??= DateTime.Now;
nextOrder.Transaction.CurrentVolume = nextOrder.Transaction.Volume;
nextOrder.Descriptor = group.Descriptor;
nextOrder.Orders = [.. nextOrder.Orders, .. groupOrders];
nextOrder.Orders = [.. groupOrders];

return nextOrder;
}

var nextOrders = order
.Orders
.Where(o => o.Instruction is InstructionEnum.Side)
.Where(o => o.Instruction is InstructionEnum.Side or null)
.Select(o => merge(o, order))
.ToList();

Expand All @@ -280,8 +281,6 @@ OrderModel merge(OrderModel subOrder, OrderModel group)
nextOrders.Add(merge(order, order));
}

order.Orders.Clear();

return nextOrders;
}
}
Expand Down
47 changes: 2 additions & 45 deletions Gateway/Simulation/Libs/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public override Task<ResponseModel<IList<OrderModel>>> CreateOrders(params Order
case OrderTypeEnum.Market: SendOrder(nextOrder); break;
}

nextOrder.Orders.ForEach(o => SendPendingOrder(o));
response.Data.Add(nextOrder);
}
}
Expand Down Expand Up @@ -266,6 +267,7 @@ protected virtual OrderModel SendPendingOrder(OrderModel order)
protected virtual OrderModel SendOrder(OrderModel order)
{
order.Transaction.Id = order.Id;
order.Transaction.Status = OrderStatusEnum.Filled;

if (Account.Positions.TryGetValue(order.Name, out var currentOrder))
{
Expand All @@ -292,51 +294,6 @@ protected virtual OrderModel SendOrder(OrderModel order)
return order;
}

/// <summary>
/// Create position when there are no other positions
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
protected virtual IList<OrderModel> ComposeOrders(OrderModel order)
{
OrderModel merge(OrderModel o, OrderModel group)
{
var nextOrder = o.Clone() as OrderModel;

nextOrder.Price ??= nextOrder.GetOpenEstimate();
nextOrder.Type ??= group.Type ?? OrderTypeEnum.Market;
nextOrder.TimeSpan ??= group.TimeSpan ?? OrderTimeSpanEnum.Gtc;
nextOrder.Instruction ??= InstructionEnum.Side;
nextOrder.Transaction.Time ??= DateTime.Now;
nextOrder.Transaction.Price ??= nextOrder.Price;
nextOrder.Transaction.Status = OrderStatusEnum.Filled;
nextOrder.Transaction.CurrentVolume = nextOrder.Transaction.Volume;
nextOrder.Descriptor = group.Descriptor;

return nextOrder;
}

var nextOrders = order
.Orders
.Where(o => o.Instruction is InstructionEnum.Side)
.Select(o => merge(o, order))
.ToList();

order
.Orders
.Where(o => o.Instruction is InstructionEnum.Brace)
.ForEach(o => SendPendingOrder(o));

if (order.Transaction is not null)
{
nextOrders.Add(merge(order, order));
}

order.Orders.Clear();

return nextOrders;
}

/// <summary>
/// Compute aggregated position price
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions Gateway/Simulation/Tests/Positions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public void CreatePendingOrder(
}
};

var openPrice = order.Side is OrderSideEnum.Buy ? point.Bid : point.Ask;

base.CreateOrders(order);

Assert.Empty(Account.Deals);
Expand All @@ -67,7 +65,7 @@ public void CreatePendingOrder(
var outOrder = Account.Orders[order.Id];

Assert.Equal(outOrder.Type, orderType);
Assert.Equal(outOrder.Price, openPrice);
Assert.Equal(outOrder.Price, orderPrice);
Assert.Equal(outOrder.TimeSpan, OrderTimeSpanEnum.Gtc);
Assert.NotEmpty(outOrder.Transaction.Id);
Assert.Equal(outOrder.Transaction.Id, order.Id);
Expand Down

0 comments on commit 190902f

Please sign in to comment.