/// <summary> /// Shows a dialog box for maintaining an blotter or fund. /// </summary> /// <param name="blotterId">Primary identifier for the blotter.</param> public virtual void Show(Blotter blotter) { try { // Make sure locks are not nested. Debug.Assert(!ClientMarketData.IsLocked); // Lock the tables needed for the dialog. ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.TypeLock.AcquireReaderLock(CommonTimeout.LockWait); // Find the blotter in the data model. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(blotter.BlotterId); if (blotterRow == null) { throw new Exception("Some else has deleted this blotter."); } // General Tab this.textBoxName.Text = blotterRow.ObjectRow.Name; this.labelTypeText.Text = blotterRow.ObjectRow.TypeRow.Description; this.textBoxDescription.Text = (blotterRow.ObjectRow.IsDescriptionNull()) ? "" : blotterRow.ObjectRow.Description; this.pictureBox.Image = blotter.Image32x32; } finally { // Release the tables used for the dialog. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.TypeLock.IsReaderLockHeld) { ClientMarketData.TypeLock.ReleaseReaderLock(); } // Make sure all locks have been released Debug.Assert(!ClientMarketData.IsLocked); } // Display the dialog. this.ShowDialog(); }
/// <summary> /// Initializes a Blotter. /// </summary> /// <param name="configurationId">Defines which external fields are used to identify an object.</param> /// <param name="blotterId">The blotter identifier.</param> /// <returns>A blotter record, null if the identifier doesn't exist.</returns> protected override void Initialize(int blotterId) { // Use the specified configuration to find the internal blotter identifier. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(blotterId); if (blotterRow == null) { throw new Exception(String.Format("Blotter {0} doesn't exist", blotterId)); } // Initialize the base class. base.Initialize(blotterId); // Initialize the record from the data model. this.blotterType = (BlotterType)blotterRow.BlotterTypeCode; }
protected override void OpenCommand() { try { // Lock the tables. System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait); // Each blotter can have a stylesheet assigned to it so Fixed Income traders view Fixed Income data, // equity traders Equity data, and so forth. If no blotter is assigned, a default will be provided. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null) { throw new ArgumentException("This blotter has been deleted", this.blotter.BlotterId.ToString()); } // If a viewer is avaiable for the objects associated with the blotter, then we'll enable the viewers for those // objects. For example, debt blotters don't require destinationOrder viewers, so there won't be one associated // with that blotter. this.hasDestinationOrderViewer = !blotterRow.IsDestinationOrderStylesheetIdNull(); this.hasExecutionViewer = !blotterRow.IsExecutionStylesheetIdNull(); this.hasSourceOrderViewer = !blotterRow.IsSourceOrderStylesheetIdNull(); } catch (Exception exception) { // Write the error out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the tables. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.StylesheetLock.IsReaderLockHeld) { ClientMarketData.StylesheetLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } if (this.hasExecutionViewer) { this.executionViewer.Open(this.Tag); } }
/// <summary> /// Creates a well formed block order document object model. /// </summary> /// <param name="blotterId">The blotter identifies what blocks are to be included in this document.</param> public BlockOrderDocument(int blotterId) { // Create the root element for the document. this.AppendChild(this.CreateElement("Blotter")); // Find the top level blotter record and recursively construct the report by merging all the children. ClientMarketData.BlotterRow mainBlotterRow = ClientMarketData.Blotter.FindByBlotterId(blotterId); if (mainBlotterRow != null) { RecurseBlotter(mainBlotterRow.ObjectRow); } // Calculate the derrived fields: aggregates like total quantity ordered, and distinct fields like // Time-in-Force and limit prices. this.CalculateFields(); }
/// <summary> /// Constructs a well formed Document Object Model for a group of executions on a block order. /// </summary> /// <param name="blockOrderId">The block order for which we want a execution document.</param> public TicketDocument(int blotterId) { // Create the root element for the document. XmlElement rootElement = this.CreateElement("Tickets"); this.AppendChild(rootElement); // Start with the block order. All the executions flow from this record. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(blotterId); if (blotterRow != null) { // The block order id is occationally useful info at the root element. XmlAttribute blotterIdAttribute = this.CreateAttribute("BlotterId"); rootElement.Attributes.Append(blotterIdAttribute); blotterIdAttribute.Value = blotterRow.BlotterId.ToString(); this.WriteBlotter(blotterRow); } }
private bool IsChildBlotter(ClientMarketData.BlotterRow parentBlotter, int blotterId) { if (parentBlotter.BlotterId == blotterId) { return(true); } ClientMarketData.ObjectRow parentObject = parentBlotter.ObjectRow; foreach (ClientMarketData.ObjectTreeRow objectTreeRow in parentObject.GetObjectTreeRowsByObjectObjectTreeParentId()) { foreach (ClientMarketData.BlotterRow childBlotter in objectTreeRow.ObjectRowByObjectObjectTreeChildId.GetBlotterRows()) { if (IsChildBlotter(childBlotter, this.blotter.BlotterId)) { return(true); } } } return(false); }
public Blotter(int objectId) : base(objectId) { // Initialize the object ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(objectId); if (!(this.IsWorkingOrderStylesheetIdNull = blotterRow.IsWorkingOrderStylesheetIdNull())) { this.WorkingOrderStylesheetId = blotterRow.WorkingOrderStylesheetId; } if (!(this.IsDestinationOrderStylesheetIdNull = blotterRow.IsDestinationOrderStylesheetIdNull())) { this.DestinationOrderStylesheetId = blotterRow.DestinationOrderStylesheetId; } if (!(this.IsMatchesStylesheetIdNull = blotterRow.IsMatchStylesheetIdNull())) { this.MatchesStylesheetId = blotterRow.MatchStylesheetId; } if (!(this.IsAdvertisementStylesheetIdNull = blotterRow.IsAdvertisementStylesheetIdNull())) { this.AdvertisementStylesheetId = blotterRow.AdvertisementStylesheetId; } }
private void WriteBlotter(ClientMarketData.BlotterRow blotterRow) { foreach (ClientMarketData.BlockOrderRow blockOrderRow in blotterRow.GetBlockOrderRows()) { // Inhibit displaying blocks with no executions. if (blockOrderRow.GetExecutionRows().Length > 0) { XmlElement blockOrdersElement = this.CreateBlockOrderElement(blockOrderRow); this.DocumentElement.AppendChild(blockOrdersElement); // These structures are used to group executions by broker. ArrayList brokerList = new ArrayList(); Hashtable brokerTable = new Hashtable(); // We are going to run through all the executions posted against the block order and construct a // hierarchical structure of brokers. Since they aren't arranged that way in the data model, we need to // scan the whole table looking for distinct brokers. foreach (ClientMarketData.ExecutionRow executionRow in blockOrderRow.GetExecutionRows()) { // See if we've run across this broker yet. If we haven't, we'll create a list that can hold all the // executions associated with a distinct broker. ArrayList executionsList = (ArrayList)brokerTable[executionRow.BrokerId]; if (executionsList == null) { brokerList.Add(executionRow.BrokerRow); executionsList = new ArrayList(); brokerTable[executionRow.BrokerId] = executionsList; } // Add this execution to the ones made to a particular broker, no matter what order it was entered // into the system. This will allow us to display the placments grouped by broker if we decide. int index; for (index = 0; index < executionsList.Count; index++) { if (((ClientMarketData.ExecutionRow)executionsList[index]).CreatedTime > executionRow.CreatedTime) { executionsList.Insert(index, executionRow); break; } } // If the row wasn't sorted into the array above, it's added to the end of the list here. if (index == executionsList.Count) { executionsList.Add(executionRow); } } // At this point, we have a hierarchy of distinct brokers and the executions made to those brokers. Go through the // structure and create the DOM. foreach (ClientMarketData.BrokerRow brokerRow in brokerList) { // Create a record for the broker. XmlElement brokersElement = this.CreateBrokersElement(brokerRow); blockOrdersElement.AppendChild(brokersElement); // Add all of the executions as children of the broker. foreach (ClientMarketData.ExecutionRow executionRow in (ArrayList)brokerTable[brokerRow.BrokerId]) { brokersElement.AppendChild(this.CreateExecutionElement(executionRow)); } } } } foreach (ClientMarketData.ObjectTreeRow objectTreeRow in blotterRow.ObjectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId()) { foreach (ClientMarketData.BlotterRow childBlotterRow in objectTreeRow.ObjectRowByFKObjectObjectTreeChildId.GetBlotterRows()) { this.WriteBlotter(childBlotterRow); } } }
/// <summary> /// Creates an displays an execution report. /// </summary> /// <param name="workingOrderId">The block order of the executions.</param> /// <param name="execution">Optional temporary execution.</param> protected override void DrawDocumentCommand(object parameter) { // Extract the command arguments. Blotter blotter = (Blotter)parameter; try { // Lock all the tables that we'll reference while building a destinationOrder document. System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BrokerLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait); // Make sure the block order still exists. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null && this.blotter.BlotterId != 0) { throw new ArgumentException("The block order has been deleted.", this.blotter.BlotterId.ToString()); } // Create the execution document. AdvertisementDocument ticketDocument = new AdvertisementDocument(blotter.BlotterId); #if DEBUGXML // We need to make sure that an error writing the debug file doesn't disturb the debug session. try { // Dump the DOM to a file. This is very useful when debugging. ticketDocument.Save("ticketDOM.xml"); } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } #endif // At this point, we've constructed a string that is compatible with the XML format of the spreadsheet // control. We can invoke the foreground thread to move the data into the control. this.XmlDocument = ticketDocument; } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the locks if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld) { ClientMarketData.WorkingOrderLock.ReleaseReaderLock(); } if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.BrokerLock.IsReaderLockHeld) { ClientMarketData.BrokerLock.ReleaseReaderLock(); } if (ClientMarketData.ExecutionLock.IsReaderLockHeld) { ClientMarketData.ExecutionLock.ReleaseReaderLock(); } if (ClientMarketData.UserLock.IsReaderLockHeld) { ClientMarketData.UserLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld) { ClientMarketData.ObjectTreeLock.ReleaseReaderLock(); } if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld) { ClientMarketData.DestinationOrderLock.ReleaseReaderLock(); } if (ClientMarketData.PriceTypeLock.IsReaderLockHeld) { ClientMarketData.PriceTypeLock.ReleaseReaderLock(); } if (ClientMarketData.SecurityLock.IsReaderLockHeld) { ClientMarketData.SecurityLock.ReleaseReaderLock(); } if (ClientMarketData.TimeInForceLock.IsReaderLockHeld) { ClientMarketData.TimeInForceLock.ReleaseReaderLock(); } if (ClientMarketData.OrderTypeLock.IsReaderLockHeld) { ClientMarketData.OrderTypeLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } }
/// <summary> /// Opens the Advertisement Viewer. /// </summary> protected void OpenCommand(params object[] parameters) { this.blotter = (Blotter)parameters[0]; try { // Lock the tables System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BrokerLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait); // Install the event handlers. The ClientMarketData component will advise us when the data has changed. ClientMarketData.Blotter.BlotterRowChanged += new ClientMarketData.BlotterRowChangeEventHandler(this.BlotterRowChangeEvent); ClientMarketData.Blotter.BlotterRowDeleted += new ClientMarketData.BlotterRowChangeEventHandler(this.BlotterRowChangeEvent); ClientMarketData.Broker.BrokerRowChanged += new ClientMarketData.BrokerRowChangeEventHandler(this.BrokerRowChangeEvent); ClientMarketData.Broker.BrokerRowDeleted += new ClientMarketData.BrokerRowChangeEventHandler(this.BrokerRowChangeEvent); ClientMarketData.Execution.ExecutionRowChanged += new ClientMarketData.ExecutionRowChangeEventHandler(this.ExecutionRowChangeEvent); ClientMarketData.Execution.ExecutionRowDeleted += new ClientMarketData.ExecutionRowChangeEventHandler(this.ExecutionRowChangeEvent); ClientMarketData.Stylesheet.StylesheetRowChanged += new ClientMarketData.StylesheetRowChangeEventHandler(this.StylesheetRowChangeEvent); ClientMarketData.Stylesheet.StylesheetRowDeleted += new ClientMarketData.StylesheetRowChangeEventHandler(this.StylesheetRowChangeEvent); ClientMarketData.EndMerge += new EventHandler(this.EndMerge); // Find the block order and extract the securty level data if it exists. This security level data is // needed to calculate the trade and settlement dates and other defaults for the executions. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null) { throw new Exception(String.Format("Blotter {0} has been deleted", this.blotter.BlotterId)); } // See if a stylesheet has been associated with the blotter. ClientMarketData.StylesheetRow stylesheetRow = blotterRow.IsAdvertisementStylesheetIdNull() ? null : ClientMarketData.Stylesheet.FindByStylesheetId(blotterRow.AdvertisementStylesheetId); if (stylesheetRow == null) { throw new Exception(String.Format("Blotter {0} has no Advertisement stylesheet", this.blotter.BlotterId)); } // As an optimization, don't reload the stylesheet if the prevous document used the same stylesheet. This // will save a few hundred milliseconds when scrolling through similar documents. if (this.stylesheetId != stylesheetRow.StylesheetId) { // Keep track of the stylesheet id in case it is changed while we're viewing it. The event handler // will use this id to determine if an incoming stylesheet will trigger a refresh of the document. this.stylesheetId = stylesheetRow.StylesheetId; } } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the table locks. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.BrokerLock.IsReaderLockHeld) { ClientMarketData.BrokerLock.ReleaseReaderLock(); } if (ClientMarketData.ExecutionLock.IsReaderLockHeld) { ClientMarketData.ExecutionLock.ReleaseReaderLock(); } if (ClientMarketData.StylesheetLock.IsReaderLockHeld) { ClientMarketData.StylesheetLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } }
private void WriteBlotter(ClientMarketData.BlotterRow blotterRow) { }