}// 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); } }//
}// 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()
// // #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, Misty.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 * Misty.Lib.BookHubs.Book aBook; * if (m_Market.TryEnterReadBook(out aBook)) * { * foreach (Misty.Lib.BookHubs.MarketInstrument mktInstr in aBook.Instruments.Values) * { * if (mktInstr.Name.Equals(m_CurrentInstrument.FullName)) * { * labelAskPrice.Text = mktInstr.Price[Misty.Lib.Utilities.QTMath.AskSide][0].ToString(); * labelBidPrice.Text = mktInstr.Price[Misty.Lib.Utilities.QTMath.BidSide][0].ToString(); * labelAskQty.Text = mktInstr.Qty[Misty.Lib.Utilities.QTMath.AskSide][0].ToString(); * labelBidQty.Text = mktInstr.Qty[Misty.Lib.Utilities.QTMath.BidSide][0].ToString(); * break; * } * } * m_Market.ExitReadBook(aBook); * } * // Reset defaults * SetConfirmMode(buttonSubmitFill,false,0); * }//SetInstrument() * // */ // // public void SetInstrument(FillHub fillHub, Misty.Lib.Products.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; /* * Misty.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 Misty.Lib.BookHubs.Book aBook; if (m_Market.TryEnterReadBook(out aBook)) { foreach (Misty.Lib.BookHubs.Market mktInstr in aBook.Instruments.Values) { if (mktInstr.Name.Equals(m_CurrentInstrument)) { labelAskPrice.Text = mktInstr.Price[Misty.Lib.Utilities.QTMath.AskSide][0].ToString(); labelBidPrice.Text = mktInstr.Price[Misty.Lib.Utilities.QTMath.BidSide][0].ToString(); labelAskQty.Text = mktInstr.Qty[Misty.Lib.Utilities.QTMath.AskSide][0].ToString(); labelBidQty.Text = mktInstr.Qty[Misty.Lib.Utilities.QTMath.BidSide][0].ToString(); break; } } m_Market.ExitReadBook(aBook); } // Reset defaults SetConfirmMode(buttonSubmitFill, false, 0); }//SetInstrument()
}// 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()
} // ReadStatements() // // // // ***************************************************************** // **** Create InstrumentName() **** // ***************************************************************** /// <summary> /// /// </summary> /// <param name="typeCodeStr"></param> /// <param name="instrDescStr"></param> /// <param name="instrSymbolStr"></param> /// <param name="rcgProduct"></param> /// <param name="rcgInstrumentName"></param> /// <returns></returns> private bool TryCreateInstrumentName(string typeCodeStr, string instrDescStr, string instrSymbolStr, out Misty.Lib.Products.Product rcgProduct, out Misty.Lib.Products.InstrumentName rcgInstrumentName) { int n; if (typeCodeStr.Contains("O") || typeCodeStr.Contains("C") || typeCodeStr.Contains("P")) { ProductTypes mistyProductType = ProductTypes.Option; string exchStr = "Option"; string instrStr = instrDescStr; string seriesName = instrDescStr; rcgProduct = new Product(exchStr, instrStr, mistyProductType); rcgInstrumentName = new InstrumentName(rcgProduct, seriesName); } else if (string.IsNullOrEmpty(typeCodeStr) || typeCodeStr.Contains("F")) { // futures format = "DEC 13 TOCOM GOLD" ProductTypes mistyProductType = ProductTypes.Future; string[] elements; try { elements = instrDescStr.Split(DelimSpace, StringSplitOptions.RemoveEmptyEntries); int nextPtr = 0; // // Instrument date extraction // string seriesName; if (Int32.TryParse(elements[0], out n)) { // Seems to be "dd MMM yy" format, since first element is integer n = "dd" string s = elements[1].Trim(); // extract month part string monthName = string.Format("{0}{1}", s.Substring(0, 1).ToUpper(), s.Substring(1, 2).ToLower()); // MAY --> May seriesName = string.Format("{0:00}{1}{2}", n, monthName, elements[2].Trim()); // 08May13 for example seriesName = "CA 3M"; nextPtr = 3; // ptr to next element. } else { // Seems to be "MMM yy" format string s = elements[0].Trim(); // extract month part string monthName = string.Format("{0}{1}", s.Substring(0, 1).ToUpper(), s.Substring(1, 2).ToLower()); // MAY --> May seriesName = string.Format("{0}{1}", monthName, elements[1].Trim()); nextPtr = 2; // ptr to next element. } string exchStr; string instrStr; int remainingElements = elements.Length - nextPtr; if (remainingElements == 1) { // No obvious delineation between product and exch? // Assume a 3-character exchange code! I believe RCG uses fixed length fields... string s = elements[nextPtr].Trim(); exchStr = s.Substring(0, 3); // First 3 chars instrStr = s.Substring(3); // remaining symbol nextPtr++; } else { exchStr = elements[nextPtr].Trim(); // presume exch name is ONE-word long nextPtr++; instrStr = elements[nextPtr].Trim(); nextPtr++; while (nextPtr < elements.Length) { instrStr = string.Format("{0} {1}", instrStr, elements[nextPtr].Trim()); nextPtr++; } } rcgProduct = new Product(exchStr, instrStr, mistyProductType); rcgInstrumentName = new InstrumentName(rcgProduct, seriesName); } catch (Exception) { // TODO: Write error message to log, and continue. rcgProduct = new Product(); rcgInstrumentName = new InstrumentName(); return(false); } } else { rcgProduct = new Product(); rcgInstrumentName = new InstrumentName(); } // Exit return(true); }// CreateInstrumentName()
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()