Exemple #1
0
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pastTimer.Stop();
            SessionStatusListener statusListener = new SessionStatusListener(mSession);

            // Check for connected session and take action before application close
            try
            {
                // Confirm Connected
                if (statusListener.Connected)
                {
                    sessionTextBox.Text = "Disconnecting";
                    mSession.logout();
                    Thread.Sleep(5000);
                    mSession.Dispose();
                    Application.Exit();
                }

                // Any other status than connected, close the application
                else
                {
                    actiBox.AppendText("CAUTION: NO SESSION DETECTED" + Environment.NewLine);
                    actiBox.AppendText("NO SESSION DETECTED" + Environment.NewLine);
                    Application.Exit();
                }
            }
            catch (Exception closeErr)
            {
                Console.WriteLine(closeErr);
            }
        }
Exemple #2
0
        private void BSFX_FormClosing(object sender, FormClosingEventArgs e)
        {
            SessionStatusListener statusListener = new SessionStatusListener(mSession);

            // Check for connected session and take action before application close
            try
            {
                priceBW.CancelAsync();
                // Confirm Connected
                if (statusListener.Connected)
                {
                    sessionTextBox.Text = "Disconnecting";
                    mSession.logout();
                    Thread.Sleep(5000);
                    mSession.Dispose();
                    Application.Exit();
                }

                // Any other status than connected, close the application
                else
                {
                    actiBox.AppendText("CAUTION: NO SESSION DETECTED.. CLOSING BSFX" + Environment.NewLine);
                    Application.Exit();
                }
            }
            catch (Exception closeErr)
            {
                Console.WriteLine(closeErr);
            }
        }
Exemple #3
0
        public void login()
        {
            // Strings for session variables
            sessionTextBox.Text = "Connecting...";
            sUserID             = userIDbox.Text.ToString();
            sPassword           = passwordBox.Text.ToString();
            sURL = "http://www.fxcorporate.com/Hosts.jsp";
            Settings.Default.sUserID   = sUserID;
            Settings.Default.sPassword = sPassword;
            Settings.Default.Save();

            //Try to create a session and connect to FXCM servers.
            try
            {
                //Session creation
                mSession = O2GTransport.createSession();
                //Session Listener
                SessionStatusListener statusListener = new SessionStatusListener(mSession);
                mSession.subscribeSessionStatus(statusListener);
                //Table Listener
                TableListener tableListener = new TableListener();
                mSession.useTableManager(O2GTableManagerMode.Yes, null);
                // Response Listener
                ResponseListener responseListener = new ResponseListener(mSession);
                mSession.subscribeResponse(responseListener);
                // LOG-IN
                statusListener.login(sUserID, sPassword, sURL, sConnection);
                Thread.Sleep(100);

                //Confirm Connected
                if (statusListener.Connected)
                {
                    sessionTextBox.BackColor = Color.Green;
                    actiBox.AppendText("***CONNECTED***" + Environment.NewLine);
                    sessionTextBox.Text = "CONNECTED";
                }

                else if (statusListener.Disconnected)
                {
                    for (int i = 0; i < 25; i++)
                    {
                        login();
                    }
                }
                // Confirm Error, then end login
                else if (statusListener.Error)
                {
                    mSession.logout();
                    while (!statusListener.Disconnected)
                    {
                        Thread.Sleep(50);
                    }
                    sessionTextBox.BackColor = Color.Red;
                    sessionTextBox.Text      = "DISCONNECTED";
                    actiBox.AppendText("Login Failed!" + Environment.NewLine);
                }

                O2GSessionDescriptorCollection descs = mSession.getTradingSessionDescriptors();
                foreach (O2GSessionDescriptor desc in descs)
                {
                    mSession.setTradingSession("sessionID", "pin");
                }
                priceBW.RunWorkerAsync();
            }
            catch (Exception loginErr)
            {
                Console.WriteLine("Exception: {0}", loginErr.ToString());
            }
        }