/// <summary>
 /// Initialize TT API
 /// </summary>
 public void Init()
 {
     // Use "Universal Login" Login Mode
     TTAPI.UniversalLoginModeDelegate ulDelegate = new
                                                   TTAPI.UniversalLoginModeDelegate(ttApiInitComplete);
     TTAPI.CreateUniversalLoginTTAPI(Dispatcher.Current, ulDelegate);
 }
Esempio n. 2
0
        static void Main()
        {
            // Create and attach a UI Dispatcher to the main Form
            // When the form exits, this scoping block will auto-dispose of the Dispatcher
            using (var disp = Dispatcher.AttachUIDispatcher())
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Create an instance of TTAPI.
                frmOrderUpdate monitorOrders = new frmOrderUpdate();
                TTAPI.UniversalLoginModeDelegate ulDelegate = new TTAPI.UniversalLoginModeDelegate(monitorOrders.initTTAPI);
                TTAPI.CreateUniversalLoginTTAPI(disp, ulDelegate);

                Application.Run(monitorOrders);
            }
        }
 public void Init()
 {
     // Use "Universal Login" Login Mode
     TTAPI.UniversalLoginModeDelegate ulDelegate = new TTAPI.UniversalLoginModeDelegate(ttApiInitComplete);
     TTAPI.CreateUniversalLoginTTAPI(Dispatcher.Current, ulDelegate);
 }
Esempio n. 4
0
        }// StartInitAPI().

        //
        /// <summary>
        /// Create UniversalLogin or XTrader API instance.
        /// Called by the TTService worker thread.
        /// </summary>
        private void InitAPI()
        {
            if (m_UseXTraderLogin)
            {   // Follow the local XTrader login.
                // Note: This will not fail even if no XTrader is running.
                // Rather, the call m_XAPI.ConnectToXTrader(), below, will get stuck forever if there is not XTrader running.
                //System.Windows.Forms.MessageBox.Show("test TT1");
                // Check for Xtrader process, postpone connecting if its NOT running.
                //System.Windows.Forms.MessageBox.Show("test5");
                System.Diagnostics.Process[] procs = null;
                try
                {
                    if (m_CheckXTraderProcessExists)
                    {
                        procs = System.Diagnostics.Process.GetProcessesByName("x_trader");
                    }
                }
                catch (Exception e)
                {
                    if (m_Log != null)
                    {
                        m_Log.NewEntry(LogLevel.Warning, "InitAPI: Exception {0}.  Turning off XTrader searching.  Will try to start API directly.", e.Message);
                    }
                    m_CheckXTraderProcessExists = false;                    // Ok, security issues may have caused this to fail.  Nothing to do be proceed.
                }
                if (m_CheckXTraderProcessExists && procs != null && procs.Length < 1)
                {   // There is NO Xtrader running.
                    if (m_Log != null)
                    {
                        m_Log.NewEntry(LogLevel.Warning, "InitAPI: Found NO XTrader process. Waiting {0} secs to look again.", m_WaitForAPISeconds);
                    }
                    Thread.Sleep(1000 * m_WaitForAPISeconds);
                    try
                    {
                        if (!m_Stopping && m_Dispatcher != null)
                        {
                            m_Dispatcher.BeginInvoke(new Action(InitAPI));
                        }
                    }
                    catch (Exception e)
                    {   // This exception can happen when we are shutting down, before we connect.
                        m_Log.NewEntry(LogLevel.Warning, "InitAPI: Exception when re-invoking. Exiting. Exception = {0}.", e.Message);
                    }
                }
                else
                {   // XTrader is running, connect to it.
                    if (m_Log != null)
                    {
                        m_Log.NewEntry(LogLevel.Warning, "InitAPI: Creating XTrader mode API.");
                    }
                    TTAPI.XTraderModeDelegate d       = new TTAPI.XTraderModeDelegate(TT_XTraderInitComplete);
                    XTraderModeTTAPIOptions   options = new XTraderModeTTAPIOptions();
                    options.XTServicesConnectionTimeout = new TimeSpan(0, 0, 20);
                    try
                    {
                        TTAPI.CreateXTraderModeTTAPI(m_Dispatcher, options, d);
                    }
                    catch (Exception e)
                    {
                        if (m_Log != null)
                        {
                            m_Log.NewEntry(LogLevel.Warning, "InitAPI: TT Exception {0}.", e.Message);
                        }
                    }
                }
            }
            else
            {                                                                                                                 // Use "Universal Login" Login Mode
                TTAPI.UniversalLoginModeDelegate ulDelegate = new TTAPI.UniversalLoginModeDelegate(TT_UniversalInitComplete); // Call back after API is created.
                try
                {
                    TTAPI.CreateUniversalLoginTTAPI(m_Dispatcher, ulDelegate);
                }
                catch (Exception e)
                {
                    if (m_Log != null)
                    {
                        m_Log.NewEntry(LogLevel.Warning, "InitAPI: TT Exception {0}.", e.Message);
                    }
                }
            }
            //System.Windows.Forms.MessageBox.Show("test TT2");
        }// InitAPI()