コード例 #1
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OptionChainSocketForm_Load(object sender, EventArgs e)
        {
            //Load the config object namespace which contains the latest protocol and your product ID.
            IQ_Config config = new IQ_Config();
            // Set the protocol for the socket
            string sRequest = String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol());

            // create the socket and tell it to connect
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Option Chains data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int        iPort          = GetIQFeedPort("Lookup");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);
            }
            catch (SocketException ex)
            {
                MessageBox.Show(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
                DisableForm();
            }
        }
コード例 #2
0
        /// <summary>
        /// Event handler for the form load event.  
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void InitializeHistorySocket(string ip = "127.0.0.1", int port = -1)
        {
            IQ_Config config = new IQ_Config();

            // create the socket
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse(ip);

            // Historical data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int iPort = (port > 0 ? port : Helper.GetIQFeedPort("Lookup"));
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);

                // Set the protocol for the lsocket
                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));
            }
            catch (SocketException ex)
            {
                DisplayError(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message));
                // exit - catastrophic error (can't connect to IQFeed socket)
            }

        }
コード例 #3
0
        // Initialize the connection to IQFeed
        private void InitializeConnection()
        {
            IQ_Config config = new IQ_Config();

            // create the socket and tell it to connect
            m_sockLevel1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // pull the level 1 port out of the registry.  we use the Level 1 port because we want streaming updates
            int iPort = GetIQFeedPort("Level1");

            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // tell the socket to connect to IQFeed
                m_sockLevel1.Connect(ipendLocalhost);

                // Set the protocol for the socket
                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));

                // this example is using asynchronous sockets to communicate with the feed.  As a result, we are using .NET's BeginReceive and EndReceive calls with a callback.
                // we call our WaitForData function (see below) to notify the socket that we are ready to receive callbacks when new data arrives
                WaitForData("Level1");
            }
            catch (SocketException ex)
            {
                ErrorMessage("Did you forget to Login to IQFeed?\n{0}", ex.Message);
            }
        }
コード例 #4
0
        public HistorySocketThread()
        {
            IQ_Config config = new IQ_Config();

            // create the socket
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Historical data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int        iPort          = GetIQFeedPort("Lookup");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);

                // Set the protocol for the lsocket
                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));
            }
            catch (SocketException ex)
            {
                Console.WriteLine(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
            }
        }
コード例 #5
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MarketDepthSocketForm_Load(object sender, EventArgs e)
        {
            //Load the config object namespace which contains the latest protocol and your product ID.
            IQ_Config config = new IQ_Config();
            // Set the protocol for the socket
            string sRequest = String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol());

            // create the socket and tell it to connect
            m_sockMarketDepth = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Market Depth data is received from IQFeed on the Level2 port.
            // pull the Level2 port out of the registry
            int        iPort          = GetIQFeedPort("Level2");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockMarketDepth.Connect(ipendLocalhost);

                byte[] szRequest = new byte[sRequest.Length];
                szRequest = Encoding.ASCII.GetBytes(sRequest);
                int iBytesToSend = szRequest.Length;
                int iBytesSent   = m_sockMarketDepth.Send(szRequest, iBytesToSend, SocketFlags.None);

                // we call our WaitForData function (see below) to notify the socket that we are ready to receive callbacks when new data arrives
                WaitForData("MarketDepth");
            }
            catch (SocketException ex)
            {
                MessageBox.Show(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
                DisableForm();
            }
        }
コード例 #6
0
        // Initialize the connection to IQFeed
        private void InitializeConnection()
        {
            IQ_Config config = new IQ_Config();

            // create the socket
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Historical data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int iPort = GetIQFeedPort("Lookup");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);

                // Set the protocol for the lsocket
                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));
            }
            catch (SocketException ex)
            {
                ErrorMessage("Did you forget to Login to IQFeed?\n{0}", ex.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SymbolLookupSocketForm_Load(object sender, EventArgs e)
        {
            //Load the config object namespace which contains the latest protocol and your product ID.
            IQ_Config config = new IQ_Config();
            // Set the protocol for the socket
            string sRequest = String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol());

            // create the socket and tell it to connect
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Symbol Lookup data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int        iPort          = GetIQFeedPort("Lookup");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);
            }
            catch (SocketException ex)
            {
                MessageBox.Show(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
                DisableForm();
            }
            byte[] szRequest = new byte[sRequest.Length];
            szRequest = Encoding.ASCII.GetBytes(sRequest);
            int iBytesToSend = szRequest.Length;
            int iBytesSent   = m_sockLookup.Send(szRequest, iBytesToSend, SocketFlags.None);

            WaitForData("Symbol");
            // default to searching the symbol field.
            rbtnSymbol.Checked = true;
        }
コード例 #8
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing launching the feed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Level1ActiveXForm_Load(object sender, EventArgs e)
        {
            IQ_Config config = new IQ_Config();
            // launch the feed.
            string sProductID      = config.getProductID();
            string sProductVersion = "1.0";
            string sDeprecated     = "0.11111111";

            axIQFeedY1.RegisterClientApp(ref sProductID, ref sDeprecated, ref sProductVersion);
        }
コード例 #9
0
        /// <summary>
        /// Event that fires when a System Message is recieved from the feed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axIQFeedY1_SystemMessage(object sender, AxIQFEEDYLib._DIQFeedYEvents_SystemMessageEvent e)
        {
            // system messages are sent to inform the client about current system information.
            // In this example, we use the S,SERVER CONNECTED message to trigger setting the IQFeed Protocol we need.
            // For a list of system messages that can be sent and the fields each contains, please check the documentation page System Messages.
            lstData.Items.Insert(0, e.strSystemData);
            IQ_Config config = new IQ_Config();

            if (e.strSystemData.Contains("S,SERVER CONNECTED"))
            {
                string sProtocolVersion = config.getProtocol();
                axIQFeedY1.SetProtocol(ref sProtocolVersion);
            }
            LimitListItems();
        }
コード例 #10
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HistorySocketForm_Load(object sender, EventArgs e)
        {
            IQ_Config config = new IQ_Config();

            lstData.Columns.Add("Data received", -2);
            lstData.Columns[0].Width -= System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;

            // populate the request type dropdown
            cboHistoryType.Items.Add("Tick Datapoints");
            cboHistoryType.Items.Add("Tick Days");
            cboHistoryType.Items.Add("Tick Timeframe");
            cboHistoryType.Items.Add("Interval Datapoints");
            cboHistoryType.Items.Add("Interval Days");
            cboHistoryType.Items.Add("Interval Timeframe");
            cboHistoryType.Items.Add("Daily Datapoints");
            cboHistoryType.Items.Add("Daily Timeframe");
            cboHistoryType.Items.Add("Weekly Datapoints");
            cboHistoryType.Items.Add("Monthly Datapoints");
            cboHistoryType.SelectedIndex = 0;

            // create the socket
            m_sockLookup = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // Historical data is received from IQFeed on the Lookup port.
            // pull the Lookup port out of the registry
            int        iPort          = GetIQFeedPort("Lookup");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            try
            {
                // connect the socket
                m_sockLookup.Connect(ipendLocalhost);

                // Set the protocol for the lsocket
                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));
            }
            catch (SocketException ex)
            {
                MessageBox.Show(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
                DisableForm();
            }

            cboHistoryType.SelectedIndex = 0;
        }
コード例 #11
0
        /// <summary>
        /// Event handler for the form load event.
        ///     It controls updating the form controls and initializing the connection to IQFeed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StreamingBarsSocket_Load(object sender, EventArgs e)
        {
            // Setup the list control
            lstData.Columns.Add("Data received", -2);
            lstData.Columns[0].Width -= System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;

            // create the socket and tell it to connect
            m_sockDerivative = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // pull the derivate port out of the registry.  we use the derivative port because we want streaming updates
            int iPort = GetIQFeedPort("Derivative");

            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);
            IQ_Config  config         = new IQ_Config();

            try
            {
                // tell the socket to connect to IQFeed
                m_sockDerivative.Connect(ipendLocalhost);

                SendRequestToIQFeed(String.Format("S,SET PROTOCOL,{0}\r\n", config.getProtocol()));

                // this example is using asynchronous sockets to communicate with the feed.  As a result, we are using .NET's BeginReceive and EndReceive calls with a callback.
                // we call our WaitForData function (see below) to notify the socket that we are ready to receive callbacks when new data arrives
                WaitForData("Derivative");
            }
            catch (SocketException ex)
            {
                MessageBox.Show(String.Format("Oops.  Did you forget to Login first?\nTake a Look at the LaunchingTheFeed example app\n{0}", ex.Message), "Error Connecting to IQFeed");
                DisableForm();
            }

            cbIntervalType.SelectedIndex = 0;
            txtDatapoints.Text           = "100";
            txtDays.Text                    = "1";
            txtIntervalValue.Text           = "3600";
            txtUpdateIntervalInSeconds.Text = "0";
            txtSymbol.Text                  = "TESTSYMBOL";
        }
コード例 #12
0
        static void Main(string[] args)
        {
            IQ_Config config = new IQ_Config();

            Console.Title       = "C# Console Benchmark Tool - Press esc to exit";
            Console.WindowWidth = 120;

            // Launch IQConnect.
            Console.WriteLine("Launching IQConnect...");
            // This is a simple way to launch the feed letting the user specify thier own login/password.
            // If you need to see all the options for launching the feed, take a look at the "LaunchingTheFeed" app.
            System.Diagnostics.Process.Start("IQConnect.exe", String.Format("-product {0} -version {1}", config.getProductID(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()));

            // now that the feed is launched, connect to the admin port of IQFeed to get the status of the feed.  This allows us to wait until the user clicks connect before trying to process data.
            // create the socket and tell it to connect
            Socket sockIQFeed = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            Console.WriteLine("Admin socket created...");

            IPAddress ipLocalhost = IPAddress.Parse("127.0.0.1");

            // pull the admin port out of the registry.  we use the Level 1 port because we want streaming updates
            int        iPort          = GetIQFeedPort("Admin");
            IPEndPoint ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);

            Console.WriteLine("IPEndPoint created...");

            try
            {
                // tell the socket to connect to IQFeed
                sockIQFeed.Connect(ipendLocalhost);
                Console.WriteLine("Admin socket connected...");
                // Since we are in a console app and don't have the message pump provided by the Form
                // we are going to use blocking socket calls instead of creating the complexity of our own timer to use async socket calls.
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Connecting to IQFeed's Admin Port\n{0}", ex.Message);
            }

            // now that we are connected to the admin port, we need to read off that socket until we get a message indicating that IQFeed is connected to the server
            byte[] szSocketBuffer = new byte[Int16.MaxValue];
            // since we are using a blocking socket, a Receive value of zero indicates that the socket has been closed.
            int  iBytesReceived = 0;
            bool bShutDown      = false;

            while (!bShutDown && (iBytesReceived = sockIQFeed.Receive(szSocketBuffer)) > 0)
            {
                // with this connection, we aren't worried about efficiency of data processing
                // since there isn't going to be a lot of data delivered to the socket.  As a result
                // we just read the data off the socket and display it to the console and then process it.
                string sData = Encoding.ASCII.GetString(szSocketBuffer, 0, iBytesReceived);
                Console.WriteLine(sData);

                // there is a lot of useful data in the admin socket messages, but for this app, we only want to make sure the feed is connected
                // before closing the socket and moving on to the Level 1 data
                if (sData.Contains(",Connected,"))
                {
                    Console.WriteLine("IQFeed is connected to the server.");
                    Console.WriteLine("Closing Admin Socket...");
                    sockIQFeed.Shutdown(SocketShutdown.Both);
                    sockIQFeed.Close();
                    bShutDown = true;
                }
            }
            // IQFeed is connected.  Lets read in our commands file that was supplied in the command line arguments.
            string[] saCommands;
            string   sAllFileData = String.Format("S,SET PROTOCOL,{0}", config.getProtocol());

            try
            {
                string sFile = "";
                if (args.GetLength(0) > 0)
                {
                    sFile = args[0];
                }
                Console.WriteLine("Start reading commands from file {0}", sFile);

                if (sFile.Length > 0)
                {
                    // read commands in from the file
                    int    iCounter = 0;
                    string sLine;

                    // Read the file and load it into the array.
                    System.IO.StreamReader srFile = new System.IO.StreamReader(sFile);
                    while ((sLine = srFile.ReadLine()) != null)
                    {
                        sAllFileData += sLine;
                        sAllFileData += "\n";
                        iCounter++;
                    }
                    srFile.Close();
                }

                Console.WriteLine("Done reading commands from file {0}", sFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Reading commands file\n{0}", ex.Message);
            }
            saCommands = sAllFileData.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            // we have our list of commands, we know IQFeed is running, lets start getting some data
            Console.WriteLine("Connecting to Level 1 Port...");
            sockIQFeed     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            iPort          = GetIQFeedPort("Level1");
            ipendLocalhost = new IPEndPoint(ipLocalhost, iPort);
            Console.WriteLine("IPEndPoint updated...");

            try
            {
                // tell the socket to connect to IQFeed
                sockIQFeed.Connect(ipendLocalhost);
                Console.WriteLine("Level1 socket connected...");
                // Since we are in a console app and don't have the message pump provided by the Form
                // we are going to use blocking socket calls instead of creating the complexity of our own timer to use async socket calls.
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Connecting to IQFeed's Level1 Port\n{0}", ex.Message);
            }

            // send commands (from file) to IQConnect.
            foreach (string sCommand in saCommands)
            {
                byte[] szCommand = new byte[sCommand.Length + 2];
                szCommand = Encoding.ASCII.GetBytes(sCommand + "\r\n");
                int iBytesToSend = szCommand.Length;
                int iBytesSent   = sockIQFeed.Send(szCommand, iBytesToSend, SocketFlags.None);
                if (iBytesToSend == iBytesSent)
                {
                    Console.WriteLine("Sent command: {0} to IQFeed...", sCommand);
                }
                else
                {
                    Console.WriteLine("Unable to send command: {0} to IQFeed...", sCommand);
                }
            }


            // start processing data received from IQConnect.
            // variables for data processing
            iBytesReceived = 0;
            bShutDown      = false;
            byte byteLineFeed   = 10;
            int  iBytesLeftover = 0;
            int  iBytesToParse  = 0;

            // variables for stats tracking
            int    iFMessages      = 0;
            int    iPMessages      = 0;
            int    iQMessages      = 0;
            int    iTMessages      = 0;
            int    iSMessages      = 0;
            int    iNMessages      = 0;
            int    iRMessages      = 0;
            int    iMsgsLastSecond = 0;
            int    iTotalMsgs      = 0;
            double dSeconds        = 0.0;

            System.Diagnostics.Stopwatch watchTimer = new System.Diagnostics.Stopwatch();
            DateTime dtCurrent;

            watchTimer.Start();

            // loop while there is data to be read and the socket is open.
            while (!bShutDown && (iBytesReceived = sockIQFeed.Receive(szSocketBuffer, iBytesLeftover, szSocketBuffer.Length - iBytesLeftover, SocketFlags.None)) > 0)
            {
                iBytesToParse  = iBytesReceived;
                iBytesToParse += iBytesLeftover;
                iBytesLeftover = 0;
                // unlike with the admin port connection and with the other example apps,
                // with this connection, we ARE worried about efficiency of data processing.
                // Additionally, want to make sure this app is using the least amount of CPU possible.
                // As a result, we are not converting data to strings for processing.
                // Since we only want to know what type of message was received so we only need to
                // look at the starting character of each message and search for the delimiting character.

                // each line of output from the level 1 port of IQFeed is delimited with a line feed character (10)
                int iNewLinePos = Array.IndexOf(szSocketBuffer, byteLineFeed);
                int iMessagePos = 0;

                // as long as we found one, we know there is still a complete message in the buffer.  process it
                while (iNewLinePos > -1)
                {
                    iTotalMsgs++;
                    iMsgsLastSecond++;
                    switch (szSocketBuffer[iMessagePos])
                    {
                    case 81:     // Q
                        // Update Message
                        iQMessages++;
                        break;

                    case 84:     // T
                        // Timestamp Message
                        iTMessages++;
                        // we trigger our output to the screen when we receive a timestamp message.

                        // skip the first writeout if a complete second hasn't elapsed
                        dSeconds  = watchTimer.Elapsed.TotalSeconds;
                        dtCurrent = DateTime.Now;
                        if (dSeconds > 0.0)
                        {
                            Console.WriteLine(String.Format("F:{0}\tP:{1}\tQ:{2}\tT:{3}\tS:{4}\tN:{5}\tR:{6}\tLM:{7}\tTMS:{8:0.0}\tTIME:{9:.000000}", iFMessages, iPMessages, iQMessages, iTMessages, iSMessages, iNMessages, iRMessages, iMsgsLastSecond, iTotalMsgs / dSeconds, dtCurrent.ToOADate()));
                            // reset our "Messages in the last second" counter
                            iMsgsLastSecond = 0;
                        }
                        break;

                    case 70:     // F
                        // Fundamental Message
                        iFMessages++;
                        break;

                    case 80:     // P
                        // Summary Message
                        iPMessages++;
                        break;

                    case 82:     // R
                        // Regional Message
                        iRMessages++;
                        break;

                    case 78:     // N
                        // News Message
                        iNMessages++;
                        break;

                    case 83:     // S
                        // System Message
                        iSMessages++;
                        break;
                    }
                    // find the beginning of our next message.  If we have an incomplete message in the buffer
                    // or if we reach the end of the buffer normally, iNewLinePos will be -1 and we well exit the loop
                    iMessagePos = iNewLinePos + 1;
                    iNewLinePos = Array.IndexOf(szSocketBuffer, byteLineFeed, iMessagePos);
                }
                // now we need to check for an incomplete message and copy it to the beginning of the buffer for the next read from the socket
                if (iMessagePos < iBytesToParse)
                {
                    // we have an incomplete message
                    iBytesLeftover  = iBytesToParse;
                    iBytesLeftover -= iMessagePos;
                    // copy the left over bytes to the front of the buffer
                    Buffer.BlockCopy(szSocketBuffer, iMessagePos, szSocketBuffer, 0, iBytesLeftover);
                }

                // zero the rest of the buffer that was used to prevent parsing data multiple times in the next read
                for (int i = iBytesLeftover; i < iBytesToParse; i++)
                {
                    szSocketBuffer[i] = 0;
                }

                // check if the user hit the esc key to quit.
                if (CheckForUserBreak())
                {
                    Console.WriteLine("Interupted by user...");
                    Console.WriteLine("Closing Level1 Socket...");
                    sockIQFeed.Shutdown(SocketShutdown.Both);
                    sockIQFeed.Close();
                    bShutDown = true;
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Event handler for the form load event.  
        ///     It controls updating the form controls
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LaunchingTheFeedForm_Load(object sender, EventArgs e)
        {
            IQ_Config config = new IQ_Config();
            txtProductID.Text = config.getProductID();
            /*
             * Start code to check if IQFeed is installed
             */

            // IQFeed Installation directory is stored in the registry key:
            // HKLM\Software\DTN\IQFeed\EXEDIR
            MyRegistryKey key = MyRegistry.LocalMachine.OpenSubKey("SOFTWARE\\DTN\\IQFeed", true);
            if (key == null)
            {
                // if it isn't in that location, it is possible the user is running and x64 OS.  Check the windows virtualized registry location
                key = MyRegistry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\DTN\\IQFeed", true);
            }
            if (key != null)
            {
                string sLocation = key.GetValue("EXEDIR", "").ToString();
                // close the key since we don't need it anymore
                key.Close();
                // verify there is a \ on the end before we append the exe name
                if (!(sLocation.EndsWith("\\") || sLocation.EndsWith("/")))
                {
                    sLocation += "\\";
                }
                sLocation += "IQConnect.exe";
                // update the location in the text box
                txtIQConnectLocation.Text = sLocation;
            }
            else
            {
                MessageBox.Show(String.Format("Unable to find IQFeed Installation.\nDid you forget Install IQFeed?\nMake sure you installed more than just the developer package."), "Could not find IQFeed");
                txtIQConnectLocation.Text = "IQFeed Not Installed";
            }
            /*
             * end code to check if IQFeed is installed
             */

            /*
             * Start code to grab IQFeed settings from the registry
             */

            // pull the login and password, save login info, and autoconnect settings out of the 
            // registry (if they are already stored)
            key = null;
            key = MyRegistry.CurrentUser.OpenSubKey("Software\\DTN\\IQFeed\\Startup", true);

            // NOTE: we don't need to check for the virtualized registry key on x64 here since these values are in the HKEY_CURRENT_USER hive.

            if (key != null)
            {
                string sData = key.GetValue("Login", "").ToString();
                txtLoginID.Text = sData;
                sData = key.GetValue("Password", "").ToString();
                txtPassword.Text = sData;
                sData = key.GetValue("AutoConnect", "0").ToString();
                if (sData.Equals("1"))
                {
                    ckbxAutoconnect.Checked = true;
                }
                sData = key.GetValue("SaveLoginPassword", "0").ToString();
                if (sData.Equals("1"))
                {
                    ckbxSaveLoginInfo.Checked = true;
                }
            }

            /*
             * End code to check if IQFeed is installed
             */

            // populate the productversion from the assembly from this app
            txtProductVersion.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
        }