Пример #1
0
        public int addFills(OrderFillStruct ofs) // stored the fills in db and send it to fillpublisher
        {
            OrderDAO ord       = new OrderDAO();
            int      ordStatus = ord.addOrderFills(ofs);

            if (ordStatus == -1)
            {
                Console.WriteLine("error in DB");
                return(-1);
            }
            else if (ordStatus == 0)
            {
                Console.WriteLine("This Order is completed now [Order ID] = " + ofs.OrderNo);
            }
            else
            {
                Console.WriteLine("Order qty diff : " + ordStatus);
            }
            string machineID = "";
            string userID    = "";

            ord.getMachineAndUserFromDB(ofs.OrderNo, ref machineID, ref userID);
            OMFillPub ofp = new OMFillPub();

            if (ofp.zmqUpdate(ofs, machineID, userID) == 0)
            {
                Console.WriteLine("Zmq update success");
            }
            else
            {
                Console.WriteLine("Zmq update fail");
            }
            return(0);
        }
Пример #2
0
        public int addOrderFills(OrderFillStruct ofs)
        {
            int orderNo   = -1;
            int ordStatus = -1;

            try
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    int nextSeq = getNextSeq(FillSeq);
                    orderNo = getOrderNoFromOrderID(ofs.OrderNo);
                    string query = "INSERT INTO FILLS (ID,OrderNo,FillID,Quantity,Price, FilledQuantity, insertTS) VALUES ("
                                   + ofs.ID + "," + orderNo + "," + ofs.FillID + "," + ofs.Quantity + "," + ofs.Price + "," + ofs.FilledQuantity + ",SYSDATETIME());";
                    cmd.CommandText = query;
                    cmd.ExecuteNonQuery();
                }
                if ((ordStatus = fillStatus(orderNo)) == 0) // Order completed. Make Insert.
                {
                    insertOrderWithOrdeNO(orderNo);
                }
                return(ordStatus);
            }
            catch (Exception ex)
            {
                Console.Write("Exception(addOrderFills) : " + ex.Message);
            }
            return(-1);
        }
Пример #3
0
        //publish the orderinfo to fillpublisher
        public int zmqUpdate(OrderFillStruct of, string machineID, string userID)
        {
            string zmqConnString = ">tcp://" + zmqPubHost + ":" + zmqPubPort;

            using (var requestSocket = new RequestSocket(zmqConnString))
            {
                of.display();
                string data = machineID + ":" + userID + ":" + of.OrderNo + ":" + of.FillID + ":" + of.Price + ":" + of.Quantity + ":" + of.FilledQuantity;
                Console.WriteLine("Sending : {0}, {1} , {2}", zmqPubHost, zmqPubPort, data);
                requestSocket.SendFrame(data);
                var message = requestSocket.ReceiveFrameString();
                Console.WriteLine("requestSocket : Received '{0}'", message);
            }
            return(0);
        }
Пример #4
0
        public int addFills(OrderFillStruct ofs)
        {
            OrderDAO ord       = new OrderDAO();
            int      ordStatus = ord.addOrderFills(ofs);

            if (ordStatus == 0)
            {
                Console.WriteLine("This Order is completed now [Order ID] = " + ofs.OrderNo);
            }
            else
            {
                Console.WriteLine("Order qty diff : " + ordStatus);
            }
            //this will calculate the qty and mark order as complete and all.
            return(0);
        }
Пример #5
0
            private void doProcessing()
            {
                string reqType = null;

                Byte[] sendBytes      = null;
                string serverResponse = null;

                try
                {
                    NetworkStream networkStream = clientSocket.GetStream();
                    Console.WriteLine("Lengeth : " + clientSocket.ReceiveBufferSize);
                    byte[] bytesFrom = new byte[(Int32)clientSocket.ReceiveBufferSize + 1];
                    networkStream.Read(bytesFrom, 0, (Int32)clientSocket.ReceiveBufferSize);
                    //reqType = System.Text.Encoding.ASCII.GetString(bytesFrom, 0, 10);
                    Console.WriteLine(" >> " + "From client-" + clNo);
                    OrderStruct os = getStructFromBytes(bytesFrom);
                    RequestType rt = getReqType(os.methodID);

                    switch (rt)
                    {
                    case RequestType.INS:
                        //DO inert activity
                        //OrderStruct osIns = getStructFromBytes(bytesFrom);
                        Orders ord     = new Orders();
                        int    OrderNo = -1;
                        if ((OrderNo = ord.addOrder(os)) < 0)
                        {
                            serverResponse = "FAILURE:INS:ORDID:" + Convert.ToString(OrderNo);
                        }
                        else
                        {
                            serverResponse = "SUCCESS:INS:ORDID:" + Convert.ToString(OrderNo);
                        }
                        break;

                    case RequestType.AMD:
                        //Do amendment activity, cancel the previous and boo new.
                        //OrderStruct osAmd = getStructFromBytes(bytesFrom);
                        Orders AmdOrd     = new Orders();
                        int    newOrderNo = -1;
                        int    oldOrderNo = os.OrderNo;
                        if ((newOrderNo = AmdOrd.amendOrder(ref os)) < 0)
                        {
                            serverResponse = "FAILURE:AMD:OLD-ORDID:" + oldOrderNo;
                        }
                        else
                        {
                            serverResponse = "SUCCESS:AMD:OLD-ORDID:" + oldOrderNo + ":NEW-ORDID:" + newOrderNo;
                        }
                        break;

                    case RequestType.CAN:
                        //Do cancel activity
                        Orders ordCan     = new Orders();
                        int    OrderNoCan = -1;
                        if ((OrderNoCan = ordCan.cancelOrder(os)) < 0)
                        {
                            serverResponse = "FAILURE:CAN:ORDID:" + Convert.ToString(os.OrderNo);
                        }
                        else
                        {
                            serverResponse = "SUCCESS:CAN:ORDID:" + Convert.ToString(OrderNoCan);
                        }
                        break;

                    case RequestType.FIL:
                        //Do cancel activity
                        Orders          ordFilDummy = new Orders();
                        OrderFillStruct ofs         = new OrderFillStruct();
                        Random          r           = new Random();
                        ofs.FillID         = r.Next();
                        ofs.OrderNo        = os.OrderNo;
                        ofs.Quantity       = os.quantity;
                        ofs.FilledQuantity = os.quantity;
                        ofs.Price          = os.price;
                        if (ordFilDummy.addFills(ofs) < 0)
                        {
                            serverResponse = "FAILURE:FIL:ORDID:" + Convert.ToString(os.OrderNo);
                        }
                        else
                        {
                            serverResponse = "SUCCESS:FIL:ORDID:" + Convert.ToString(os.OrderNo);
                        }
                        break;

                    case RequestType.EOD:
                        Orders eodObj      = new Orders();
                        int    totalStatus = -1;
                        if ((totalStatus = eodObj.takeEODPositions()) < 0)
                        {
                            serverResponse = "FAILURE:EOD:" + totalStatus;
                        }
                        else
                        {
                            serverResponse = "FAILURE:EOD:" + totalStatus;
                        }
                        break;

                    default:
                        //Retrn generic error
                        reqType        = System.Text.Encoding.ASCII.GetString(bytesFrom);
                        serverResponse = "ERROR:UNK:ORDID:[" + reqType + "]";
                        break;
                    }
                    sendBytes = Encoding.ASCII.GetBytes(serverResponse);
                    networkStream.Write(sendBytes, 0, sendBytes.Length);
                    networkStream.Flush();
                    this.clientSocket.Close();
                    Console.WriteLine(" >> Closing connection : " + serverResponse);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception :  >> " + ex.ToString());
                }
            }