/// <summary> /// Init and start TT API. /// </summary> /// <param name="instance">XTraderModeTTAPI instance</param> /// <param name="ex">Any exception generated from the ApiCreationException</param> public void ttApiInitHandler(TTAPI api, ApiCreationException ex) { if (ex == null) { m_TTAPI = (UniversalLoginTTAPI)api; m_TTAPI.AuthenticationStatusUpdate += new EventHandler<AuthenticationStatusUpdateEventArgs>(m_TTAPI_AuthenticationStatusUpdate); m_TTAPI.Start(); } else if (!ex.IsRecoverable) { MessageBox.Show("API Initialization Failed: " + ex.Message); } }
/// <summary> /// Init and start TT API. /// </summary> /// <param name="instance">XTraderModeTTAPI instance</param> /// <param name="ex">Any exception generated from the ApiCreationException</param> public void ttApiInitHandler(TTAPI api, ApiCreationException ex) { if (ex == null) { m_TTAPI = (XTraderModeTTAPI)api; m_TTAPI.ConnectionStatusUpdate += new EventHandler<ConnectionStatusUpdateEventArgs>(ttapiInstance_ConnectionStatusUpdate); m_TTAPI.Start(); } else if (!ex.IsRecoverable) { MessageBox.Show("API Initialization Failed: " + ex.Message); } }
/// <summary> /// Event notification for status of TT API initialization /// </summary> public void ttApiInitComplete(TTAPI api, ApiCreationException ex) { if (ex == null) { // Authenticate your credentials m_apiInstance = (UniversalLoginTTAPI)api; m_apiInstance.AuthenticationStatusUpdate += new EventHandler<AuthenticationStatusUpdateEventArgs>(apiInstance_AuthenticationStatusUpdate); m_apiInstance.Start(); } else { Console.WriteLine("TT API Initialization Failed: {0}", ex.Message); Dispose(); } }
/// <summary> /// Init and start TT API. /// </summary> /// <param name="instance">XTraderModeTTAPI instance</param> /// <param name="ex">Any exception generated from the ApiCreationException</param> public void ttApiInitHandler(TTAPI api, ApiCreationException ex) { if (ex == null) { m_TTAPI = (XTraderModeTTAPI)api; m_TTAPI.ConnectionStatusUpdate += new EventHandler<ConnectionStatusUpdateEventArgs>(ttapiInstance_ConnectionStatusUpdate); m_TTAPI.Start(); m_customerDefaultsSubscription = new CustomerDefaultsSubscription(m_TTAPI.Session, Dispatcher.Current); m_customerDefaultsSubscription.CustomerDefaultsChanged += new EventHandler(m_customerDefaultsSubscription_CustomerDefaultsChanged); m_customerDefaultsSubscription.Start(); } else if (!ex.IsRecoverable) { MessageBox.Show("API Initialization Failed: " + ex.Message); } }
public void Dispose() { lock (m_lock) { if (!m_disposed) { if (PlsDictionary != null) { foreach (ProductKey Pkey in PlsDictionary.Keys.ToList()) { PlsDictionary[Pkey].Update -= PLSEventHandler; PlsDictionary[Pkey].Dispose(); PlsDictionary[Pkey] = null; } PlsDictionary = null; } if (IcsDictionary != null) { foreach (ProductKey Pkey in IcsDictionary.Keys.ToList()) { IcsDictionary[Pkey].InstrumentsUpdated -= ICUEventHandler; IcsDictionary[Pkey].Dispose(); IcsDictionary[Pkey] = null; } IcsDictionary = null; } if (IlsDictionary != null) { foreach (InstrumentKey IKey in IlsDictionary.Keys.ToList()) { for (int j = 0; j < ilsUpdateList.Count; j++) { IlsDictionary[IKey].Update -= ilsUpdateList[j]; } IlsDictionary[IKey].Dispose(); IlsDictionary[IKey] = null; } IlsDictionary = null; } if (PsDictionary != null) { foreach (InstrumentKey Ikey in PsDictionary.Keys.ToList()) { PsDictionary[Ikey].FieldsUpdated -= priceUpdatedEventHandler; PsDictionary[Ikey].Dispose(); PsDictionary[Ikey] = null; } PsDictionary = null; } if (TsDictionary != null) { foreach (InstrumentKey IKey in TsDictionary.Keys.ToList()) { TsDictionary[IKey].OrderUpdated -= m_ts_OrderUpdated; TsDictionary[IKey].OrderAdded -= m_ts_OrderAdded; TsDictionary[IKey].OrderDeleted -= m_ts_OrderDeleted; TsDictionary[IKey].OrderFilled -= orderFilledEventHandler; TsDictionary[IKey].OrderRejected -= m_ts_OrderRejected; TsDictionary[IKey].Dispose(); TsDictionary[IKey] = null; } TsDictionary = null; } // Begin shutdown the TT API TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }
public void Init() { // Use "Universal Login" Login Mode TTAPI.UniversalLoginModeDelegate ulDelegate = new TTAPI.UniversalLoginModeDelegate(ttApiInitComplete); TTAPI.CreateUniversalLoginTTAPI(Dispatcher.Current, ulDelegate); }
}// 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()
public void Dispose() { TTAPI.ShutdownCompleted += TTAPI_ShutdownCompleted; TTAPI.Shutdown(); }
public void Init(TTAPIOptions apiConfig) { ApiInitializeHandler apiInitializeHandler = new ApiInitializeHandler(ttNetApiInitHandler); TTAPI.CreateTTAPI(Dispatcher.Current, apiConfig, apiInitializeHandler); }
public void Dispose() { lock (m_lock) { if (!m_disposed) { TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }