private void getTSBarData(ref KaiTrade.Interfaces.ITSSet myTSSet) { CQGTimedBars myTimedBars; CQGTimedBarsRequest myReq; try { driverLog.Info("getTSBarData:" + myTSSet.ToString()); myTSSet.Status = KaiTrade.Interfaces.Status.opening; myReq = m_CQGHostForm.CQGApp.CreateTimedBarsRequest(); // Get the CQG Instrument for the request CQGInstrument instrument = GetInstrument(myTSSet.Mnemonic); if (instrument == null) { instrument = GetInstrumentWithMnemonic(myTSSet.Mnemonic); if (instrument == null) { Exception myE = new Exception("Invalid instrument"); throw myE; } } myReq.Symbol = instrument.FullName; switch (myTSSet.RangeType) { case KaiTrade.Interfaces.TSRangeType.IntInt: myReq.RangeStart = myTSSet.IntStart; myReq.RangeEnd = myTSSet.IntEnd; break; case KaiTrade.Interfaces.TSRangeType.DateInt: myReq.RangeStart = myTSSet.DateTimeStart; myReq.RangeEnd = myTSSet.IntEnd; break; case KaiTrade.Interfaces.TSRangeType.DateDate: myReq.RangeStart = myTSSet.DateTimeStart; myReq.RangeEnd = myTSSet.DateTimeEnd; break; default: break; } myReq.IncludeEnd = myTSSet.IncludeEnd; int interval; if (isIntraDay(out interval, myTSSet.Period)) { myTSSet.IntraDayInterval = interval; myReq.IntradayPeriod = myTSSet.IntraDayInterval; } else { switch (myTSSet.Period) { case KaiTrade.Interfaces.TSPeriod.Day: myReq.HistoricalPeriod = eHistoricalPeriod.hpDaily; break; case KaiTrade.Interfaces.TSPeriod.Week: myReq.HistoricalPeriod = eHistoricalPeriod.hpWeekly; break; case KaiTrade.Interfaces.TSPeriod.Month: myReq.HistoricalPeriod = eHistoricalPeriod.hpMonthly; break; case KaiTrade.Interfaces.TSPeriod.Quarter: myReq.HistoricalPeriod = eHistoricalPeriod.hpQuarterly; break; case KaiTrade.Interfaces.TSPeriod.SemiYear: myReq.HistoricalPeriod = eHistoricalPeriod.hpSemiannual; break; case KaiTrade.Interfaces.TSPeriod.Year: myReq.HistoricalPeriod = eHistoricalPeriod.hpYearly; break; default: myReq.HistoricalPeriod = eHistoricalPeriod.hpUndefined; break; } } // Not used myReq.Continuation = eTimeSeriesContinuationType.tsctNoContinuation; myReq.EqualizeCloses = true; myReq.DaysBeforeExpiration = 0; myReq.UpdatesEnabled = myTSSet.UpdatesEnabled; myReq.SessionsFilter = 0; switch (myTSSet.TSSessionFlags) { case KaiTrade.Interfaces.TSSessionFlags.Undefined: myReq.SessionFlags = eSessionFlag.sfUndefined; break; case KaiTrade.Interfaces.TSSessionFlags.DailySession: myReq.SessionFlags = eSessionFlag.sfDailyFromIntraday; break; default: myReq.SessionFlags = eSessionFlag.sfUndefined; break; } myReq.SessionsFilter = (int)myTSSet.TSSessionFilter; // depending of the type of request myTimedBars = m_CQGHostForm.CQGApp.RequestTimedBars(myReq); myTSSet.ExternalID = myTimedBars.Id; myTSSet.ExternalRef = myTimedBars; m_TSSets.Add(myTSSet.ExternalID, myTSSet); driverLog.Info("getTSBarData completed cqgid:" + myTimedBars.Id.ToString() + ":" + myTimedBars.Status.ToString()); } catch (Exception myE) { log.Error("getTSBarData", myE); this.SendStatusMessage(KaiTrade.Interfaces.Status.open, "getTSBarData" + myE.Message); myTSSet.Status = KaiTrade.Interfaces.Status.error; myTSSet.Text = myE.Message; } }
/// <summary> /// Apply any change in status as a status message and /// update to the internal status header /// </summary> /// <param name="myStatus"></param> private void updateStatus(KaiTrade.Interfaces.Status myStatus) { try { // if the status has changes then do an // status update if (m_PubStatus != myStatus) { m_PubStatus = myStatus; m_Status = new K2DataObjects.Field("STATUS", myStatus.ToString()); m_StatusInfo = new System.Collections.Generic.List<KaiTrade.Interfaces.IField>(); m_StatusInfo.Add(m_Status); applyStatus(m_StatusInfo); } // then update the synthetic status field doUpdate(); } catch (Exception myE) { m_Log.Error("updateStatus", myE); } }
/// <summary> /// submit a complete order for processing, note the order must have a /// valid product and trade venue /// </summary> /// <param name="myOrder"></param> public void SubmitOrder(KaiTrade.Interfaces.Order myOrder) { try { lock (this) { QuickFix.Message myNOS; KaiTrade.Interfaces.Message myMsg; string myDriverCode; RenderOrderAsFix(out myNOS, out myMsg, out myDriverCode, myOrder); try { if (myOrder.OCAGroupName.Length > 0) { KTAFacade.Instance().Factory.GetOCOManager().AddOrderOCO(myOrder, myOrder.OCAGroupName); } //Send the message KaiTrade.Interfaces.Driver myDrv = AppFactory.Instance().GetDriverManager().GetDriver(myDriverCode); if (myDrv != null) { // send the message for processing order.LastOrderCommand = KaiTrade.Interfaces.LastOrderCommand.neworder; //SendDelegate mySend = new SendDelegate(myDrv.Send); //IAsyncResult ar = mySend.BeginInvoke(myMsg, SRCallback, "123456789"); myDrv.Send(myMsg); } else { string myError = "Driver not found for code:" + myDriverCode; m_Log.Error(myError); Exception myE = new Exception(myError); throw myE; } if (m_ORLog.IsInfoEnabled) { m_ORLog.Info("SubmitOrder:" + myOrder.ToString()); } } catch (Exception myE) { m_Log.Error("SubmitOrder:" + myOrder.Identity, myE); myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED); throw (myE); } } } catch (Exception myE) { m_Log.Error("SubmitOrder:", myE); myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED); myOrder.Text = myE.Message; // inform order manager clients that the order has changed AppFactory.Instance().GetOrderManager().SetChanged(myOrder.Identity); throw (myE); } }
/// <summary> /// Set the status of all subscriptions /// </summary> /// <param name="myStatus"></param> protected override void setSubscriptionsStatus(KaiTrade.Interfaces.Status myStatus) { try { driverLog.Info("setSubscriptionsStatus:" + myStatus.ToString()); foreach (KaiTrade.Interfaces.ITSSet mySet in m_TSSets.Values) { mySet.Status = myStatus; } base.setSubscriptionsStatus(myStatus); } catch (Exception myE) { log.Error("setSubscriptionsStatus", myE); } }
/// <summary> /// Disconnect a TSSet /// </summary> /// <param name="myTSSet"></param> public override void DisconnectTSData(KaiTrade.Interfaces.ITSSet myTSSet) { try { driverLog.Info("DisconnectTSData:" + myTSSet.ToString()); if (myTSSet.ExternalRef != null) { switch (myTSSet.TSType) { case KaiTrade.Interfaces.TSType.BarData: m_CQGHostForm.CQGApp.RemoveTimedBars(myTSSet.ExternalRef as CQGTimedBars); break; case KaiTrade.Interfaces.TSType.Condition: m_CQGHostForm.CQGApp.RemoveCondition(myTSSet.ExternalRef as CQGCondition); break; case KaiTrade.Interfaces.TSType.StudyData: m_CQGHostForm.CQGApp.RemoveCustomStudy(myTSSet.ExternalRef as CQGCustomStudy); break; case KaiTrade.Interfaces.TSType.Expression: m_CQGHostForm.CQGApp.RemoveExpression(myTSSet.ExternalRef as CQGExpression); break; case KaiTrade.Interfaces.TSType.TradeSystem: m_CQGHostForm.CQGApp.RemoveTradingSystem(myTSSet.ExternalRef as CQGTradingSystem); break; default: break; } } else { driverLog.Warn("Cannot disconnect set since no external ref provided"); } driverLog.Info("DisconnectTSData:Exit"); } catch (Exception myE) { log.Error("DisconnectTSData", myE); this.SendStatusMessage(KaiTrade.Interfaces.Status.open, "DoGetTSData" + myE.Message); } }
/// <summary> /// send a stuts message /// </summary> /// <param name="myState"></param> /// <param name="myText"></param> public void SendStatusMessage(KaiTrade.Interfaces.Status myState, string myText) { try { driverLog.Info(Name + ":" +myState.ToString() +":" + myText); // update the base session status UpdateStatus("DriverStatus", "", "", "", myState, myText); IDriverStatusMessage myDSM; setupStatus(out myDSM, myState, myText); KaiTrade.Interfaces.IMessage statusMsg = new K2DataObjects.Message(); statusMsg.Format = "XML"; statusMsg.Label = "DriverStatus"; statusMsg.Data = JsonConvert.SerializeObject(myDSM); SendStatusMessage(statusMsg); _lastStatus = statusMsg; } catch(Exception myE) { log.Error("SendStatusMessage", myE); } }
/// <summary> /// Set the status of all subscriptions /// </summary> /// <param name="myStatus"></param> protected virtual void setSubscriptionsStatus(KaiTrade.Interfaces.Status myStatus) { try { driverLog.Info("setSubscriptionsStatus:" + myStatus.ToString()); foreach (KaiTrade.Interfaces.IPublisher myPub in _publisherRegister.Values) { myPub.Status = myStatus; } } catch (Exception myE) { log.Error("setSubscriptionsStatus", myE); } }