Ejemplo n.º 1
0
        public static bool insertOrder(string symbol, string expiry, string callput, string exch, string strike, double price, int qty, char action, TradingBoxV2 tb)
        {
            tradingBox = tb;
            try
            {
                //Console.WriteLine("Format : INS:SYM:Price:Quantity:direction:machineID:userID\n");
                //Console.WriteLine("usage Number of Test Cases followed by input per line <INS:AAPL:111.90:1:B> or <CAN:AAPL:0:111.90:1:B>\nDesc : INS:SYMBOL:PRICE:QTY:DIR");

                /*byte[] bytesFrom = new byte[(int)clientSocket.ReceiveBufferSize + 1];
                 * networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                 * reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                 * Console.WriteLine("Received : " + reqType);
                 * clientSocket.Close();
                 */

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

                //stringToStruct("INS:AAPL0000:111.90:1:B:21:25", ref os);
                string input = "INS:" + symbol + ":" + price + ":" + qty + ":" + strike + ":" + action + ":" + expiry + ":" + callput + ":" + exch + ":" + MachineGuid + ":" + UserGuid;
                tradingBox.displayTextArea(input);

                OrderStruct os = new OrderStruct(8, 8);
                stringToStruct(input, ref os);
                os.display();

                TcpClient clientSocket = new TcpClient();
                tradingBox.displayTextArea("Connecting.....");

                clientSocket.Connect("127.0.0.1", 5552);
                // use the ipaddress as in the server program

                tradingBox.displayTextArea("Connected ...");

                NetworkStream networkStream = clientSocket.GetStream();

                sendBytes = (getBytes(os));

                networkStream.Write(sendBytes, 0, sendBytes.Length);
                tradingBox.displayTextArea("written " + sendBytes.Length + " bytes.");


                System.Threading.Thread.Sleep(200);
                networkStream.Flush();

                byte[] bytesFrom = new byte[(Int32)clientSocket.ReceiveBufferSize + 1];
                networkStream.Read(bytesFrom, 0, (Int32)clientSocket.ReceiveBufferSize);
                reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                tradingBox.displayTextArea("Received : " + reqType);
                clientSocket.Close();

                return(true);
            }
            catch (Exception e)
            {
                tradingBox.displayTextArea("Error..... " + e.StackTrace);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static bool cancelOrder(string symbol, string orderid)
        {
            try
            {
                string reqType   = null;
                Byte[] sendBytes = null;

                //stringToStruct("INS:AAPL0000:111.90:1:B:21:25", ref os);
                string input = "CAN:" + symbol + ":" + orderid + ":" + MachineGuid + ":" + UserGuid;
                tradingBox.displayTextArea(input);

                OrderStruct os = new OrderStruct(8, 8);
                stringToStruct(input, ref os);
                os.display();

                TcpClient clientSocket = new TcpClient();
                tradingBox.displayTextArea("Connecting.....");

                clientSocket.Connect("127.0.0.1", 5551);
                // use the ipaddress as in the server program

                tradingBox.displayTextArea("Connected ...");

                NetworkStream networkStream = clientSocket.GetStream();

                sendBytes = (getBytes(os));

                networkStream.Write(sendBytes, 0, sendBytes.Length);
                tradingBox.displayTextArea("written " + sendBytes.Length + " bytes.");
                networkStream.Flush();

                System.Threading.Thread.Sleep(200);

                byte[] bytesFrom = new byte[(int)clientSocket.ReceiveBufferSize + 1];
                networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                tradingBox.displayTextArea("Received : " + reqType);
                clientSocket.Close();

                return(true);
            }

            catch (Exception e)
            {
                tradingBox.displayTextArea("Error..... " + e.StackTrace);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public static bool insertOrderEOD()
        {
            try
            {
                string reqType   = null;
                Byte[] sendBytes = null;

                //stringToStruct("INS:AAPL0000:111.90:1:B:21:25", ref os);
                string input = "EOD:NIFTY";

                OrderStruct os = new OrderStruct(11, 8);
                stringToStruct(input, ref os);
                os.display();

                TcpClient clientSocket = new TcpClient();

                //clientSocket.Connect("127.0.0.1", 5552);
                clientSocket.Connect("158.69.193.253", 5552);
                // use the ipaddress as in the server program

                NetworkStream networkStream = clientSocket.GetStream();

                sendBytes = (getBytes(os));

                networkStream.Write(sendBytes, 0, sendBytes.Length);
                System.Threading.Thread.Sleep(200);
                networkStream.Flush();

                byte[] bytesFrom = new byte[(Int32)clientSocket.ReceiveBufferSize + 1];
                networkStream.Read(bytesFrom, 0, (Int32)clientSocket.ReceiveBufferSize);
                reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);

                clientSocket.Close();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static bool cancelOrder(string symbol, string orderid)
        {
            try
            {
                string reqType   = null;
                Byte[] sendBytes = null;

                //stringToStruct("INS:AAPL0000:111.90:1:B:21:25", ref os);
                string input = "CAN:" + symbol + ":" + orderid + ":" + MachineGuid + ":" + UserGuid;
                tradingBox.displayTextArea(input);

                OrderStruct os = new OrderStruct(11, 8);
                stringToStruct(input, ref os);
                os.display();

                TcpClient clientSocket = new TcpClient();
                tradingBox.displayTextArea("Connecting.....");

                //clientSocket.Connect("127.0.0.1", 5551);
                clientSocket.Connect("158.69.193.253", 5552);
                // use the ipaddress as in the server program

                tradingBox.displayTextArea("Connected ...");

                NetworkStream networkStream = clientSocket.GetStream();

                sendBytes = (getBytes(os));

                networkStream.Write(sendBytes, 0, sendBytes.Length);
                tradingBox.displayTextArea("written " + sendBytes.Length + " bytes.");
                networkStream.Flush();

                System.Threading.Thread.Sleep(200);

                byte[] bytesFrom = new byte[(int)clientSocket.ReceiveBufferSize + 1];
                networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                tradingBox.ShowStatus1(reqType);
                tradingBox.displayTextArea("Received : " + reqType);
                clientSocket.Close();

                try
                {
                    String[] arr = reqType.Split(':');
                    //if (arr.Length == 4)
                    {
                        string strOrdId = arr[3];
                        if (strOrdId.Contains('\0'))
                        {
                            tradingBox.orderid = strOrdId.Substring(0, strOrdId.IndexOf('\0'));
                        }
                        else
                        {
                            tradingBox.orderid = strOrdId;
                            tradingBox.ShowStatus1("OrderId  : " + tradingBox.orderid);
                        }
                    }
                }
                catch (Exception e)
                {
                    tradingBox.ShowStatus1("Exception in OrderId Generation " + e.Message);
                }

                return(true);
            }

            catch (Exception e)
            {
                tradingBox.displayTextArea("Error..... " + e.StackTrace);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public static bool modifyOrder(int orderid, string symbol, string expiry, string callput, string exch, string strike, double price, int qty, char action, int OrderType, int TIF, TradingBoxV3 tb)
        {
            tradingBox = tb;
            try
            {
                //Console.WriteLine("Format : INS:SYM:Price:Quantity:direction:machineID:userID\n");
                //Console.WriteLine("usage Number of Test Cases followed by input per line <INS:AAPL:111.90:1:B> or <CAN:AAPL:0:111.90:1:B>\nDesc : INS:SYMBOL:PRICE:QTY:DIR");

                /*byte[] bytesFrom = new byte[(int)clientSocket.ReceiveBufferSize + 1];
                 * networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                 * reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                 * Console.WriteLine("Received : " + reqType);
                 * clientSocket.Close();
                 */

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

                //stringToStruct("INS:AAPL0000:111.90:1:B:21:25", ref os);
                //string input = "INS:" + symbol + ":" + price + ":" + qty + ":" + strike + ":" + action + ":" + expiry + ":" + callput + ":" + exch + ":" + MachineGuid + ":" + UserGuid + ":" + OrderType + ":" + TIF;
                string input = "AMD:" + symbol + ":" + orderid + ":" + price + ":" + qty + ":" + strike + ":" + action + ":" + expiry + ":" + callput + ":" + exch + ":" + MachineGuid + ":" + UserGuid + ":" + OrderType + ":" + TIF;
                tradingBox.displayTextArea(input);

                OrderStruct os = new OrderStruct(11, 8);
                stringToStruct(input, ref os);
                os.display();

                TcpClient clientSocket = new TcpClient();
                tradingBox.displayTextArea("Connecting.....");

                //clientSocket.Connect("127.0.0.1", 5552);
                clientSocket.Connect("158.69.193.253", 5552);
                // use the ipaddress as in the server program

                tradingBox.displayTextArea("Connected ...");

                NetworkStream networkStream = clientSocket.GetStream();

                sendBytes = (getBytes(os));

                networkStream.Write(sendBytes, 0, sendBytes.Length);
                tradingBox.displayTextArea("written " + sendBytes.Length + " bytes.");
                System.Threading.Thread.Sleep(200);
                networkStream.Flush();

                byte[] bytesFrom = new byte[(Int32)clientSocket.ReceiveBufferSize + 1];
                networkStream.Read(bytesFrom, 0, (Int32)clientSocket.ReceiveBufferSize);
                reqType = System.Text.Encoding.ASCII.GetString(bytesFrom);
                tradingBox.ShowStatus1(reqType);
                tradingBox.displayTextArea("Received : " + reqType);

                clientSocket.Close();

                try
                {
                    String[] arr = reqType.Split(':');
                    //if (arr.Length == 4)
                    {
                        string strOrdId = arr[3];
                        if (strOrdId.Contains('\0'))
                        {
                            tradingBox.orderid = strOrdId.Substring(0, strOrdId.IndexOf('\0'));
                        }
                        else
                        {
                            tradingBox.orderid = strOrdId;
                            tradingBox.ShowStatus1("OrderId  : " + tradingBox.orderid);
                        }
                    }
                }
                catch (Exception e)
                {
                    tradingBox.ShowStatus1("Exception in OrderId Generation " + e.Message);
                }
                return(true);
            }
            catch (Exception e)
            {
                tradingBox.ShowStatus1("Erro..... Order Details");
                tradingBox.displayTextArea("Error..... " + e.StackTrace);
            }
            return(false);
        }