private void SubscribeToInstrument(ProductKey productKey, string contract) { InstrumentLookupSubscription req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, productKey, contract); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(req_Update); req.Start(); }
/// <summary> /// Shuts down the TT API /// </summary> public void Dispose() { lock (m_lock) { if (!m_disposed) { // Unattached callbacks and dispose of all subscriptions if (m_req != null) { m_req.Update -= m_req_Update; m_req.Dispose(); m_req = null; } if (m_ps != null) { m_ps.FieldsUpdated -= m_ps_FieldsUpdated; m_ps.Dispose(); m_ps = null; } // Begin shutdown the TT API TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }
/// <summary> /// Clean up TTAPI objects /// </summary> public void Dispose() { lock (m_lock) { if (!m_disposed) { // Detach callbacks and dispose of all subscriptions if (m_req != null) { m_req.Dispose(); m_req = null; } if (m_tsSub != null) { m_tsSub.Dispose(); } m_tsSub = null; } // Shutdown the Dispatcher if (m_disp != null) { m_disp.BeginInvokeShutdown(); m_disp = null; } m_disposed = true; } }
/// <summary> /// Find a given instrument based on the InstrumentKey. /// </summary> /// <param name="instrumentKey">InstrumentKey</param> private void findInstrument(InstrumentKey instrumentKey) { InstrumentLookupSubscription sub = new InstrumentLookupSubscription(m_session, m_dispatcher, instrumentKey); sub.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupSubscription_Update); sub.Start(); }
/// <summary> /// Event notification for status of authentication /// </summary> public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { // lookup the leg instruments ProductKey prodKeyLeg = new ProductKey(MarketKey.Cbot, ProductType.Future, "ZN"); // We will use a dictionary to hold all instrument requests and update it when each instrument is found. // Once all lookup requests for the legs are complete, we can continue with the creation of the spread. // tagValue will be used in the dictionary to identify each lookup request. int tagValue = 1000; m_req1 = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Mar13"); m_req1.Tag = tagValue; m_spreadLegKeys.Add(tagValue, null); m_req1.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req1.Start(); tagValue++; m_req2 = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Jun13"); m_req2.Tag = tagValue; m_spreadLegKeys.Add(tagValue, null); m_req2.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req2.Start(); } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
void CreateAutoSpreader(object sender, InstrumentLookupSubscriptionEventArgs e) { if (e.Instrument != null && e.Error == null) { // Instrument was found Console.WriteLine("Found: {0}", e.Instrument.Name); InstrumentDictionary.Add(e.Instrument.Key, e.Instrument); // Update the dictionary to indicate that the instrument was found. InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription; if (SpreadLegKeys.ContainsKey((int)instrLookupSub.Tag)) { SpreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument; } } else if (e.IsFinal) { // Instrument was not found and TT API has given up looking for it Console.WriteLine("Cannot find instrument: {0}", e.Error.Message); Subs.Dispose(); } // If we have found all of the leg instruments, proceed with the creation of the spread. if (HaveWeFoundAllLegs()) { Console.WriteLine("All leg instruments have been found. Creating the spread..."); // SpreadDetails related properties SpreadDetails spreadDetails = new SpreadDetails(); spreadDetails.Name = AutoSpreaderName; for (int i = 0; i < DbTickerList.Count; i++) { Instrument instrument = SpreadLegKeys[i + 1]; var ValidOrderFeeds = instrument.GetValidOrderFeeds(); while (ValidOrderFeeds.Count == 0) { ValidOrderFeeds = instrument.GetValidOrderFeeds(); Console.WriteLine("Attempting to get valid forder feed for: " + DbTickerList[i]); } SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, ValidOrderFeeds[0].ConnectionKey); spreadlegDetails.SpreadRatio = (int)RatioAndMultiplier["Ratio"][i]; spreadlegDetails.PriceMultiplier = RatioAndMultiplier["Multiplier"][i]; spreadlegDetails.CustomerName = "<DEFAULT>"; spreadlegDetails.PayupTicks = PayUpTicks; spreadDetails.Legs.Append(spreadlegDetails); } // Create an AutospreaderInstrument corresponding to the synthetic spread Air = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails); Air.Completed += new EventHandler <CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed); Air.Submit(); } }
} //InstrumentCatalog_InstrumentsUpdated() // // private void InstrumentLookup_InstrumentUpdated(object sender, InstrumentLookupSubscriptionEventArgs eventArgs) { if (eventArgs.Instrument != null && eventArgs.Error == null) { UVProd.InstrumentName instrName; Instrument ttInstrument = eventArgs.Instrument; if (TTConvertNew.TryConvert(ttInstrument, out instrName)) { // Success in converting to our internal naming scheme. InstrumentDetails details; if (m_InstrumentDetails.TryGetValue(instrName, out details)) { // This instrument was already added! if (!ttInstrument.Key.Equals(details.Key)) { Log.NewEntry(LogLevel.Warning, "{0}: Instrument {1} found before with non-unique key {2}!", this.Name, instrName.FullName, instrName.SeriesName); } else { Log.NewEntry(LogLevel.Warning, "{0}: Instrument {1} found before and keys match! Good.", this.Name, instrName.FullName); } } else { // Add new InstrumentDetails m_KeyToInstruments.Add(ttInstrument.Key, instrName); m_InstrumentDetails.Add(instrName, ttInstrument.InstrumentDetails); Log.NewEntry(LogLevel.Minor, "{0}: Instruments found {1} <---> {2}.", this.Name, instrName, ttInstrument.Key.ToString()); if (sender is InstrumentLookupSubscription) { InstrumentLookupSubscription instSubscription = (InstrumentLookupSubscription)sender; if (!m_InstrumentLookups.ContainsValue(instSubscription)) { // If user called for instr info using only a series name, and not key, we couldn't store subscription object then. // Store it now! m_InstrumentLookups.Add(ttInstrument.Key, instSubscription); Log.NewEntry(LogLevel.Minor, "{0}: Adding new Instrument Subscription found {1}.", this.Name, instrName); } } } } else { // Failed to convert TT instrument to a UV Instrument. // This happens because either their name is too confusing to know what it is. // Or, more likely, we are set to ignore the product type (options, equity, swaps). Log.NewEntry(LogLevel.Warning, "{0}: Instrument creation failed for {1}.", this.Name, ttInstrument.Key.ToString()); } OnInstrumentsFound(); } else if (eventArgs.IsFinal) { // Instrument was not found and TTAPI has given up on looking. if (eventArgs.Instrument != null) { Log.NewEntry(LogLevel.Warning, "{0}: TTAPI gave up looking for {1}.", this.Name, eventArgs.Instrument.Key.ToString()); } else { Log.NewEntry(LogLevel.Warning, "{0}: TTAPI gave up looking for something. ", this.Name, eventArgs.RequestInfo.ToString()); } } }//InstrumentLookup_Callback()
public void FindInstrument(ProductKey productKey, string contract) { Console.WriteLine(String.Format("TT API FindInstrument {0} {1}", productKey, contract)); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, productKey, contract); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); }
public void startInstrumentLookupSubscriptionsFromDataTable(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { foreach (DataRow item in TickerTable.Rows) { ttapiTicker currentTicker; if (item.Field <bool>("IsSpreadQ")) { currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker: item.Field <string>("Ticker"), productType: "SPREAD"); } else { currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker: item.Field <string>("Ticker"), productType: "FUTURE"); } if (currentTicker.marketKey == "CME") { mkey = MarketKey.Cme; } else if (currentTicker.marketKey == "ICE_IPE") { mkey = MarketKey.Ice; } if (currentTicker.productType == "FUTURE") { ptype = ProductType.Future; } else if (currentTicker.productType == "SPREAD") { ptype = ProductType.Spread; } InstrumentKey IKey = new InstrumentKey(new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); Console.WriteLine(currentTicker.SeriesKey); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); //Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Spread, "CL"), "Nov16:-1xDec16"); for (int i = 0; i < ilsUpdateList.Count; i++) { Ils.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(ilsUpdateList[i]); } IlsDictionary.Add(IKey, Ils); Ils.Start(); } } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
/// <summary> /// Begin work on this thread /// </summary> public void Init() { // Perform an instrument lookup m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(m_marketKey, m_productType, m_product), m_contract); //m_req.Update += newEventHandler<InstrumentLookupSubscriptionEventArgs>(req_Update); m_req.Start(); }
public void SubscribeInstrument(TTInstrument ttinstr) { cout("TengineTT: Subscribing to Instrument: {0}", ttinstr); InstrumentLookupSubscription req = new InstrumentLookupSubscription(m_TTAPI.Session, m_disp, ttinstr.ProductKey, ttinstr.Contract); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(req_Update); m_lreq.Add(req); req.Start(); }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> private void FindInstrument(IList <InstrumentKey> keys) { if ((keys.Count > 0) && (keys.Count <= MAX_INSTRUMENT_COUNT)) { SetComponentText(toolStripStatusLabel1, "Drag & Drop detected. Initializing instrument..."); // dispose of any current instrument models if (m_bindingModels != null) { foreach (var entry in m_bindingModels) { entry.Value.ThreadID = ""; entry.Value.Exchange = ""; entry.Value.Product = ""; entry.Value.ProdType = ""; entry.Value.Contract = ""; entry.Value.BidPrice = ""; entry.Value.AskPrice = ""; entry.Value.LastPrice = ""; entry.Value.Dispatcher.BeginInvokeShutdown(); } } // Release any current data bindings ReleaseDataBinding(); // (re) instantiate our binding instrument model m_bindingModels = new Dictionary <InstrumentKey, InstrumentModel>(MAX_INSTRUMENT_COUNT); // index assigned to each instrument which corresponds to the GUI output int index = 1; foreach (InstrumentKey key in keys) { Console.WriteLine(String.Format("TT API FindInstrument {0}", key.ToString())); // create the model for the instrument & set the component data bindings InstrumentModel model = new InstrumentModel(this); SetDataBinding(index++, model); // add the instrument model to our lookup table m_bindingModels.Add(key, model); // Instrument lookups are all still on the main application thread InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); } } else { MessageBox.Show("This application accepts a maximum of " + MAX_INSTRUMENT_COUNT + " contracts."); } }
/// <summary> /// Perform the instrument lookups /// </summary> public void Init() { foreach (ContractDetails cd in m_lcd) { InstrumentLookupSubscription req = new InstrumentLookupSubscription( m_apiInstance.Session, Dispatcher.Current, new ProductKey(cd.m_marketKey, cd.m_productType, cd.m_product), cd.m_contract); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(req_Update); m_lreq.Add(req); req.Start(); } }
public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { Contract C = new Contract(); C.Init(this, MainForm, apiInstance); InstrumentLookupSubscription req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, new ProductKey("CME", "FUTURE", "HE"), "Feb19"); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(C.req_Update); req.Start(); MainForm.XtraderConnected("HE Feb19", C); }
/// <summary> /// Event notification for instrument lookup /// </summary> void m_req_Update(object sender, InstrumentLookupSubscriptionEventArgs e) { if (e.Instrument != null && e.Error == null) { // Instrument was found Console.WriteLine("Found: {0}", e.Instrument.Name); // Update the dictionary to indicate that the instrument was found. InstrumentLookupSubscription instrLookupSub = sender as InstrumentLookupSubscription; if (m_spreadLegKeys.ContainsKey((int)instrLookupSub.Tag)) { m_spreadLegKeys[(int)instrLookupSub.Tag] = e.Instrument; } } else if (e.IsFinal) { // Instrument was not found and TT API has given up looking for it Console.WriteLine("Cannot find instrument: {0}", e.Error.Message); Dispose(); } // If we have found all of the leg instruments, proceed with the creation of the spread. if (HaveWeFoundAllLegs()) { Console.WriteLine("All leg instruments have been found. Creating the spread..."); // SpreadDetails related properties SpreadDetails spreadDetails = new SpreadDetails(); spreadDetails.Name = "My Spread"; int i = 0; // Add the legs to the SpreadDetails foreach (Instrument instrument in m_spreadLegKeys.Values) { // In this example, the order is routed to the first order feed in the list of valid order feeds. // You should use the order feed that is appropriate for your purposes. SpreadLegDetails spreadlegDetails = new SpreadLegDetails(instrument, instrument.GetValidOrderFeeds()[0].ConnectionKey); spreadlegDetails.SpreadRatio = (i % 2 == 0) ? 1 : -1; spreadlegDetails.PriceMultiplier = (i % 2 == 0) ? 1 : -1; spreadlegDetails.CustomerName = "<Default>"; spreadDetails.Legs.Append(spreadlegDetails); i++; } // Create an AutospreaderInstrument corresponding to the synthetic spread m_casReq = new CreateAutospreaderInstrumentRequest(m_apiInstance.Session, Dispatcher.Current, spreadDetails); m_casReq.Completed += new EventHandler <CreateAutospreaderInstrumentRequestEventArgs>(m_casReq_Completed); m_casReq.Submit(); } }
/// <summary> /// Launch an autospreader instrument to a selected order server. /// First find the instrument then launch it to the selected order feed. /// </summary> private void buttonLaunch_Click(object sender, EventArgs e) { DataGridViewSelectedCellCollection selectedCells = dataGridViewSpreadView.SelectedCells; if (selectedCells.Count > 0) { SpreadDetails currentSpreadDetails = ((MutableSpreadDetails)selectedCells[0].OwningRow.DataBoundItem).SpreadDetails; InstrumentLookupSubscription instrumentLookupSubscription = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, currentSpreadDetails.InstrumentKey); instrumentLookupSubscription.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupSubscription_Update); instrumentLookupSubscription.Start(); } }
void instrumentLookupRequest_Update(object sender, InstrumentLookupSubscriptionEventArgs e) { TTInstrument tti; Console.WriteLine("ILR_Update on Thread"); if (e.Instrument != null && e.Error == null) { Console.WriteLine("SUBSCRIBED on thread: " + e.Instrument.Name); // successfully subscribed to an instrument so request prices if (e.Instrument.Key.IsAutospreader) { tti = processSpreadFound(e.Instrument); } else { tti = processInstrumentFound(e.Instrument); // If this instrument request was tagged, then put this instrument request // in sentInstrumentRequests with the tag as the key InstrumentLookupSubscription instrumentRequest = sender as InstrumentLookupSubscription; string tag = instrumentRequest.Tag as string; if (tag != null && !tag.Equals("")) { _sentInstrumentRequests[tag] = tti; } } if (OnInstrumentFound != null) { OnInstrumentFound(tti, true); } } else if (e.IsFinal) { Console.WriteLine("{0} {1}", e.RequestInfo.IsByName, e.RequestInfo.InstrumentName); // Instrument was not found and TTAPI has given up looking for it if (e.Instrument == null) { tti = null; } else { tti = new TTInstrument(e.Instrument); } if (OnInstrumentFound != null) { OnInstrumentFound(tti, false); } } }
/// <summary> /// Shuts down the TT API /// </summary> public void Dispose() { lock (m_lock) { if (!m_disposed) { // Unattached callbacks and dispose of all subscriptions if (m_req1 != null) { m_req1.Update -= m_req_Update; m_req1.Dispose(); m_req1 = null; } if (m_req2 != null) { m_req2.Update -= m_req_Update; m_req2.Dispose(); m_req2 = null; } if (m_ps != null) { m_ps.FieldsUpdated -= m_ps_FieldsUpdated; m_ps.Dispose(); m_ps = null; } if (m_ts != null) { m_ts.OrderAdded -= m_ts_OrderAdded; m_ts.OrderDeleted -= m_ts_OrderDeleted; m_ts.OrderFilled -= m_ts_OrderFilled; m_ts.OrderRejected -= m_ts_OrderRejected; m_ts.OrderUpdated -= m_ts_OrderUpdated; m_ts.Dispose(); m_ts = null; } if (m_casReq != null) { m_casReq.Completed -= m_casReq_Completed; m_casReq.Dispose(); m_casReq = null; } // Begin shutdown the TT API TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }
private void UpdateInstrumentSubscription() { InstruSubscription instru; if (_instruQueue.TryDequeue(out instru)) { log.Info($"Suscribe to instrument: {instru.InstruId}"); priceSub = new InstrumentLookupSubscription(_apiInstance.Session, Dispatcher.Current, new InstrumentKey(instru.Market, instru.InstruType, instru.ProductName, instru.InstruId)); priceSub.Update += ReqUpdate; m_lreq.Add(priceSub); priceSub.Start(); } }
/// <summary> /// Click event which will initiate the price subscription /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConnect_Click(object sender, EventArgs e) { UpdateStatusBar("Connecting to Instrument..."); // Create a product key from the given values ProductKey key = new ProductKey(this.txtExchange.Text, (ProductType)this.cboProductType.SelectedItem, this.txtProduct.Text); // Find out instrument based on the previously created key and the contract name InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(this.m_TTAPI.Session, Dispatcher.Current, key, this.txtContract.Text); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); }
private void frmSOD_ManualFill_DragDrop(object sender, DragEventArgs e) { foreach (InstrumentKey key in e.Data.GetInstrumentKeys()) { // Update the Status Bar text. UpdateStatusBar(String.Format("TT API FindInstrument {0}", key.ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrRequest_Update); instrRequest.Start(); // Only allow the first instrument. break; } }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> public void FindInstrument(IList<InstrumentKey> keys) { if (keys.Count == 1) { UpdateStatusBar("Drag & Drop detected. Initializing instrument..."); Console.WriteLine(String.Format("TT API FindInstrument {0}", keys[0].ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, keys[0]); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); } else { MessageBox.Show("This application only accepts a single Contract"); } }
public void shutdownTTAPI() { // Dispose of all request objects if (req != null) { req.Dispose(); req = null; } // Shutdown the API if (apiInstance != null) { apiInstance.Shutdown(); apiInstance = null; } }
public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cbot, ProductType.Future, "ZN"), "Sep12"); req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(req_Update); req.Start(); } else { Console.WriteLine("Login Failed: " + e.Status.StatusMessage); Dispose(); } }
public void SubscribeToInstrument(InstrumentDescriptor descriptor) { if (_dispatcher.InvokeRequired()) { _dispatcher.BeginInvoke(() => { SubscribeToInstrument(descriptor); }); return; } InstrumentLookupSubscription req = new InstrumentLookupSubscription(_apiSession, Dispatcher.Current, descriptor.ProductKey, descriptor.ContractName); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupRequest_Update); req.Start(); }
void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Future, "ES"), "Mar13"); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(req_Update); req.Start(); } else { Console.WriteLine("Login Failed: " + e.Status.StatusMessage); Dispose(); } }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> public void FindInstrument(IList <InstrumentKey> keys) { foreach (InstrumentKey key in keys) { // Update the Status Bar text. UpdateStatusBar(String.Format("TT API FindInstrument {0}", key.ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += instrRequest_Completed; instrRequest.Tag = key.ToString(); instrRequest.Start(); // Only allow the first instrument. break; } }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> public void FindInstrument(IList <InstrumentKey> keys) { if (keys.Count == 1) { UpdateStatusBar("Drag & Drop detected. Initializing instrument..."); Console.WriteLine(String.Format("TT API FindInstrument {0}", keys[0].ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, keys[0]); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); } else { MessageBox.Show("This application only accepts a single Contract"); } }
/// <summary> /// Perform the instrument lookups /// </summary> public void Init() { foreach (ContractDetails cd in m_lcd) { InstrumentKey key = new InstrumentKey(new ProductKey(cd.m_marketKey, cd.m_productType, cd.m_product), cd.m_contract); Console.WriteLine("Strategy1::Subscribing to Instrument: {0}", key); InstrumentLookupSubscription req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, key); /*InstrumentLookupSubscription req = new InstrumentLookupSubscription( * m_apiInstance.Session, Dispatcher.Current, * new ProductKey(cd.m_marketKey, cd.m_productType, cd.m_product), cd.m_contract);*/ req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(req_Update); m_lreq.Add(req); req.Start(); } }
public void SubscribeToInstrument(InstrumentKey key) { if (_dispatcher.InvokeRequired()) { _dispatcher.BeginInvoke(() => { SubscribeToInstrument(key); }); return; } InstrumentLookupSubscription req = new InstrumentLookupSubscription(_apiSession, Dispatcher.Current, key); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupRequest_Update); req.Start(); Console.WriteLine("SUBSCRIBETOINSTRUMENT REQUEST: " + key.ToString()); }
/// <summary> /// Event notification for status of authentication /// </summary> public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { // lookup an instrument m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cbot, ProductType.Future, "ZN"), "Sep13"); m_req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req.Start(); } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
public void startInstrumentLookupSubscriptions(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { foreach (string dbTicker in dbTickerList) { ttapiTicker currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker); if (currentTicker.marketKey == "CME") { mkey = MarketKey.Cme; } else if (currentTicker.marketKey == "ICE_IPE") { mkey = MarketKey.Ice; } if (currentTicker.productType == "FUTURE") { ptype = ProductType.Future; } else if (currentTicker.productType == "SPREAD") { ptype = ProductType.Spread; } InstrumentKey IKey = new InstrumentKey(new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); for (int i = 0; i < ilsUpdateList.Count; i++) { Ils.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(ilsUpdateList[i]); } IlsDictionary.Add(IKey, Ils); Ils.Start(); } } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
public void CreateInstrument(string marketName, string productTypeName, string productName, string contractName, string tag) { if (_dispatcher.InvokeRequired()) { _dispatcher.BeginInvoke(() => { CreateInstrument(marketName, productTypeName, productName, contractName, tag); }); return; } InstrumentDescriptor descriptor = new InstrumentDescriptor(marketName, productTypeName, productName, contractName); InstrumentLookupSubscription req = new InstrumentLookupSubscription(_apiSession, Dispatcher.Current, descriptor.ProductKey, descriptor.ContractName); req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupRequest_Update); req.Tag = tag; // Tag our request with our unique tag string req.Start(); Console.WriteLine("CREATEINSTRUMENT REQUEST: " + descriptor.ToString()); }
/// <summary> /// Event notification for status of authentication /// </summary> public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { // lookup an instrument m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Future, "ES"), "Mar13"); m_req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req.Start(); } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
/// <summary> /// Shuts down the TT API /// </summary> public void Dispose() { lock(m_lock) { if (!m_disposed) { // Unattached callbacks and dispose of all subscriptions if (m_req != null) { m_req.Update -= m_req_Update; m_req.Dispose(); m_req = null; } if (m_ps != null) { m_ps.FieldsUpdated -= m_ps_FieldsUpdated; m_ps.Dispose(); m_ps = null; } if (m_ts != null) { m_ts.OrderAdded -= m_ts_OrderAdded; m_ts.OrderDeleted -= m_ts_OrderDeleted; m_ts.OrderFilled -= m_ts_OrderFilled; m_ts.OrderRejected -= m_ts_OrderRejected; m_ts.OrderUpdated -= m_ts_OrderUpdated; m_ts.Dispose(); m_ts = null; } // Begin shutdown the TT API TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }
/// <summary> /// Find a given instrument based on the InstrumentKey. /// </summary> /// <param name="instrumentKey">InstrumentKey</param> private void findInstrument(InstrumentKey instrumentKey) { InstrumentLookupSubscription sub = new InstrumentLookupSubscription(m_session, m_dispatcher, instrumentKey); sub.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(instrumentLookupSubscription_Update); sub.Start(); }
private void StartSpreadDetailsProcess() { // We will create a spread with 2 legs Console.WriteLine("Find instruments for the legs..."); ProductKey prodKeyLeg = new ProductKey(MarketKey.Cbot, ProductType.Future, "ZN"); // We will use a dictionary to hold all instrument requests and update it when each instrument is found. // Once all lookup requests for the legs are complete, we can continue with the creation of the spread. // tagValue will be used in the dictionary to identify each lookup request. int tagValue = 1000; req1 = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Sep12"); req1.Tag = tagValue; spreadLegKeys.Add(tagValue, null); req1.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(legReq_Update); req1.Start(); tagValue++; req2 = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Dec12"); req2.Tag = tagValue; spreadLegKeys.Add(tagValue, null); req2.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(legReq_Update); req2.Start(); }
public void startInstrumentLookupSubscriptionsFromTTAPITickers(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { foreach (ttapiTicker ticker in TTAPITickerList) { if (ticker.marketKey == "CME") mkey = MarketKey.Cme; else if (ticker.marketKey == "ICE_IPE") mkey = MarketKey.Ice; if (ticker.productType == "FUTURE") ptype = ProductType.Future; else if (ticker.productType == "SPREAD") ptype = ProductType.Spread; InstrumentKey IKey = new InstrumentKey(new ProductKey(mkey, ptype, ticker.productName), ticker.SeriesKey); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, ticker.productName), ticker.instrumentName); for (int i = 0; i < ilsUpdateList.Count; i++) { Ils.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(ilsUpdateList[i]); } IlsDictionary.Add(IKey, Ils); Ils.Start(); } } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
/// <summary> /// Click event which will initiate the price subscription /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConnect_Click(object sender, EventArgs e) { UpdateStatusBar("Connecting to Instrument..."); // Create a product key from the given values ProductKey key = new ProductKey(this.txtExchange.Text, (ProductType)this.cboProductType.SelectedItem, this.txtProduct.Text); // Find out instrument based on the previously created key and the contract name InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(this.m_TTAPI.Session, Dispatcher.Current, key, this.txtContract.Text); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); }
public void StartInstrumentLookupSubscriptionsFromCatalog(object sender, InstrumentCatalogUpdatedEventArgs e) { foreach (TradingTechnologies.TTAPI.Instrument inst in e.Added) { Console.WriteLine("Instr: {0}", inst.Name); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, inst.Key); for (int i = 0; i < ilsUpdateList.Count; i++) { Ils.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(ilsUpdateList[i]); } Console.WriteLine(Ils.Instrument.Key.ToString()); IlsDictionary.Add(inst.Key, Ils); Ils.Start(); //InstrumentCatalogSubscription ics2 = (InstrumentCatalogSubscription)sender; //ics2.InstrumentsUpdated -= ics_InstrumentsUpdated; //ics2.Dispose(); //ics2 = null; } TradingTechnologies.TTAPI.Product Prod = ((InstrumentCatalogSubscription)sender).Product; PlsDictionary[Prod.Key].Update -= PLSEventHandler; PlsDictionary[Prod.Key].Dispose(); PlsDictionary[Prod.Key] = null; PlsDictionary.Remove(Prod.Key); if ((PlsDictionary.Count == 0) & PlsDictionaryCompleteQ) { IlsDictionaryCompleteQ = true; } }
/// <summary> /// Shuts down the TT API /// </summary> public void Dispose() { lock (m_lock) { if (!m_disposed) { // Unattached callbacks and dispose of all subscriptions if (m_ts != null) { m_ts.Update -= m_ts_Update; m_ts.Dispose(); m_ts = null; } if (m_req != null) { m_req.Update -= m_req_Update; m_req.Dispose(); m_req = null; } // Begin shutdown the TT API TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted); TTAPI.Shutdown(); m_disposed = true; } } }
protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // Shutdown all subscriptions if (req != null) { req.Dispose(); req = null; } if (ps != null) { ps.Dispose(); ps = null; } if (ts != null) { ts.Dispose(); ts = null; } // Shutdown the Dispatcher if (disp != null) { disp.BeginInvokeShutdown(); disp = null; } // Shutdown the TT API if (apiInstance != null) { apiInstance.Shutdown(); apiInstance = null; } } } disposed = true; }
/// <summary> /// Event notification for status of authentication /// </summary> public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { // lookup the leg instruments ProductKey prodKeyLeg = new ProductKey(MarketKey.Cbot, ProductType.Future, "ZN"); // We will use a dictionary to hold all instrument requests and update it when each instrument is found. // Once all lookup requests for the legs are complete, we can continue with the creation of the spread. // tagValue will be used in the dictionary to identify each lookup request. int tagValue = 1000; m_req1 = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Mar13"); m_req1.Tag = tagValue; m_spreadLegKeys.Add(tagValue, null); m_req1.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req1.Start(); tagValue++; m_req2 = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, prodKeyLeg, "Jun13"); m_req2.Tag = tagValue; m_spreadLegKeys.Add(tagValue, null); m_req2.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req2.Start(); } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
/// <summary> /// Perform the instrument lookups /// </summary> public void Init() { foreach (ContractDetails cd in m_lcd) { InstrumentLookupSubscription req = new InstrumentLookupSubscription( m_apiInstance.Session, Dispatcher.Current, new ProductKey(cd.m_marketKey, cd.m_productType, cd.m_product), cd.m_contract); req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(req_Update); m_lreq.Add(req); req.Start(); } }
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < FilteredList.Count; i++) { if (FilteredList[i].MarketKey == "CME") mkey = MarketKey.Cme; else if (FilteredList[i].MarketKey == "ICE_IPE") mkey = MarketKey.Ice; if (FilteredList[i].ProductType == "FUTURE") ptype = ProductType.Future; else if (FilteredList[i].ProductType == "SPREAD") ptype = ProductType.Spread; m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, FilteredList[i].ProductName), FilteredList[i].InstrumentName); m_req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req.Start(); } }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> public void FindInstrument(IList<InstrumentKey> keys) { foreach (InstrumentKey key in keys) { // Update the Status Bar text. UpdateStatusBar(String.Format("TT API FindInstrument {0}", key.ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += instrRequest_Completed; instrRequest.Tag = key.ToString(); instrRequest.Start(); // Only allow the first instrument. break; } }
/// <summary> /// Function to find a list of InstrumentKeys. /// </summary> /// <param name="keys">List of InstrumentKeys.</param> private void FindInstrument(IList<InstrumentKey> keys) { if ((keys.Count > 0) && (keys.Count <= MAX_INSTRUMENT_COUNT)) { SetComponentText(toolStripStatusLabel1, "Drag & Drop detected. Initializing instrument..."); // dispose of any current instrument models if (m_bindingModels != null) { foreach (var entry in m_bindingModels) { entry.Value.ThreadID = ""; entry.Value.Exchange = ""; entry.Value.Product = ""; entry.Value.ProdType = ""; entry.Value.Contract = ""; entry.Value.BidPrice = ""; entry.Value.AskPrice = ""; entry.Value.LastPrice = ""; entry.Value.Dispatcher.BeginInvokeShutdown(); } } // Release any current data bindings ReleaseDataBinding(); // (re) instantiate our binding instrument model m_bindingModels = new Dictionary<InstrumentKey, InstrumentModel>(MAX_INSTRUMENT_COUNT); // index assigned to each instrument which corresponds to the GUI output int index = 1; foreach (InstrumentKey key in keys) { Console.WriteLine(String.Format("TT API FindInstrument {0}", key.ToString())); // create the model for the instrument & set the component data bindings InstrumentModel model = new InstrumentModel(this); SetDataBinding(index++, model); // add the instrument model to our lookup table m_bindingModels.Add(key, model); // Instrument lookups are all still on the main application thread InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += instrRequest_Completed; instrRequest.Start(); } } else { MessageBox.Show("This application accepts a maximum of " + MAX_INSTRUMENT_COUNT + " contracts."); } }
public void startInstrumentLookupSubscriptionsFromDataTable(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { foreach (DataRow item in TickerTable.Rows) { ttapiTicker currentTicker; if (item.Field<bool>("IsSpreadQ")) { currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker: item.Field<string>("Ticker"), productType: "SPREAD"); } else { currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker: item.Field<string>("Ticker"), productType: "FUTURE"); } if (currentTicker.marketKey == "CME") mkey = MarketKey.Cme; else if (currentTicker.marketKey == "ICE_IPE") mkey = MarketKey.Ice; if (currentTicker.productType == "FUTURE") ptype = ProductType.Future; else if (currentTicker.productType == "SPREAD") ptype = ProductType.Spread; InstrumentKey IKey = new InstrumentKey(new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); Console.WriteLine(currentTicker.SeriesKey); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); //Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Spread, "CL"), "Nov16:-1xDec16"); for (int i = 0; i < ilsUpdateList.Count; i++) { Ils.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(ilsUpdateList[i]); } IlsDictionary.Add(IKey, Ils); Ils.Start(); } } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
private void Form1_DragDrop(object sender, DragEventArgs e) { // If the Drop-data contains at least one contract, ... if (e.Data.HasInstrumentKeys()) { label2.Text = ""; foreach (InstrumentKey ik in e.Data.GetInstrumentKeys()) { // Begin an instrument subscription req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, ik); req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(req_Update); req.Start(); } } }
public void StartASEEventChain() { int TagValue = 1; foreach (string dbTicker in DbTickerList) { ttapiTicker currentTicker = TA.TickerConverters.ConvertFromDbTicker2ttapiTicker(dbTicker); if (currentTicker.marketKey == "CME") mkey = MarketKey.Cme; else if (currentTicker.marketKey == "ICE_IPE") mkey = MarketKey.Ice; if (currentTicker.productType == "FUTURE") ptype = ProductType.Future; else if (currentTicker.productType == "SPREAD") ptype = ProductType.Spread; InstrumentKey IKey = new InstrumentKey(new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); Ils = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(mkey, ptype, currentTicker.productName), currentTicker.SeriesKey); Ils.Tag = TagValue; SpreadLegKeys.Add(TagValue, null); TagValue++; Ils.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(CreateAutoSpreader); IlsDictionary.Add(IKey, Ils); Ils.Start(); } }
private void frmSOD_ManualFill_DragDrop(object sender, DragEventArgs e) { foreach (InstrumentKey key in e.Data.GetInstrumentKeys()) { // Update the Status Bar text. UpdateStatusBar(String.Format("TT API FindInstrument {0}", key.ToString())); InstrumentLookupSubscription instrRequest = new InstrumentLookupSubscription(m_TTAPI.Session, Dispatcher.Current, key); instrRequest.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(instrRequest_Update); instrRequest.Start(); // Only allow the first instrument. break; } }
/// <summary> /// Launch an autospreader instrument to a selected order server. /// First find the instrument then launch it to the selected order feed. /// </summary> private void buttonLaunch_Click(object sender, EventArgs e) { DataGridViewSelectedCellCollection selectedCells = dataGridViewSpreadView.SelectedCells; if (selectedCells.Count > 0) { SpreadDetails currentSpreadDetails = ((MutableSpreadDetails)selectedCells[0].OwningRow.DataBoundItem).SpreadDetails; InstrumentLookupSubscription instrumentLookupSubscription = new InstrumentLookupSubscription(m_session, m_dispatcher, currentSpreadDetails.InstrumentKey); instrumentLookupSubscription.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(instrumentLookupSubscription_Update); instrumentLookupSubscription.Start(); } }
/// <summary> /// Event notification for status of authentication /// </summary> public void apiInstance_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e) { if (e.Status.IsSuccess) { // lookup an instrument m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Spread, "CL"), "Calendar: 1xCL Nov16:-1xDec16"); m_req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req.Start(); m_fs = new FillsSubscription(m_apiInstance.Session, Dispatcher.Current); m_fs.FillAdded += new EventHandler<FillAddedEventArgs>(m_fs_FillAdded); m_fs.Start(); } else { Console.WriteLine("TT Login failed: {0}", e.Status.StatusMessage); Dispose(); } }
void ics_InstrumentsUpdated(object sender, InstrumentCatalogUpdatedEventArgs e) { foreach (TradingTechnologies.TTAPI.Instrument inst in e.Added) { Console.WriteLine("Instr: {0}", inst.Name); //Console.WriteLine(e.GetType()); //sw.WriteLine(inst.Name); //sw.Flush(); InstrumentList.Add(inst.Name); m_req = new InstrumentLookupSubscription(m_apiInstance.Session, Dispatcher.Current,inst.Key); m_req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(m_req_Update); m_req.Start(); //Console.WriteLine(e. ); } }