/// <summary> /// Fired when CQGTimedBar item is added to the end of CQGTimedBars. /// </summary> /// <param name="cqg_timed_bars"> /// Reference to changed CQGTimedBars. /// </param> private void CEL_TimedBarsAdded(CQG.CQGTimedBars cqg_timed_bars) { try { lock (m_BarToken1) { try { // try get the set KaiTrade.Interfaces.ITSSet mySet; if (m_TSSets.ContainsKey(cqg_timed_bars.Id)) { mySet = m_TSSets[cqg_timed_bars.Id]; //mySet.Items.Clear(); Done in the dump all if (cqg_timed_bars.Status == eRequestStatus.rsSuccess) { DumpAllData(cqg_timed_bars, mySet); } else { mySet.Text = cqg_timed_bars.LastError.Description; } } } catch (Exception myE) { log.Error("CEL_TimedBarsAdded", myE); } } } catch { } }
/// <summary> /// This event is fired, when some changes occur in the connection with CQG data server. /// </summary> /// <param name="newStatus"> /// The current status of the connection with the data server. /// </param> private void CEL_DataConnectionStatusChanged(CQG.eConnectionStatus new_status) { System.Drawing.Color BackCol; try { if (new_status == eConnectionStatus.csConnectionUp) { BackCol = System.Drawing.Color.FromArgb(0, 209, 15); m_NotStarted = 1; //sInfo = "DATA Connection is UP"; } else if (new_status == eConnectionStatus.csConnectionDelayed) { BackCol = System.Drawing.Color.FromArgb(255, 114, 0); //sInfo = "DATA Connection is Delayed"; } else { BackCol = System.Drawing.Color.FromArgb(255, 114, 0); //sInfo = "DATA Connection is Down"; } } catch (Exception ex) { modErrorHandler.ShowError("CQGConnection.cs", "CEL_DataConnectionStatusChanged", ex); } }
/// <summary> /// Fired when the collection of timed bars (CQGTimedBars) is resolved or /// when some error occured during timed bars request processing. /// </summary> /// <param name="cqg_timed_bars"> /// Reference to resolved CQGTimedBars /// </param> /// <param name="cqg_error"> /// The CQGError object that describes the last error occurred /// while processing the TimedBars request or /// Nothing/Invalid_Error in case of no error. /// </param> private void CEL_TimedBarsResolved(CQG.CQGTimedBars cqg_timed_bars, CQG.CQGError cqg_error) { try { lock (m_BarToken1) { try { driverLog.Info("CEL_TimedBarsResolved:" + cqg_timed_bars.Id.ToString()); // try get the set KaiTrade.Interfaces.ITSSet mySet; if (m_TSSets.ContainsKey(cqg_timed_bars.Id)) { mySet = m_TSSets[cqg_timed_bars.Id]; if (wireLog.IsInfoEnabled) { wireLog.Info("CEL_TimedBarsResolved:TSSetFound:" + mySet.Name + ":" + mySet.Alias + ":" + mySet.Mnemonic); } if (cqg_timed_bars.Status == eRequestStatus.rsSuccess) { mySet.Status = KaiTrade.Interfaces.Status.open; DumpAllData(cqg_timed_bars, mySet); } else { mySet.Status = KaiTrade.Interfaces.Status.error; mySet.Text = cqg_error.Description; this.SendStatusMessage(KaiTrade.Interfaces.Status.open, "CEL_TimedBarsResolved" + mySet.Text); } } else { driverLog.Info("CEL_TimedBarsResolved:Dataset not found"); } } catch (Exception myE) { log.Error("CEL_TimedBarsResolved", myE); } } } catch { } }
/// <summary> /// Dumps all request data (outputs\parameters\records) /// </summary> private void DumpAllData(CQG.CQGConstantVolumeBars myBars, KaiTrade.Interfaces.ITSSet mySet) { try { // Clears all records mySet.Items.Clear(); if (myBars.Count == 0) { return; } for (int i = 0; i < myBars.Count; i++) { // get a new TS item KaiTrade.Interfaces.ITSItem myItem = mySet.GetNewItem(); DumpRecord(myItem, mySet, myBars[i], i); myItem.SourceActionType = KaiTrade.Interfaces.TSItemSourceActionType.barAdded; myItem.ItemType = KaiTrade.Interfaces.TSItemType.constantVolume; mySet.AddItem(myItem); if (wireLog.IsInfoEnabled) { wireLog.Info("TBADD:" + myItem.ToTabSeparated()); } } // mark the set as changed - will cause the publisher // to do an update or image mySet.Added = true; } catch (Exception myE) { log.Error("DumpAllData", myE); } }
/// <summary> /// Fired when CQGTimedBar item is updated. /// </summary> /// <param name="cqg_timed_bars"> /// Reference to changed CQGTimedBars /// </param> /// <param name="index_"> /// Specifies the updated CQGTimedBar index. /// </param> private void CEL_TimedBarsUpdated(CQG.CQGTimedBars cqg_timed_bars, int index_) { try { lock (m_BarToken1) { try { // try get the set KaiTrade.Interfaces.ITSSet mySet; //return; if (m_TSSets.ContainsKey(cqg_timed_bars.Id)) { mySet = m_TSSets[cqg_timed_bars.Id]; if (!mySet.ReportAll) { // they only want added bars - so exit return; } KaiTrade.Interfaces.ITSItem[] bars = new KaiTrade.Interfaces.ITSItem[1]; bars[0] = mySet.GetNewItem(); CopyBar(bars[0], mySet, cqg_timed_bars[index_], index_); bars[0].SourceActionType = KaiTrade.Interfaces.TSItemSourceActionType.barUpdated; bars[0].DriverChangedData = true; mySet.ReplaceItem(bars[0], index_); BarUpdateClients(mySet.RequestID, bars); //mySet.Changed = true; } } catch (Exception myE) { log.Error("CEL_TimedBarsUpdated", myE); } } } catch { } }
/// <summary> /// Dumps all request data (outputs\parameters\records) /// </summary> private void DumpAllData(CQG.CQGTimedBars myBars, KaiTrade.Interfaces.ITSSet mySet) { try { int exitingItemCount = mySet.Items.Count; // Clears all records mySet.Items.Clear(); if (myBars.Count == 0) { return; } KaiTrade.Interfaces.ITSItem[] bars = new KaiTrade.Interfaces.ITSItem[myBars.Count]; for (int i = 0; i < myBars.Count; i++) { // get a new TS item bars[i] = mySet.GetNewItem(); CopyBar(bars[i], mySet, myBars[i], i); bars[i].SourceActionType = KaiTrade.Interfaces.TSItemSourceActionType.barAdded; bars[i].ItemType = KaiTrade.Interfaces.TSItemType.time; if (i >= exitingItemCount) { bars[i].DriverChangedData = true; } else if (i >= myBars.Count - 2) { bars[i].DriverChangedData = true; } else { bars[i].DriverChangedData = false; } //this.BarUpdateClients(my mySet.AddItem(bars[i]); if (wireLog.IsInfoEnabled) { wireLog.Info("TBADD:" + bars[i].ToTabSeparated()); } } // Will enable all bar clients of the driver to handle the bars this.BarUpdateClients(mySet.RequestID, bars); } catch (Exception myE) { log.Error("DumpAllData", myE); } }
/// <summary> /// Fired when CQGConstantVolumeBar item is added to the end of CQGConstantVolumeBars. /// </summary> /// <param name="cqg_constant_volume_bars"> /// Reference to changed CQGConstantVolumeBars. /// </param> private void CEL_ConstantVolumeBarsAdded(CQG.CQGConstantVolumeBars cqg_constant_volume_bars) { try { lock (m_Token4) { try { // try get the set KaiTrade.Interfaces.ITSSet mySet; if (m_TSSets.ContainsKey(cqg_constant_volume_bars.Id)) { mySet = m_TSSets[cqg_constant_volume_bars.Id]; mySet.Items.Clear(); if (cqg_constant_volume_bars.Status == eRequestStatus.rsSuccess) { DumpAllData(cqg_constant_volume_bars, mySet); } else { mySet.Text = cqg_constant_volume_bars.LastError.Description; } } } catch (Exception myE) { log.Error("CEL_ConstantVolumeBarsAdded", myE); } } } catch { } }
/// <summary> /// Fired when CQGConstantVolumeBar item is updated. /// </summary> /// <param name="cqg_constant_volume_bars"> /// Reference to changed CQGConstantVolumeBars /// </param> /// <param name="index_"> /// Specifies the updated CQGConstantVolumeBar index. /// </param> private void CEL_ConstantVolumeBarsUpdated(CQG.CQGConstantVolumeBars cqg_constant_volume_bars, int index_) { try { lock (m_Token4) { try { // try get the set KaiTrade.Interfaces.ITSSet mySet; //return; if (m_TSSets.ContainsKey(cqg_constant_volume_bars.Id)) { mySet = m_TSSets[cqg_constant_volume_bars.Id]; if (!mySet.ReportAll) { // they only want added bars - so exit return; } KaiTrade.Interfaces.ITSItem myItem = mySet.GetNewItem(); DumpRecord(myItem, mySet, cqg_constant_volume_bars[index_], index_); mySet.ReplaceItem(myItem, index_); mySet.Changed = true; } } catch (Exception myE) { log.Error("CEL_ConstantVolumeBarsUpdated", myE); } } } catch { } }
/// <summary> /// This event is fired as a response to a Tradable Commodities request either when the /// collection is resolved or when an error has occurred during the request processing. /// </summary> /// <param name="GWAccountID"> /// Gateway account ID, for which tradable commodity names were requested, represented as Long. /// </param> /// <param name="commodityNames"> /// Collection of the tradable commodities. /// </param> /// <param name="cqgErr"> /// CQGError object representing the error occurred while processing the time series request. /// </param> private void CEL_TradableCommoditiesResolved(int GWAccountID, CQG.CQGCommodities commodityNames, CQG.CQGError cqgErr) { try { // Raise error, when an error occurs during the request. if (cqgErr != null) { string myError = "Error " + cqgErr.Code + ": " + cqgErr.Description; throw new Exception(myError); } // just do futures for now eInstrumentType myType = eInstrumentType.itFuture; for (int l = 0; l <= commodityNames.Count - 1; l++) { m_CQGHostForm.CQGApp.RequestCommodityInstruments(commodityNames[l], myType, true); } } catch (Exception myE) { log.Error("CEL_TradableCommoditiesResolved", myE); } }
/// <summary> /// Fired when a CQGExpressionOutputs item is updated. /// </summary> /// <param name="cqg_expression"> /// Reference to changed CQGExpression /// </param> /// <param name="index_"> /// Specifies the updated CQGExpressionOutputs index. /// </param> private void CEL_ExpressionUpdated(CQG.CQGExpression cqg_expression, int index_) { try { lock (m_ExpToken1) { try { // try get the set KaiTrade.Interfaces.ITSSet mySet; lock (m_Token1) { if (m_TSSets.ContainsKey(cqg_expression.Id)) { mySet = m_TSSets[cqg_expression.Id]; if (!mySet.ReportAll) { // they only want added bars - so exit return; } if (wireLog.IsInfoEnabled) { wireLog.Info("CEL_ExpressionUpdated:TSSetFound:" + mySet.Name + ":" + mySet.Alias + ":" + mySet.Mnemonic); } if ((mySet.Items.Count - 1) == index_) { // get a new TS item //KaiTrade.Interfaces.ITSItem myItem = mySet.GetNewItem(); //myItem.Index = i; //myItem.TimeStamp = cqg_expression[index_].Timestamp; //myItem.ConditionName = mySet.ConditionName; CQGExpressionOutputs expressionOutputs = cqg_expression[index_]; string myDump = "CEL_EUPD" + "|" + expressionOutputs.Timestamp.ToString(); mySet.TimeStamp = expressionOutputs.Timestamp; for (int j = 0; j <= expressionOutputs.Count - 1; j++) { //myItem.SetCurveValue(cqg_expression.OutputHeaders[j], double.Parse(expressionOutputs[j].ToString())); mySet.SetUDCurveValue(j, double.Parse(expressionOutputs[j].ToString())); mySet.SetUDCurveName(j, cqg_expression.OutputHeaders[j].ToString()); myDump += "|" + cqg_expression.OutputHeaders[j].ToString() + "|" + expressionOutputs[j].ToString(); } wireLog.Info(myDump); } else { } mySet.Updated = true; } } } catch (Exception myE) { log.Error("CEL_ExpressionUpdated", myE); } } } catch { } }
/// <summary> /// This event is fired when the expression (CQGExpression) is resolved or /// when some error has occurred during the expression request processing. /// </summary> /// <param name="cqg_expression"> /// Reference to resolved CQGExpression /// </param> /// <param name="cqg_error"> /// CQGError object describing the last error occurred during the expression /// request processing or Nothing/Invalid_Error in case of no error. /// CQGCEL.IsValid(Invalid_Error) returns False. /// </param> private void CEL_ExpressionResolved(CQG.CQGExpression cqg_expression, CQG.CQGError cqg_error) { try { lock (m_ExpToken1) { try { driverLog.Info("CEL_ExpressionResolved:" + cqg_expression.Id.ToString()); // try get the set KaiTrade.Interfaces.ITSSet mySet; if (m_TSSets.ContainsKey(cqg_expression.Id)) { mySet = m_TSSets[cqg_expression.Id]; if (wireLog.IsInfoEnabled) { wireLog.Info("CEL_ExpressionResolved:TSSetFound:" + mySet.Name + ":" + mySet.Alias + ":" + mySet.Mnemonic); } if (cqg_expression.Status == eRequestStatus.rsSuccess) { // Clears all records mySet.Items.Clear(); mySet.Status = KaiTrade.Interfaces.Status.open; if (cqg_expression.Count == 0) { return; } for (int i = 0; i < cqg_expression.Count; i++) { // get a new TS item KaiTrade.Interfaces.ITSItem myItem = mySet.GetNewItem(); myItem.Index = i; myItem.TimeStamp = cqg_expression[i].Timestamp; myItem.ConditionName = mySet.ConditionName; CQGExpressionOutputs expressionOutputs = cqg_expression[i]; for (int j = 0; j <= expressionOutputs.Count - 1; j++) { myItem.SetCurveValue(cqg_expression.OutputHeaders[j], double.Parse(expressionOutputs[j].ToString())); } myItem.DriverChangedData = true; mySet.AddItem(myItem); } mySet.Added = true; } else { mySet.Text = cqg_error.Description; mySet.Status = KaiTrade.Interfaces.Status.error; this.SendStatusMessage(KaiTrade.Interfaces.Status.open, "CEL_ExpressionResolved" + mySet.Text); } } else { driverLog.Info("CEL_ExpressionResolved:TSData not found"); } } catch (Exception myE) { log.Error("CEL_ExpressionResolved", myE); } } } catch { } }
/// <summary> /// This event is fired, when some changes occur in the connection with CQG data server. /// </summary> /// <param name="newStatus"> /// The current status of the connection with the data server. /// </param> private void CEL_DataConnectionStatusChanged(CQG.eConnectionStatus new_status) { System.Drawing.Color BackCol; try { if (new_status == eConnectionStatus.csConnectionUp) { BackCol = System.Drawing.Color.FromArgb(0, 209, 15); m_NotStarted = 1; m_sInfo = "UP"; nudDOMDepth.Enabled = false; btnCancel.Enabled = true; btnStop.Enabled = true; btnStart.Enabled = false; } else if (new_status == eConnectionStatus.csConnectionDelayed) { BackCol = System.Drawing.Color.FromArgb(205, 114, 0); m_sInfo = "De"; m_NotStarted = 0; nudDOMDepth.Enabled = false; btnCancel.Enabled = false; btnStop.Enabled = false; btnStart.Enabled = true; } else { BackCol = System.Drawing.Color.FromArgb(255, 0, 0); m_sInfo = "Do"; m_NotStarted = 0; nudDOMDepth.Enabled = true; btnCancel.Enabled = false; btnStop.Enabled = false; btnStart.Enabled = true; } lblDataConnStatus.BackColor = BackCol; lblDataConnStatus.Text = m_sInfo; } catch (Exception ex) { modErrorHandler.ShowError("frmTickNet", "CEL_DataConnectionStatusChanged", ex); } }
/// <summary> /// This event is fired, when an instrument is resolved and subscribed //' Description: Occurs when an instrument is resolved and subscribed //' //' Parameters: //' symbol_ (string) <in> - the symbol used in the btnSubscribe function //' Instrument (CQGInstrument) <in> - the subscribed CQGInstrument public void CEL_InstrumentSubscribed(string symbol, CQG.ICQGInstrument instrument) { try { if (instrument == null) { // Failed to subscribe instrument //lblSymbolStatus.Text = "Not Valid"; return; } System.Drawing.Color BackCol; BackCol = System.Drawing.Color.FromArgb(0, 255, 0); //lblSymbolStatus.Text = "Not Valid"; lblSymbolStatus.BackColor = BackCol; instrument.DataSubscriptionLevel = eDataSubscriptionLevel.dsQuotesAndDOM; //lblSymbolStatus.Text = "Valid"; } catch (Exception ex) { modErrorHandler.ShowError("ticknet", "CEL_InstrumentSubscribed", ex); } }