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
            private OrderStruct getStructFromBytes(byte[] bytesFrom)
            {
                IntPtr ptPoit = Marshal.AllocHGlobal(bytesFrom.Length);

                Marshal.Copy(bytesFrom, 0, ptPoit, bytesFrom.Length);
                OrderStruct os = (OrderStruct)Marshal.PtrToStructure(ptPoit, typeof(OrderStruct));

                //Console.WriteLine("Order : "+os.methodID);
                os.display();
                return(os);
            }
Exemple #3
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);
        }