Exemple #1
0
        public int cancelOrder(OrderStruct os)  //will add check in case of already filled, no cancel.
        {
            OrderDAO    ord  = new OrderDAO();
            OrderStruct dbos = new OrderStruct(8, 8);

            if (ord.getOrderFromDB(os.OrderNo, ref dbos) < 0)
            {
                Console.WriteLine("Error : Unable to get order details from DB");
                return(-1);
            }
            Console.WriteLine("DBG: truct val");
            dbos.display();
            string ordStatus = new string(dbos.OrderStatus);

            if (ordStatus.Equals("CANCELED") || ordStatus.Equals("COMPLETED"))
            {
                Console.WriteLine("Order is already " + ordStatus);
                return(-1);
            }
            Console.WriteLine("Order No [" + dbos.OrderNo + "] : Status [" + ordStatus + "]");
            //return -1;
            if (ord.cancelOrder(dbos) < 0)
            {
                return(-1);
            }
            Console.WriteLine("TODO: Send FIX - cancel for os.ID");
            //Send FIX - cancel for os.ID
            return(0);
        }
Exemple #2
0
        public int cancelOrder(OrderStruct os)
        {//will add check in case of already filled, no cancel.
            OrderDAO    ord  = new OrderDAO();
            OrderStruct dbos = new OrderStruct(11, 8);

            if (ord.getOrderFromDB(os.OrderNo, ref dbos) < 0)
            {
                Console.WriteLine("Error : Unable to get order details from DB");
                return(-1);
            }
            Console.WriteLine("DBG: truct val");
            dbos.display();
            string ordStatus = new string(dbos.OrderStatus);

            //if(ordStatus.Equals("CANCELED") || ordStatus.Equals("COMPLETED"))
            //{
            //    Console.WriteLine("Order is already "+ordStatus);
            //    return -1;
            //}
            Console.WriteLine("Order No [" + dbos.OrderNo + "] : Status [" + ordStatus + "]");
            //return -1;
            int ordNo = ord.cancelOrder(ref dbos);

            if (ordNo < 0)
            {
                return(-1);
            }
            Console.WriteLine("TODO: Send FIX - cancel for os.ID");
            //Send FIX - cancel for os.ID

            OrigClOrdID origCLOrdID = new OrigClOrdID(Convert.ToString(dbos.fixAcceptedID));
            ClOrdID     OrdId       = new ClOrdID(Convert.ToString(ordNo));
            string      symboldata  = sanitiseField(os.symbol);
            Symbol      symbol      = new Symbol(symboldata);
            Side        side        = new Side(Side.BUY);

            if (os.direction == 'S')
            {
                side = new Side(Side.SELL);
            }

            Console.WriteLine("cancelling origOrdId : " + dbos.fixAcceptedID + " newOrdId : " + ordNo);
            Console.WriteLine("symboldata : " + symboldata + " side : " + side);

            var orderCan = new QuickFix.FIX42.OrderCancelRequest(origCLOrdID, OrdId, symbol, side,
                                                                 new TransactTime(DateTime.Now.ToUniversalTime()));

            Session.SendToTarget(orderCan, FixClient.MySess);
            return(os.OrderNo);
        }
Exemple #3
0
        public int FIXResponseHandlerForFill(int OrderID, string ExchangeOrderId, float qty, float price, float filledQty, string status, char exectype)
        {
            OrderDAO    ord     = new OrderDAO();
            OrderStruct os      = new OrderStruct();
            int         orderNo = ord.getOrderNoFromOrderID(OrderID);

            ord.addOrderFillsFromFIX(OrderID, orderNo, ExchangeOrderId, qty, price, filledQty, status);
            ord.getOrderFromDB(orderNo, ref os);
            float     pos       = ord.getCurrentPosition(os.tokenID, new string(os.userID));
            string    other_msg = Convert.ToString(pos);
            string    data      = new string(os.machineID) + ":" + new string(os.userID) + ":" + os.OrderNo + ":" + new string(os.OrderStatus) + ":" + ExchangeOrderId + ":" + exectype + ":" + status + ":" + other_msg;
            OMFillPub ofp       = new OMFillPub();

            if (ofp.zmqUpdates(data) == 0)
            {
                Console.WriteLine("Zmq update success");
            }
            else
            {
                Console.WriteLine("Zmq update fail");
            }
            return(0);
        }