Exemplo n.º 1
0
        private void MatchBuyLogic(OrderEventArgs e)
        {
            foreach (Order curOrder in e.SellBook)
            {
                if (e.Order.OrderType == "MARKET" && e.Order.Quantity > 0)
                {
                    Console.WriteLine("Match found..Generate Market Order Trade..");
                    int quantity = Math.Min(e.Order.Quantity, curOrder.Quantity); //need to check this
                    curOrder.Quantity = curOrder.Quantity - quantity;
                    e.Order.Quantity  = e.Order.Quantity - quantity;
                    Console.WriteLine(quantity.ToString() + " " + curOrder.Instrument.ToString() + " at " + curOrder.LimitPrice.ToString() + " order ID's " + curOrder.OrderID.ToString() + " & " + e.Order.OrderID.ToString());
                    // write executed orders to xml file

                    //records trade info and sends executed order info back to client
                    FuturesOrder executedOrder1 = (FuturesOrder)curOrder.Clone();//make copy so original order is not effected in case of partial fill
                    executedOrder1.ExecutionQuantity  = quantity;
                    executedOrder1.executionPrice     = curOrder.LimitPrice;
                    executedOrder1.ExecutionTimeStamp = DateTime.Now;
                    FuturesOrder executedOrder2 = (FuturesOrder)e.Order.Clone();//make copy so original order is not effected in case of partial fill
                    executedOrder1.ExecutionQuantity  = quantity;
                    executedOrder2.executionPrice     = curOrder.LimitPrice;
                    executedOrder2.ExecutionTimeStamp = DateTime.Now;
                    //send executed order back to client
                    ClearingHouseTest.UpdateMarginForExucutedOrder(executedOrder1); //used to update margin with actual execution price
                    ClearingHouseTest.UpdateMarginForExucutedOrder(executedOrder2); //used to update margin with actual execution price
                    ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(executedOrder1));
                    ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(executedOrder2));
                }

                else if (curOrder.LimitPrice <= e.Order.LimitPrice && e.Order.Quantity > 0)
                {
                    Console.WriteLine("Match found..Generate Trade..");
                    int quantity = Math.Min(e.Order.Quantity, curOrder.Quantity);
                    curOrder.Quantity = curOrder.Quantity - e.Order.Quantity;
                    e.Order.Quantity  = e.Order.Quantity - quantity;
                    Console.WriteLine(quantity.ToString() + " " + curOrder.Instrument.ToString() + " at " + curOrder.LimitPrice.ToString() + " order ID's " + curOrder.OrderID.ToString() + " & " + e.Order.OrderID.ToString());

                    //records trade info and sends executed order info back to client
                    FuturesOrder executedOrder1 = (FuturesOrder)curOrder.Clone();//make copy so original order is not effected in case of partial fill
                    executedOrder1.ExecutionQuantity  = quantity;
                    executedOrder1.executionPrice     = curOrder.LimitPrice;
                    executedOrder1.ExecutionTimeStamp = DateTime.Now;
                    FuturesOrder executedOrder2 = (FuturesOrder)e.Order.Clone();//make copy so original order is not effected in case of partial fill
                    executedOrder1.ExecutionQuantity  = quantity;
                    executedOrder2.executionPrice     = curOrder.LimitPrice;
                    executedOrder2.ExecutionTimeStamp = DateTime.Now;
                    ClearingHouseTest.UpdateMarginForExucutedOrder(executedOrder1); //used to update margin with actual execution price
                    ClearingHouseTest.UpdateMarginForExucutedOrder(executedOrder2); //used to update margin with actual execution price
                    //send executed order back to client
                    ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(executedOrder1));
                    ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(executedOrder2));
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void processMatchedLimitOrders(ArrayList limitOrders, double openPrice, ArrayList marketOrders = null)
        {
            FuturesOrder processOrder;



            while (limitOrders.Count > 0)
            {
                processOrder = (limitOrders[0] as FuturesOrder);
                limitOrders.RemoveAt(0);
                if (processOrder.Quantity != 0)
                {
                    Console.WriteLine("0");
                }
                processOrder.executionPrice     = openPrice;
                processOrder.ExecutionTimeStamp = DateTime.Now;
                ClearingHouseTest.UpdateMarginForExucutedOrder(processOrder); //to update margin account with execution price
                ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(processOrder));
                //send back to client
            }
            if (marketOrders != null)
            {
                while (marketOrders.Count > 0)
                {
                    processOrder = (marketOrders[0] as FuturesOrder);
                    marketOrders.RemoveAt(0);
                    if (processOrder.Quantity != 0)
                    {
                        Console.WriteLine("0");
                    }
                    processOrder.executionPrice     = openPrice;
                    processOrder.ExecutionTimeStamp = DateTime.Now;
                    //send back to client
                    ClearingHouseTest.UpdateMarginForExucutedOrder(processOrder);//used to update margin with actual execution price
                    ExecutedOrdersToSend.TcpClientTest.Connect(OMEHost.ToXML(processOrder));
                }
            }
        }