// // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** public DropRules2(FillHub fillHub) { this.UniqueUserName = fillHub.Name; this.m_FillHub = fillHub; this.DropFileStartDateTime = fillHub.Log.GetTime(); // time stamp "label" used for archiving current drop file. #if (DEBUG) BookDropPeriod = new TimeSpan(0, 5, 0); #endif this.LastBookDrop = fillHub.Log.GetTime().Subtract(this.BookDropPeriod).AddMinutes(5.0); this.m_LocalTimeLast = this.LastBookDrop; this.NextResetDateTime = this.NextResetDateTime.Subtract(this.NextResetDateTime.TimeOfDay).Add(ResetTimeOfDay); string path = this.GetLocalPath(); string fileName = this.GetLocalFileName(); this.m_FillHub.Log.NewEntry(LogLevel.Major, "DropRules: Dropping to {0}{1}", path, fileName); m_DropWriter = new DropQueueWriter(path, fileName); // Raw Fill drops string dropDirPath = this.GetArchivePath(DateTime.Now); string dropFileName = this.GetArchiveFileName(DateTime.Now, "Fills"); m_DropFills = new DropQueueWriter(dropDirPath, dropFileName); }
// // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** /// <summary> /// After constructing the drop rules, one can load a previous file or change /// parameters before writing. The writers are created only after calling "Start()". /// </summary> /// <param name="fillHub"></param> public DropRules(FillHub fillHub) { // Create the unique user name. // UserLoginID + FillHubName (usually acct#) // TTApiService api = TTApiService.GetInstance(); this.UniqueUserName = string.Format("{0}_{1}", api.LoginUserName, fillHub.Name); //this.UniqueUserName = fillHub.Name; this.m_FillHub = fillHub; this.DropFileStartDateTime = fillHub.Log.GetTime(); // time stamp "label" used for archiving current drop file. m_StringifyOverrideTable = new Dictionary <Type, string[]>(); m_StringifyOverrideTable.Add(m_FillHub.GetType(), new string[] { string.Empty, "GetAttributesDrop", "GetElementsDrop" }); //#if (DEBUG) //BookDropPeriod = new TimeSpan(0, 5, 0); //PushToRepository = false; //#endif this.LastBookDrop = fillHub.Log.GetTime().Subtract(this.BookDropPeriod).AddMinutes(5.0); this.m_LocalTimeLast = this.LastBookDrop; //this.NextResetDateTime = this.NextResetDateTime.Subtract(this.NextResetDateTime.TimeOfDay).Add(ResetTimeOfDay); }
// ***************************************************************** // **** Constructors **** // ***************************************************************** public FormRejectViewer(FillHub fillHub) { m_FillHub = fillHub; //m_FillHub.FillRejectionsUdated += new EventHandler(FillHub_FillRejectionsUpdate); InitializeComponent(); UpdateSelectedItem(null); }
private List <string> m_PropertyFormat = new List <string>(); // column formats // // // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** public FormFillBookViewer(Ambre.TTServices.Markets.MarketTTAPI priceHub, FillHub aFillHub) { InitializeComponent(); Log = aFillHub.Log; m_FillHub = aFillHub; m_Market = priceHub; UpdateNewFills(); }// FormFillBookViewer()
// // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** public FormAddFills(Ambre.TTServices.Markets.MarketTTAPI priceHub, FillHub aFillHub) { InitializeComponent(); Log = aFillHub.Log; m_FillHub = aFillHub; m_Market = priceHub; this.buttonDeleteBook.Text = ButtonDeleteBook_Normal; // set this to normal this.buttonDeleteBook.Enabled = false; // TODO: disable until i can work out the "dupe key" problems. #if (DEBUG) this.buttonDeleteBook.Enabled = false; #endif }
}// UpdateInstruments() // // private void UpdateInstrumentDetails() { // Get selected fill hub. if (comboBoxFillHubs.SelectedItem == null) { return; } string fillHubName = comboBoxFillHubs.SelectedItem.ToString(); FillHub fillHub = null; if (!m_FillHubs.TryGetValue(fillHubName, out fillHub)) { return; } // Get selected instrument if (comboBoxInstruments.SelectedItem == null) { return; } InstrumentName instrument = new InstrumentName(); if (comboBoxInstruments.SelectedItem is InstrumentName) { instrument = (InstrumentName)comboBoxInstruments.SelectedItem; } // Get information about this instrument. IFillBook posBook = null; if ((!instrument.IsEmpty) && fillHub.TryEnterReadBook(instrument, out posBook)) { double x = posBook.RealizedDollarGains; this.textBoxRealPnL.Text = x.ToString(); this.textBoxRealPnLNew.Text = "0"; x = posBook.RealizedStartingDollarGains; this.textBoxStartRealPnL.Text = x.ToString(); this.textBoxStartRealPnLNew.Text = "0"; fillHub.ExitReadBook(instrument); } else { // No specific instrument is selected this.textBoxRealPnL.Text = "0"; this.textBoxRealPnLNew.Text = "0"; this.textBoxStartRealPnL.Text = "0"; this.textBoxStartRealPnLNew.Text = "0"; } }// UpdateInstrumentDetails()
// // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** /// <summary> /// After constructing the drop rules, one can load a previous file or change /// parameters before writing. The writers are created only after calling "Start()". /// </summary> /// <param name="fillHub"></param> public DropSimple(FillHub fillHub) { // Create the unique user name. TTApiService api = TTApiService.GetInstance(); this.UniqueUserName = string.Format("{0}_{1}", api.LoginUserName, fillHub.Name); this.m_FillHub = fillHub; this.DropFileStartDateTime = fillHub.Log.GetTime(); // time stamp "label" used for archiving current drop file. m_StringifyOverrideTable = new Dictionary <Type, string[]>(); m_StringifyOverrideTable.Add(m_FillHub.GetType(), new string[] { string.Empty, "GetAttributesDrop", "GetElementsDrop" }); this.LastBookDrop = fillHub.Log.GetTime().Subtract(this.BookDropPeriod).AddMinutes(5.0); this.m_LocalTimeLast = this.LastBookDrop; }
// // #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()
// ***************************************************************** // **** Private Methods **** // ***************************************************************** // // // // // // **** ShutDown() **** // /// <summary> /// Called when the form is about to close to release resources nicely. /// </summary> private void ShutDown() { if (!m_IsAppShuttingDown) { m_IsAppShuttingDown = true; if (Log != null) { Log.RequestStop(); Log = null; } if (m_FillHub != null) { //m_FillHub.PositionBookCreated -= new EventHandler(FillHub_PositionBookCreated); //m_FillHub.PositionBookChanged -= new EventHandler(FillHub_PositionBookChanged); //m_FillHub.PositionBookPnLChanged -= new EventHandler(FillHub_PositionBookPnLChanged); m_FillHub.Request(new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestShutdown)); m_FillHub = null; } if (m_MarketHub != null) { m_MarketHub.RequestStop(); m_MarketHub = null; } if (m_TTServices != null) { m_TTServices.ServiceStateChanged -= new EventHandler(TTServices_ServiceStateChanged); m_TTServices.Dispose(); m_TTServices = null; } if (m_TalkerHub != null) { m_TalkerHub.ServiceStateChanged -= new EventHandler(TalkerHub_ServiceStateChanged); m_TalkerHub.Request(TalkerHubRequest.StopService); //m_TalkerHub = null; } } }//Shutdown().
// private void CollectStateInfo(ControlPnLTransferTool control, out FillHub leftFillHub, out InstrumentName leftInstrumentName, out List <double> leftDoubles) { leftFillHub = null; leftInstrumentName = new InstrumentName(); leftDoubles = new List <double>(); int ptr = 0; List <object> leftStates = control.GetCurrentState(); string fillHubName = leftStates[ptr].ToString(); ptr++; if (!m_FillHubs.TryGetValue(fillHubName, out leftFillHub)) { return; } //bool leftInstrumentSelected = false; if (leftStates[ptr] is InstrumentName) { leftInstrumentName = (InstrumentName)leftStates[ptr]; //leftInstrumentSelected = true; } else { leftInstrumentName = new InstrumentName(); } ptr++; // Load all the remaining numbers in data set. while (ptr < leftStates.Count) { double x = double.NaN; if (double.TryParse(leftStates[ptr].ToString(), out x)) { leftDoubles.Add(x); } ptr++; } }
// // // #endregion//Constructors #region Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // ********************************************* // **** AddHub() **** // ********************************************* /// <summary> /// User must add hub to which this page will listen to/and display /// position changes. /// </summary> /// <param name="newFillHub"></param> public void AddHub(FillHub newFillHub) { // Add to our fillhubs m_FillHub = newFillHub; if (Log == null) { Log = m_FillHub.Log; // Use first fillHub's log as my own. } // Listen to its events newFillHub.PositionBookCreated += new EventHandler(FillHub_PositionBookCreated); newFillHub.PositionBookDeleted += new EventHandler(FillHub_PositionBookDeleted); newFillHub.PositionBookChanged += new EventHandler(FillHub_PositionBookChanged); // Rename this page after the fill hub it describes. if (string.IsNullOrEmpty(newFillHub.Name)) { this.Text = "Total"; } else { this.Text = newFillHub.Name; } }//AddHub()
}//constructor // // private void InitializeServices() { AppInfo info = AppInfo.GetInstance("Bret"); bool isLogViewerVisible = false; #if (DEBUG) isLogViewerVisible = true; #endif Log = new LogHub("TalkerForm", info.LogPath, isLogViewerVisible, LogLevel.ShowAllMessages); // Instantiate TT API. m_TTServices = TTServices.TTApiService.GetInstance(); m_TTServices.ServiceStateChanged += new EventHandler(TTServices_ServiceStateChanged); m_TTServices.Start(true); // Instantiate hubs m_MarketHub = new MarketTTAPI(); m_MarketHub.Log.IsViewActive = isLogViewerVisible; //m_MarketHub.InstrumentChanged += new EventHandler(MarketHub_InstrumentChanged); m_MarketHub.Start(); m_FillHub = new FillHub(string.Empty, isLogViewerVisible); m_FillHub.MarketHub = m_MarketHub; //m_FillHub.PositionBookCreated += new EventHandler(FillHub_PositionBookCreated); //m_FillHub.PositionBookChanged += new EventHandler(FillHub_PositionBookChanged); //m_FillHub.PositionBookPnLChanged += new EventHandler(FillHub_PositionBookPnLChanged); m_FillHub.Start(); m_TalkerHub = new TalkerHub(isLogViewerVisible); m_TalkerHub.ServiceStateChanged += new EventHandler(TalkerHub_ServiceStateChanged); m_TalkerHub.RequestAddHub(m_FillHub); m_TalkerHub.Start(); }
private List <UV.Lib.OrderHubs.Fill> m_DropFillList = new List <UV.Lib.OrderHubs.Fill>(); // workspace // #endregion// members #region Constructors // ***************************************************************** // **** Constructors **** // ***************************************************************** public DropRulesOld(FillHub fillHub, UV.Lib.IO.Drops.DropQueueWriter dropWriter) { m_FillHub = fillHub; Log = m_FillHub.Log; m_DropWriter = dropWriter; }
// // #endregion//Constructors #region Properties // ***************************************************************** // **** Properties **** // ***************************************************************** public void UpdateNow(FillHub fillHub) { m_FillHub = fillHub; UpdateRejectList(); }
}// // // // // #endregion//Constructors #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // // // // public void ControlPanel_ButtonClicked(object sender, EventArgs eventArgs) { if (!(sender is Button)) { return; } Button button = (Button)sender; try { if (button.Parent != m_LeftControl) { return; // at present, only buttons active on left control } // // Collect the state of the LEFT control // FillHub leftFillHub; InstrumentName leftInstrumentName; List <double> leftDoubles; CollectStateInfo(m_LeftControl, out leftFillHub, out leftInstrumentName, out leftDoubles); // // Collect the state of the RIGHT control // FillHub rightFillHub = null; InstrumentName rightInstrumentName = new InstrumentName(); List <double> rightDoubles = new List <double>(); if (m_IsRightControlVisible) { CollectStateInfo(m_RightControl, out rightFillHub, out rightInstrumentName, out rightDoubles); } // // Process and submit request // string buttonName = button.Name; if (m_IsRightControlVisible) { // Transfer mode: transfer between left "from account" (left) to the "to account" (right) // Transfer from account: Misty.Lib.OrderHubs.OrderHubRequest leftRequest = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestRealPnLReset); leftRequest.Data = new object[3]; if (!leftInstrumentName.IsEmpty) { leftRequest.Data[0] = leftInstrumentName; } else { System.Windows.Forms.MessageBox.Show("Transfers must be from one Instrument to another.", "Request not submitted"); return; // Now, only transfers from specific instr to another is allowed. } double moneyToTransfer = 0; if (buttonName.Equals("buttonSubmitRealPnL")) { if (!double.IsNaN(leftDoubles[0])) // previous value { moneyToTransfer = leftDoubles[0]; } leftRequest.Data[1] = 0; // new value is zero. leftRequest.Data[2] = null; // leave starting-pnl alone. } else if (buttonName.Equals("buttonSubmitStartRealPnL")) { if (!double.IsNaN(leftDoubles[2])) { moneyToTransfer = leftDoubles[2]; } leftRequest.Data[1] = null; leftRequest.Data[2] = 0; // new value is zero. } else { System.Windows.Forms.MessageBox.Show(string.Format("Unknown button {0}", buttonName), "Request not submitted"); return; } // Transfer to account: Misty.Lib.OrderHubs.OrderHubRequest rightRequest = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestRealPnLReset); rightRequest.Data = new object[3]; if (!rightInstrumentName.IsEmpty) { rightRequest.Data[0] = rightInstrumentName; } else { MessageBox.Show("Transfers must be from one Instrument to another.", "Request not submitted"); return; // Now, only transfers from specific instr to another is allowed. } double currentMoney = 0; if (buttonName.Equals("buttonSubmitRealPnL")) { if (!double.IsNaN(rightDoubles[0])) // previous value { currentMoney = rightDoubles[0]; } else { MessageBox.Show(" \"Transfer to\" account has bad value for current PnL.", "Request not submitted"); return; } rightRequest.Data[1] = currentMoney + moneyToTransfer; // new value is sum rightRequest.Data[2] = null; // leave starting-pnl alone. } else if (buttonName.Equals("buttonSubmitStartRealPnL")) { if (!double.IsNaN(rightDoubles[2])) { currentMoney = rightDoubles[2]; } else { MessageBox.Show(" \"Transfer to\" account has bad value for current PnL.", "Request not submitted"); return; } rightRequest.Data[1] = null; // leave value alone rightRequest.Data[2] = currentMoney + moneyToTransfer; // new value } // Submit both requests now. StringBuilder msg = new StringBuilder(); msg.AppendFormat("From: \r\nAccount: {0} \r\nInstrument:{1}", leftFillHub.ServiceName, leftRequest.Data[0]); if (leftRequest.Data[1] != null) { msg.AppendFormat("\r\nDaily PnL: {0}", leftRequest.Data[1]); } else if (leftRequest.Data[2] != null) { msg.AppendFormat("\r\nStarting PnL: {0}", leftRequest.Data[2]); } else { MessageBox.Show(" \"Transfer from\" request has no values in data.", "Request not submitted"); return; } msg.Append("\r\n"); msg.AppendFormat("To: \r\nAccount: {0} \r\nInstrument:{1}", rightFillHub.ServiceName, rightRequest.Data[0]); if (rightRequest.Data[1] != null) { msg.AppendFormat("\r\nDaily PnL: {0}", rightRequest.Data[1]); } else if (rightRequest.Data[2] != null) { msg.AppendFormat("\r\nStarting PnL: {0}", rightRequest.Data[2]); } else { MessageBox.Show(" \"Transfer to\" request has no values in data.", "Request not submitted"); return; } msg.Append("\r\nPlease confirm these final amounts."); DialogResult result = MessageBox.Show(msg.ToString(), "Confirm transfer", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { leftFillHub.Request(leftRequest); // Subtract the money first. rightFillHub.Request(rightRequest); } } else { // User supplied MANUAL values for PnL. if (buttonName.Equals("buttonSubmitRealPnL")) { Misty.Lib.OrderHubs.OrderHubRequest request = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestRealPnLReset); request.Data = new object[3]; if (!leftInstrumentName.IsEmpty) { request.Data[0] = leftInstrumentName; } else { request.Data[0] = null; // means update all instruments. } if (!double.IsNaN(leftDoubles[1])) { request.Data[1] = leftDoubles[1]; // value to update all instrument pnl. } else { MessageBox.Show("Manual value is not set.", "Request not submitted"); return; } request.Data[2] = null; // null means leave starting PnL alone. leftFillHub.Request(request); } else if (buttonName.Equals("buttonSubmitStartRealPnL")) { Misty.Lib.OrderHubs.OrderHubRequest request = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestRealPnLReset); request.Data = new object[3]; if (!leftInstrumentName.IsEmpty) { request.Data[0] = leftInstrumentName; } else { request.Data[0] = null; // means update all instruments. } request.Data[1] = null; // null means leave daily real pnl alone. if (!double.IsNaN(leftDoubles[3])) // update the starting pnl. { request.Data[2] = leftDoubles[3]; } else { MessageBox.Show("Manual value is not set.", "Request not submitted"); return; } leftFillHub.Request(request); } } } catch (Exception) { } }
}//HubEventHandler() // // // ********************************************************* // **** Process Hub Request **** // ********************************************************* /// <summary> /// Direct requests from outsiders for managing this TalkerHub. /// </summary> private void ProcessRequest(TalkerHubEventArg eventArg) { switch (eventArg.Request) { case TalkerHubRequest.AmberXLConnect: // try to connect to Excel if (m_SocketBreTalker == null) { m_SocketBreTalker = new SocketManager(); m_SocketBreTalker.Connected += new EventHandler(HubEventEnqueue); m_SocketBreTalker.Disconnected += new EventHandler(HubEventEnqueue); m_SocketBreTalker.MessageReceived += new EventHandler(HubEventEnqueue); } if (!TryToConnectToExcel()) { // Failed to connect. // TODO: Put this request in our waiting queue and try again periodically. m_AmbreXLReconnectFailureCount++; m_AmbreXLReconnectCounter = Math.Min(AmbreXLReconnectCounterMin * m_AmbreXLReconnectFailureCount, AmbreXLReconnectCounterMax); Log.NewEntry(LogLevel.Major, "ProcessRequest: Failed {0} times to connect to socket. Try again in {1:0.0} seconds.", m_AmbreXLReconnectFailureCount, (m_AmbreXLReconnectCounter / 1000.0)); } else { Log.NewEntry(LogLevel.Major, "ProcessRequest: Connected to Socket."); } break; case TalkerHubRequest.AmbreXLDisconnect: m_SocketBreTalker.StopConversation(); break; case TalkerHubRequest.StopService: if (m_SocketBreTalker != null) { m_SocketBreTalker.StopConversation(); if (m_SocketBreTalker.IsServing) { m_SocketBreTalker.StopServer(); } } this.Stop(); break; case TalkerHubRequest.RequestAddHub: if (eventArg.Data != null) { foreach (object newHub in eventArg.Data) { if (newHub is FillHub) { FillHub newFillHub = (FillHub)newHub; FillHub oldFillHub; if (m_FillHubs.TryGetValue(newFillHub.Name, out oldFillHub)) { // User must want to replace fill hub with same name... m_FillHubs.Remove(oldFillHub.Name); oldFillHub.PositionBookCreated -= new EventHandler(HubEventEnqueue); // unsubscribe to this old hub oldFillHub.PositionBookChanged -= new EventHandler(HubEventEnqueue); oldFillHub.PositionBookDeleted -= new EventHandler(HubEventEnqueue); } m_FillHubs.Add(newFillHub.Name, newFillHub); newFillHub.PositionBookCreated += new EventHandler(HubEventEnqueue); // subscribe to this new hub newFillHub.PositionBookChanged += new EventHandler(HubEventEnqueue); newFillHub.PositionBookDeleted += new EventHandler(HubEventEnqueue); } // if new hub is FillHub type. else if (newHub is MarketTTAPI) { //UV.Lib.MarketHubs.MarketHub marketHub = (UV.Lib.MarketHubs.MarketHub)newHub; MarketTTAPI marketHub = (MarketTTAPI)newHub; m_MarketHub = marketHub; } } //for each hub passed to us. } // if request contains data. break; default: break; } }//ProcessRequest()
}//UpdateMarketTopics. // // // // private void CategorizeTopic(Topic topic) { string hubName = topic.HubName; if (string.IsNullOrEmpty(hubName)) { hubName = DefaultHubName; } // New Dictionary <InstrumentName, Dictionary <SubscriptionType, List <Topic> > > m_Subscriptions = null; if (!m_SubscriptionsByHubName.TryGetValue(hubName, out m_Subscriptions)) { // Create a new subscription list for this hub. m_Subscriptions = new Dictionary <InstrumentName, Dictionary <SubscriptionType, List <Topic> > >(); m_SubscriptionsByHubName.Add(hubName, m_Subscriptions); } // Create subscription lists for any new Instruments found. if (topic.Type != SubscriptionType.Unknown && !m_Subscriptions.ContainsKey(topic.Instrument)) { m_Subscriptions.Add(topic.Instrument, new Dictionary <SubscriptionType, List <Topic> >()); } Dictionary <SubscriptionType, List <Topic> > subscriptionList; // A list of all subscriptions of the desired type! if (m_Subscriptions.TryGetValue(topic.Instrument, out subscriptionList)) { if (!subscriptionList.ContainsKey(topic.Type)) { subscriptionList.Add(topic.Type, new List <Topic>()); } List <Topic> topicList; if (subscriptionList.TryGetValue(topic.Type, out topicList)) // list of subscriptions for desired type and instrument. { if (!topicList.Contains(topic)) { // This is a new topic. The user may ask for same subscription multiple times. // That would be inefficient, but if he does then this list will contain multiple topics // that all show the same information. Log.NewEntry(LogLevel.Minor, "New subscription {0}.", topic); topicList.Add(topic); } else { // We have already categorized this topic. Do nothing. } } else { Log.NewEntry(LogLevel.Warning, "CategorizeTopic problem 1."); } } else { Log.NewEntry(LogLevel.Warning, "CategorizeTopic problem 2."); } // // Calculate initial value. // FillHub m_FillHub = null; if (m_FillHubs.TryGetValue(hubName, out m_FillHub)) { switch (topic.Type) { case SubscriptionType.Position: FillBookLifo book; if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.NetPosition.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue("0"); } break; case SubscriptionType.AvePositionCost: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.AveragePrice.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; case SubscriptionType.RealPnL: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.RealizedDollarGains.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; case SubscriptionType.StartingRealPnL: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.RealizedStartingDollarGains.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; case SubscriptionType.UnRealPnL: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.UnrealizedDollarGains().ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; case SubscriptionType.Volume: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.Volume.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; case SubscriptionType.StartingVolume: if (m_FillHub.TryEnterReadBook(topic.Instrument, out book)) { topic.SetValue(book.StartingVolume.ToString()); m_FillHub.ExitReadBook(topic.Instrument); } else { topic.SetValue(""); } break; default: break; } } else { topic.SetValue("Unknown HubName"); } }//CategorizeTopic()
}//ProcessRequest() // // // ********************************************************* // **** Process FillHub Event **** // ********************************************************* /// <summary> /// Processes events from a fill hub. Events include PositionBook changed or created events. /// The fillhub ptr and InstrumentName (corresponding to the book) is passed to us. We lookup any subscription /// topics for these. /// </summary> /// <param name="eventArg"></param> private void ProcessFillHubEvent(FillHub.PositionBookChangedEventArgs eventArg) { FillHub callingHub = eventArg.Sender; // pointer to the particular FillHub from which event was created. string name = callingHub.Name; if (string.IsNullOrEmpty(name)) { name = DefaultHubName; } InstrumentName instrument = eventArg.Instrument; // Search for the FillHub in our list of subscriptions. Dictionary <InstrumentName, Dictionary <SubscriptionType, List <Topic> > > m_Subscriptions = null; if (!m_SubscriptionsByHubName.TryGetValue(name, out m_Subscriptions)) { return; } Dictionary <SubscriptionType, List <Topic> > subscriptionList; if (m_Subscriptions.TryGetValue(instrument, out subscriptionList) && subscriptionList.Count > 0) { // We have some active subscriptions for this instrument. string newValue; FillBookLifo book; if (callingHub.TryEnterReadBook(instrument, out book)) { // We found the book that changed its position. Update all things that may have changed. // // Update everything about this book. // List <Topic> topicList; if (subscriptionList.TryGetValue(SubscriptionType.Position, out topicList)) { newValue = book.NetPosition.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.AvePositionCost, out topicList)) { newValue = book.AveragePrice.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.RealPnL, out topicList)) { newValue = book.RealizedDollarGains.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.StartingRealPnL, out topicList)) { newValue = book.RealizedStartingDollarGains.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.UnRealPnL, out topicList)) { newValue = book.UnrealizedDollarGains().ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.Volume, out topicList)) { newValue = book.Volume.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.StartingVolume, out topicList)) { newValue = book.StartingVolume.ToString(); foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } callingHub.ExitReadBook(instrument); } else { // We have a subscription request for this instrument, we obtained an event from it, // yet, when we inquire about this instrument, it is unknown!?!? // This CAN happen whenever an specific fill book is deleted by the user. List <Topic> topicList; newValue = "0"; if (subscriptionList.TryGetValue(SubscriptionType.Position, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.AvePositionCost, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.RealPnL, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.StartingRealPnL, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.UnRealPnL, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.Volume, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } if (subscriptionList.TryGetValue(SubscriptionType.StartingVolume, out topicList)) { foreach (Topic topic in topicList) { if (!topic.PeekAtValue().Equals(newValue)) { topic.SetValue(newValue); } } } } } //else // Log.NewEntry(LogLevel.Minor, "ProcessFillHubEvent: No subscriptions for {0}.",instrument); // user hasn't subscribed to this instrument. }//ProcessFillHubEvent().