}// ReadTable() // // // // // // #endregion//Private Methods #region Static Functions // ***************************************************************** // **** Static Functions **** // ***************************************************************** // // public static bool TryExtractExpiryFromSeriesName(InstrumentName name1, out DateTime expiryDate) { expiryDate = DateTime.MinValue; System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US"); if (DateTime.TryParseExact(name1.SeriesName, "MMMyy", ci, System.Globalization.DateTimeStyles.None, out expiryDate)) { return(true); } else if (DateTime.TryParseExact(name1.SeriesName, "yyyy/MM", ci, System.Globalization.DateTimeStyles.None, out expiryDate)) { return(true); } else if (DateTime.TryParseExact(name1.SeriesName, "MM/yyyy", ci, System.Globalization.DateTimeStyles.None, out expiryDate)) { return(true); } else if (DateTime.TryParseExact(name1.SeriesName, "ddMMMyy", ci, System.Globalization.DateTimeStyles.None, out expiryDate)) { return(true); } else { return(false); } }//
// // // // #endregion//Public Methods #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // /// <summary> /// Called for futures only where we expect the series name to have some sort of date in it. /// This is mainly a way of filtering out instrument like "e-Brent Cal 14" and "e-Brent Q1" /// which are getting denoted as futures but have multiple instruments within. /// </summary> /// <param name="instr"></param> /// <returns></returns> private bool IsStandardInstrument(InstrumentName instr) { DateTime dateTime; if (DateTime.TryParse(instr.SeriesName, out dateTime)) { return(true); } return(false); }
}// SaveTable // // // // // // // #endregion//Public Methods #region no Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // // // // **** Read Product Table() **** // // Product table format: breProductName, RcgProductName private void ReadTable() { using (System.IO.StreamReader reader = new System.IO.StreamReader(this.FilePath)) { string aLine; bool continueReading = true; while (continueReading) { aLine = reader.ReadLine(); if (aLine == null) { break; } aLine = aLine.Trim(); if (string.IsNullOrWhiteSpace(aLine)) { continue; // skip blank lines } if (aLine.StartsWith("// END", StringComparison.CurrentCultureIgnoreCase)) // this signals end of file at the moment. { continueReading = false; continue; } else if (aLine.Contains("//")) { int n = aLine.IndexOf("//"); if (n == 0) { continue; } else if (n > 0) { aLine = aLine.Substring(0, n); } } // // Extract table entries // string[] elements = aLine.Split(','); if (elements.Length >= 2) { // Need two elements InstrumentName instr1; InstrumentName instr2; if (InstrumentName.TryDeserialize(elements[0].Trim(), out instr1) && InstrumentName.TryDeserialize(elements[1].Trim(), out instr2)) { m_KeyList.Add(instr1); m_ValueList.Add(instr2); } } }//wend reader.Close(); m_SavedInstrumentCount = m_KeyList.Count; // update the instrument Count. } }// ReadTable()
// ***************************************************************** // **** Constructors **** // ***************************************************************** // /// <summary> /// Create Instrument Details for a given instrument. /// </summary> /// <param name="instr"></param> /// <param name="currency"></param> /// <param name="tickSize">Smallest price change possible of intsrument</param> /// <param name="multiplier">The multiplier * current price = notional value of contract. (Multiplier = TickValue / TickSize)</param> /// <param name="executableTickSize"> Smallest possible increment to be filled in</param> /// <param name="expires"></param> /// <param name="type"></param> public InstrumentDetails(InstrumentName instr, string currency, double tickSize, double executableTickSize, double multiplier, DateTime expires, ProductTypes type) { this.InstrumentName = instr; this.Currency = currency; this.TickSize = tickSize; // smallest increment price can fluctuate by this.ExecutableTickSize = executableTickSize; this.Multiplier = multiplier; // See above for explanation of multipilier this.ExpirationDate = expires; this.Type = type; this.TickValue = multiplier * tickSize; // Native Currency Value of a Tick if (type == ProductTypes.Future | type == ProductTypes.Spread) { this.isStandard = IsStandardInstrument(instr); } }
// // #endregion//Constructors #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** /// <summary> /// When an instrument is clicked on in the position viewer window, that window /// calls this routine letting us know which instrument is active. /// </summary> /* * public void SetInstrument(FillHub fillHub, UV.Lib.Products.InstrumentBase instrument) * { * m_CurrentInstrument = instrument; // set current instrument * m_FillHub = fillHub; // set current fill hub * this.Text = string.Format("Add Fills - {0}", m_CurrentInstrument.FullName); * this.labelInstrumentName.Text = m_CurrentInstrument.FullName; * this.labelExpirationDate.Text = string.Format("{0:ddd dd MMM yyyy}", m_CurrentInstrument.ExpirationDate); * * // Update Markets * UV.Lib.BookHubs.Book aBook; * if (m_Market.TryEnterReadBook(out aBook)) * { * foreach (UV.Lib.BookHubs.MarketInstrument mktInstr in aBook.Instruments.Values) * { * if (mktInstr.Name.Equals(m_CurrentInstrument.FullName)) * { * labelAskPrice.Text = mktInstr.Price[UV.Lib.Utilities.QTMath.AskSide][0].ToString(); * labelBidPrice.Text = mktInstr.Price[UV.Lib.Utilities.QTMath.BidSide][0].ToString(); * labelAskQty.Text = mktInstr.Qty[UV.Lib.Utilities.QTMath.AskSide][0].ToString(); * labelBidQty.Text = mktInstr.Qty[UV.Lib.Utilities.QTMath.BidSide][0].ToString(); * break; * } * } * m_Market.ExitReadBook(aBook); * } * // Reset defaults * SetConfirmMode(buttonSubmitFill,false,0); * }//SetInstrument() * // */ // // public void SetInstrument(FillHub fillHub, InstrumentName instrument) { m_CurrentInstrument = instrument; // set current instrument m_FillHub = fillHub; // set current fill hub this.Text = string.Format("Add Fills - {0}", m_CurrentInstrument.FullName); this.labelInstrumentName.Text = m_CurrentInstrument.FullName; /* * UV.Lib.Products.InstrumentBase instrBase; * if (m_Market.TryGetInstrument(instrument, out instrBase)) * { * this.labelExpirationDate.Text = string.Format("{0:ddd dd MMM yyyy}", instrBase.ExpirationDate); * } * else * this.labelExpirationDate.Text = "unknown market instr"; */ TradingTechnologies.TTAPI.InstrumentDetails details; if (m_Market.TryLookupInstrumentDetails(instrument, out details)) { this.labelExpirationDate.Text = string.Format("{0:ddd dd MMM yyyy}", details.ExpirationDate.ToDateTime()); } else { this.labelExpirationDate.Text = "unknown market instr"; } // Update Markets Book aBook; if (m_Market.TryEnterReadBook(out aBook)) { foreach (Market mktInstr in aBook.Instruments.Values) { if (mktInstr.Name.Equals(m_CurrentInstrument)) { labelAskPrice.Text = mktInstr.Price[QTMath.AskSide][0].ToString(); labelBidPrice.Text = mktInstr.Price[QTMath.BidSide][0].ToString(); labelAskQty.Text = mktInstr.Qty[QTMath.AskSide][0].ToString(); labelBidQty.Text = mktInstr.Qty[QTMath.BidSide][0].ToString(); break; } } m_Market.ExitReadBook(aBook); } // Reset defaults SetConfirmMode(buttonSubmitFill, false, 0); }//SetInstrument()
// // // ***************************************************************** // **** CreateUVInstrumentDetails() **** // ***************************************************************** /// <summary> /// Create UV Instrument Details from TT Instrument Details /// </summary> /// <param name="instrName"></param> /// <param name="instrDetails"></param> public static UVInstrDetails CreateUVInstrumentDetails(UV.Lib.Products.InstrumentName instrName, TTInstrumentDetails instrDetails) { UVProductTypes instrType; // finds the correct product type if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Future)) { instrType = UVProductTypes.Future; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Spread)) { instrType = UVProductTypes.Spread; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Option)) { instrType = UVProductTypes.Option; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.AutospreaderSpread)) { instrType = UVProductTypes.AutoSpreaderSpread; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Bond)) { instrType = UVProductTypes.Bond; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Stock)) { instrType = UVProductTypes.Equity; } else if (instrDetails.Key.ProductKey.Type.Equals(ProductType.Strategy)) { instrType = UVProductTypes.Synthetic; } else { instrType = UVProductTypes.Unknown; } UV.Lib.Products.InstrumentDetails uvInstrDetails; uvInstrDetails = new UVInstrDetails(instrName, // create the UV Instr details instrDetails.Currency.Code, TTConvertNew.ToUVTickSize(instrDetails), TTConvertNew.ToUVExecTickSize(instrDetails), TTConvertNew.ToUVMultiplier(instrDetails), instrDetails.ExpirationDate.ToDateTime(), instrType); return(uvInstrDetails); }
}// TryGetNewEntries() // // // // **** Save Table() **** // // Product table format: breProductName, RcgProductName public void SaveTable(string newFilePath = "") { string filePath; if (string.IsNullOrEmpty(newFilePath)) { filePath = this.FilePath; } else { filePath = newFilePath; } // Lets alphabetize this table List <InstrumentName> sortingList = new List <InstrumentName>(m_KeyList); sortingList.Sort(new InstrumentNameComparer()); int searchFromIndex = 0; InstrumentName lastInstrName = new InstrumentName(); using (System.IO.StreamWriter stream = new System.IO.StreamWriter(filePath, false)) { foreach (InstrumentName instrName in sortingList) { if (!instrName.Equals(lastInstrName)) { searchFromIndex = 0; // instrName is different from last one, so start search from beginning index. } lastInstrName = instrName; // Remember this instrName. // Search for entry. int n1 = m_KeyList.IndexOf(instrName, searchFromIndex); // location of this instrName entry. searchFromIndex = n1 + 1; // Write the entries now. InstrumentName instr1 = m_KeyList[n1]; InstrumentName instr2 = m_ValueList[n1]; stream.WriteLine("{0,32},{1,32}", InstrumentName.Serialize(instr1).Trim(), InstrumentName.Serialize(instr2).Trim()); }// next instrName stream.Write("// END"); stream.Close(); m_SavedInstrumentCount = sortingList.Count; // update instrument count } }// SaveTable
/// <summary> /// /// </summary> /// <param name="memberOfList1"></param> /// <param name="matchingMembersOfList2"></param> /// <param name="list1"></param> /// <param name="list2"></param> /// <param name="useExactMatch">false -> matching product part only</param> /// <returns></returns> private bool TryFindMappings(InstrumentName memberOfList1, ref List <InstrumentName> matchingMembersOfList2, ref List <InstrumentName> list1, ref List <InstrumentName> list2 , bool useExactMatch = true) { int nCount = matchingMembersOfList2.Count; for (int i = 0; i < list1.Count; ++i) { if (memberOfList1.Equals(list1[i])) // we have located a matching in list1 at this index i. { InstrumentName mappedInstrument = list2[i]; // this is the output of that entry of list1. matchingMembersOfList2.Add(mappedInstrument); // add it to the outgoing list. } else if (!useExactMatch) // alternatively, the user may only want partial matches. { // Look for near matches. // These have two restrictions, mapping is a product entry (not specific instr). if (list1[i].IsProduct && memberOfList1.Product.Equals(list1[i].Product)) // and the products must match exactly. { // The entry in list1 seems to be a product that matches users instr. InstrumentName mappedInstrument = list2[i]; // So, grab the output of the map, and store it. matchingMembersOfList2.Add(mappedInstrument); } } } // Exit return(matchingMembersOfList2.Count > nCount); }// TryFindMatch()
public bool TryGetKey(InstrumentName aValue, ref List <InstrumentName> matchingKeys, bool useExactMatch = true) { return(this.TryFindMappings(aValue, ref matchingKeys, ref m_ValueList, ref m_KeyList, useExactMatch)); }
// #endregion//Properties #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // public bool TryGetValue(InstrumentName key, ref List <InstrumentName> matchingValues, bool useExactMatch = true) { return(this.TryFindMappings(key, ref matchingValues, ref m_KeyList, ref m_ValueList, useExactMatch)); }
}// TryFindMatch() // // // **** Add() **** // public void Add(InstrumentName key, InstrumentName value) { m_KeyList.Add(key); m_ValueList.Add(value); }// Add()