// #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // /// <summary> /// Caller would like to setup all queries to the database and submit /// them asyncronously to the database hub. /// </summary> private void CreateAndSubmitInstrumentQueries() { for (int i = 0; i < m_Instruments.Count; i++) { InstrumentInfoQuery instrumentInfoQuery = new InstrumentInfoQuery(); instrumentInfoQuery.InstrumentName = m_Instruments[i]; instrumentInfoQuery.IsRead = true; // we are reading fromt he db, not writing m_DatabaseReaderWriter.SubmitAsync(instrumentInfoQuery); } }
// ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // private void buttonStart_Click(object sender, EventArgs e) { m_HedgeOptionsWriter = new HedgeOptionsWriter(m_Log); m_InstrumentExistInDatabase = new List <InstrumentName>(); m_InstrumentPendingWriting = new List <InstrumentName>(); m_BREInstrumentInfoItems = new Dictionary <InstrumentName, InstrumentInfoItem>(); // Generate query to get all instruments from the data base. InstrumentInfoQuery BREInstrumentInfoQuery = new InstrumentInfoQuery(); ProductTypes productTypes; if (Enum.TryParse <ProductTypes>(textBoxProductType.Text, out productTypes)) { m_Product = new Product(textBoxExchangeName.Text, textBoxProductName.Text, productTypes); BREInstrumentInfoQuery.InstrumentName = new InstrumentName(m_Product, string.Empty); BREInstrumentInfoQuery.IsRead = true; BREInstrumentInfoQuery.Status = QueryStatus.New; } else { m_Log.NewEntry(LogLevel.Error, "Product type parse failed"); return; } // Submit query and store existing instruments from the data base. m_DatabaseReaderWriter.SubmitSync(BREInstrumentInfoQuery); List <InstrumentInfoItem> BREInstrumentInfoItems = BREInstrumentInfoQuery.Results; foreach (InstrumentInfoItem BREInstrumentInfoItem in BREInstrumentInfoItems) { if (m_BREInstrumentInfoItem == null) { m_BREInstrumentInfoItem = BREInstrumentInfoItem; // Need one of this only. } string instrumentNameString = BREInstrumentInfoItem.InstrumentNameTT; InstrumentName instrumentName; if (instrumentNameString != null && InstrumentName.TryDeserialize(instrumentNameString, out instrumentName)) { m_InstrumentExistInDatabase.Add(instrumentName); m_BREInstrumentInfoItems.Add(instrumentName, BREInstrumentInfoItem); } } // Launch market instruments request. m_Market.RequestProducts(new List <Product>() { m_Product }); m_Market.RequestInstruments(m_Product); }
// ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // /// <summary> /// This function will read the hedge options information from the resulting query. /// One instrument hedge options can only be read once, otherwise error jumps out. /// </summary> /// <param name="queryResult"></param> /// <returns></returns> public bool TryReadHedgeOptionsInformation(InstrumentInfoQuery queryResult) { bool isSuccess = false; InstrumentName quoteInstrument = queryResult.InstrumentName; List <InstrumentInfoItem> instrumentInfoItems = queryResult.Results; // Normally only one element in the list above is relevant and the dimension for the result is 1 normally. foreach (InstrumentInfoItem instrumentInfoItem in instrumentInfoItems) { if (m_HedgeOptionsByInstrumentName.ContainsKey(quoteInstrument)) { m_Log.NewEntry(LogLevel.Error, "Hedge options already setup for instrument {0}.", quoteInstrument); continue; } else { string instrumentNameTT = instrumentInfoItem.InstrumentNameTT; string instrumentNameDatabase = instrumentInfoItem.InstrumentNameDatabase; HedgeOptions hedgeOptions; if (HedgeOptions.TryCreateHedgeOptions(quoteInstrument, instrumentNameTT, instrumentNameDatabase, m_Log, out hedgeOptions)) { if (!TryGenerateHedgeOptions(quoteInstrument, instrumentInfoItem, hedgeOptions)) { m_Log.NewEntry(LogLevel.Error, "Failed to generate hedge options for instrument {0}.", quoteInstrument); } else { m_HedgeOptionsByInstrumentName.Add(quoteInstrument, hedgeOptions); isSuccess = true; } } else { m_Log.NewEntry(LogLevel.Error, "Failed to create hedge options for instrument {0}.", quoteInstrument); } } } return(isSuccess); }
// // private void buttonWrite_Click(object sender, EventArgs e) { List <InstrumentInfoQuery> BREInstrumentInfoQuerys = new List <InstrumentInfoQuery>(); foreach (InstrumentName instrumentName in m_InstrumentPendingWriting) { if (m_BREInstrumentInfoItems.ContainsKey(instrumentName)) { InstrumentInfoItem BREInstrumentInfoItem = m_BREInstrumentInfoItems[instrumentName]; InstrumentInfoQuery BREInstrumentInfoQuery = new InstrumentInfoQuery(); BREInstrumentInfoQuery.InstrumentName = instrumentName; BREInstrumentInfoQuery.IsRead = false; BREInstrumentInfoQuery.Status = QueryStatus.New; BREInstrumentInfoQuery.Results.Add(BREInstrumentInfoItem); if (!m_InstrumentExistInDatabase.Contains(instrumentName)) { BREInstrumentInfoQuerys.Add(BREInstrumentInfoQuery); } } else { m_Log.NewEntry(LogLevel.Error, "No instrument found for instrument {0}.", instrumentName); return; } } foreach (InstrumentInfoQuery BREInstrumentInfoQuery in BREInstrumentInfoQuerys) { m_DatabaseReaderWriter.SubmitAsync(BREInstrumentInfoQuery); } m_UIDispatcher.Invoke( new Action(() => { this.buttonWrite.Enabled = false; }) ); }
// ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region no Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // #endregion//Private Methods #region Event Handlers // ***************************************************************** // **** Event Handlers **** // ***************************************************************** // // private void buttonSetupInstrumentMatrix_Click(object sender, EventArgs e) { // Process clicks of buttons. m_HedgeOptionsReader = new HedgeOptionsReader(m_Log); m_InstrumentNames = new List <InstrumentName>(); m_InstrumentNameStrings = new List <string>(); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xDec14"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xMar15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xJun15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xSep15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xDec15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xMar16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xJun16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun16:-1xSep16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep16:-1xDec16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xMar15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xJun15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xSep15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xDec15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xMar16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xJun16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xSep16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun16:-1xDec16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep14:-1xJun15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec14:-1xSep15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar15:-1xDec15"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Jun15:-1xMar16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Sep15:-1xJun16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Dec15:-1xSep16"); m_InstrumentNameStrings.Add("CME.GE (Spread) Calendar: 1xGE Mar16:-1xDec16"); foreach (string instrumentString in m_InstrumentNameStrings) { InstrumentInfoQuery BREInstrumentInfoQuery = new InstrumentInfoQuery(); InstrumentName instrumentName; if (InstrumentName.TryDeserialize(instrumentString, out instrumentName)) { m_InstrumentNames.Add(instrumentName); BREInstrumentInfoQuery.InstrumentName = instrumentName; BREInstrumentInfoQuery.IsRead = true; BREInstrumentInfoQuery.Status = QueryStatus.New; m_DatabaseReaderWriter.SubmitSync(BREInstrumentInfoQuery); m_HedgeOptionsReader.TryReadHedgeOptionsInformation(BREInstrumentInfoQuery); } else { return; } } Dictionary <InstrumentName, HedgeOptions> hedgeOptionsByInstrument = m_HedgeOptionsReader.GetHedgeOptionsByInstrumentName(); m_InstrumentMatrix = new InstrumentMatrix(m_InstrumentNames, m_Log); if (m_InstrumentMatrix.TrySetupInstrumentMatrix(hedgeOptionsByInstrument)) { m_Log.NewEntry(LogLevel.Minor, "Successfully setup the instrument matrix."); ProcessShowData(); } }