예제 #1
0
        /// <summary>
        /// Initialize the data used in this application.
        /// </summary>
        private void InitializeData(object parameter)
        {
            string           title            = string.Empty;
            string           symbol           = string.Empty;
            string           name             = string.Empty;
            Bitmap           logo             = null;
            decimal          leavesQuantity   = 0.0m;
            decimal          minimumQuantity  = 0.0m;
            NegotiationState negotiationState = NegotiationState.None;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(this.matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

                symbol          = securityRow.Symbol;
                name            = securityRow.ObjectRow.Name;
                minimumQuantity = securityRow.MinimumQuantity;
                if (!securityRow.IsLogoNull())
                {
                    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo));
                    logo = new Bitmap(memoryStream);
                }
                title          = string.Format("{0} of {1}", orderTypeRow.Description, symbol);
                leavesQuantity = workingOrderRow.SubmittedQuantity;
                foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                {
                    foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                    {
                        leavesQuantity -= executionRow.ExecutionQuantity;
                    }
                }
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            Invoke(new SetDialogAttributesDelegate(SetDialogAttributes), new object[] { title, symbol, name, logo, leavesQuantity, negotiationState });
        }
예제 #2
0
        /// <summary>
        /// Creates an XML Element representing a placment in the order document.
        /// </summary>
        /// <param name="xmlDocument">The destination XML document.</param>
        /// <param name="orderRow">A order record.</param>
        public LocalOrderElement(XmlDocument xmlDocument, LocalOrderSet.OrderRow orderRow) :
            base("LocalOrder", xmlDocument)
        {
            // Add the attributes of a order to this record.
            AddAttribute("OrderId", orderRow.OrderId.ToString());

            // Account field
            if (!orderRow.IsAccountIdNull())
            {
                AddAttribute("AccountId", orderRow.AccountId.ToString());

                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(orderRow.AccountId);
                if (accountRow != null)
                {
                    AddAttribute("AccountId", accountRow.AccountId.ToString());
                    AddAttribute("AccountName", accountRow.ObjectRow.Name);
                    AddAttribute("AccountMnemonic", accountRow.Mnemonic);
                }
            }

            // Security field
            if (!orderRow.IsSecurityIdNull())
            {
                AddAttribute("SecurityId", orderRow.SecurityId.ToString());

                ClientMarketData.SecurityRow securityRow = ClientMarketData.Security.FindBySecurityId(orderRow.SecurityId);
                if (securityRow != null)
                {
                    AddAttribute("SecurityId", securityRow.SecurityId.ToString());
                    AddAttribute("SecurityName", securityRow.ObjectRow.Name);
                    AddAttribute("SecuritySymbol", securityRow.Symbol);
                }
            }

            // Broker field
            if (!orderRow.IsBrokerIdNull())
            {
                AddAttribute("BrokerId", orderRow.BrokerId.ToString());

                ClientMarketData.BrokerRow brokerRow = ClientMarketData.Broker.FindByBrokerId(orderRow.BrokerId);
                if (brokerRow != null)
                {
                    AddAttribute("BrokerId", brokerRow.BrokerId.ToString());
                    AddAttribute("BrokerName", brokerRow.ObjectRow.Name);
                    AddAttribute("BrokerSymbol", brokerRow.Symbol);
                    if (!brokerRow.IsPhoneNull())
                    {
                        AddAttribute("BrokerPhone", brokerRow.Phone);
                    }
                }
            }

            // TransactionType field
            if (!orderRow.IsTransactionTypeCodeNull())
            {
                AddAttribute("TransactionTypeCode", orderRow.TransactionTypeCode.ToString());

                ClientMarketData.TransactionTypeRow transactionTypeRow = ClientMarketData.TransactionType.FindByTransactionTypeCode(orderRow.TransactionTypeCode);
                if (transactionTypeRow != null)
                {
                    AddAttribute("TransactionTypeMnemonic", transactionTypeRow.Mnemonic);
                }
            }

            // TimeInForce field
            if (!orderRow.IsTimeInForceCodeNull())
            {
                AddAttribute("TimeInForceCode", orderRow.TimeInForceCode.ToString());

                ClientMarketData.TimeInForceRow timeInForceRow = ClientMarketData.TimeInForce.FindByTimeInForceCode(orderRow.TimeInForceCode);
                if (timeInForceRow != null)
                {
                    AddAttribute("TimeInForceMnemonic", timeInForceRow.Mnemonic);
                }
            }

            // OrderType field
            if (!orderRow.IsOrderTypeCodeNull())
            {
                AddAttribute("OrderTypeCode", orderRow.OrderTypeCode.ToString());

                ClientMarketData.OrderTypeRow orderTypeRow = ClientMarketData.OrderType.FindByOrderTypeCode(orderRow.OrderTypeCode);
                if (orderTypeRow != null)
                {
                    AddAttribute("OrderTypeMnemonic", orderTypeRow.Mnemonic);
                }
            }

            if (!orderRow.IsQuantityNull())
            {
                AddAttribute("Quantity", orderRow.Quantity.ToString());
            }
            if (!orderRow.IsPrice1Null())
            {
                AddAttribute("Price1", orderRow.Price1.ToString());
            }
            if (!orderRow.IsPrice2Null())
            {
                AddAttribute("Price2", orderRow.Price2.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// Creates an XML Element representing a placment in the placement document.
        /// </summary>
        /// <param name="xmlDocument">The destination XML document.</param>
        /// <param name="placementRow">A placement record.</param>
        public PlacementElement(XmlDocument xmlDocument, PlacementSet.PlacementRow placementRow) :
            base("Placement", xmlDocument)
        {
            // This is the primary identifier for the record.
            AddAttribute("PlacementId", placementRow.LocalPlacementId.ToString());

            // Broker field
            if (!placementRow.IsBrokerIdNull())
            {
                ClientMarketData.BrokerRow brokerRow = ClientMarketData.Broker.FindByBrokerId(placementRow.BrokerId);
                if (brokerRow != null)
                {
                    AddAttribute("BrokerId", brokerRow.BrokerId.ToString());
                    AddAttribute("BrokerName", brokerRow.ObjectRow.Name);
                    AddAttribute("BrokerSymbol", brokerRow.Symbol);
                }
            }

            // TimeInForce field
            if (!placementRow.IsTimeInForceCodeNull())
            {
                ClientMarketData.TimeInForceRow timeInForceRow =
                    ClientMarketData.TimeInForce.FindByTimeInForceCode(placementRow.TimeInForceCode);
                if (timeInForceRow != null)
                {
                    AddAttribute("TimeInForceCode", placementRow.TimeInForceCode.ToString());
                    AddAttribute("TimeInForceMnemonic", timeInForceRow.Mnemonic);
                }
            }

            // OrderType field
            if (!placementRow.IsOrderTypeCodeNull())
            {
                ClientMarketData.OrderTypeRow orderTypeRow =
                    ClientMarketData.OrderType.FindByOrderTypeCode(placementRow.OrderTypeCode);
                if (orderTypeRow != null)
                {
                    AddAttribute("OrderTypeCode", placementRow.OrderTypeCode.ToString());
                    AddAttribute("OrderTypeMnemonic", orderTypeRow.Mnemonic);
                }
            }

            // Quantity
            if (!placementRow.IsQuantityNull())
            {
                AddAttribute("Quantity", placementRow.Quantity.ToString());
            }

            // Price 1
            if (!placementRow.IsPrice1Null())
            {
                AddAttribute("Price1", placementRow.Price1.ToString());
            }

            // Price 2
            if (!placementRow.IsPrice2Null())
            {
                AddAttribute("Price2", placementRow.Price2.ToString());
            }

            // Created Time
            if (!placementRow.IsCreatedTimeNull())
            {
                AddAttribute("CreatedTime", placementRow.CreatedTime.ToString("s"));
            }

            // Created Login
            if (!placementRow.IsCreatedLoginIdNull())
            {
                ClientMarketData.LoginRow createdLoginRow = ClientMarketData.Login.FindByLoginId(placementRow.CreatedLoginId);
                if (createdLoginRow != null)
                {
                    AddAttribute("CreatedLoginId", createdLoginRow.LoginId.ToString());
                    AddAttribute("CreatedLoginName", createdLoginRow.ObjectRow.Name);
                }
            }

            // Modified Time
            if (!placementRow.IsModifiedTimeNull())
            {
                AddAttribute("ModifiedTime", placementRow.ModifiedTime.ToString("s"));
            }

            // Modified Login
            if (!placementRow.IsModifiedLoginIdNull())
            {
                ClientMarketData.LoginRow modifiedLoginRow = ClientMarketData.Login.FindByLoginId(placementRow.ModifiedLoginId);
                if (modifiedLoginRow != null)
                {
                    AddAttribute("ModifiedLoginId", modifiedLoginRow.LoginId.ToString());
                    AddAttribute("ModifiedLoginName", modifiedLoginRow.ObjectRow.Name);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Method called to retrieve the securityId for the security selected in the match viewere.
        /// </summary>
        /// <param name="parameter"></param>
        private void InitializeData(object parameter)
        {
            int id = Int32.MinValue;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(this.matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

                if (securityRow != null)
                {
                    id = securityRow.SecurityId;
                }
            }
            catch (Exception e)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", e.Message, e.StackTrace);
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            if (id != Int32.MinValue)
            {
                this.Open(id);
            }
        }
예제 #5
0
파일: Order.cs 프로젝트: DonaldAirey/quasar
        /// <summary>
        /// Creates a denormalized order record from a local record.
        /// </summary>
        /// <param name="localOrder">A local order record.</param>
        /// <returns>A order record that is independant of the global data set for all the anscillary data.</returns>
        public static OrderSet.OrderRow Create(LocalOrderSet.OrderRow localOrder)
        {
            // Create a new, empty order record.
            OrderSet.OrderRow orderRow = orderSet.Order.NewOrderRow();

            // This new record is a copy of a local record and uses the local system of identifiers.
            orderRow.IsLocal = true;

            // Copy each field that has an analog in the local record set into the new record.
            foreach (DataColumn dataColumn in localOrder.Table.Columns)
            {
                orderRow[dataColumn.ColumnName] = localOrder[dataColumn];
            }

            // AccountId cross-referenced data is filled in here.
            if (!localOrder.IsAccountIdNull())
            {
                ClientMarketData.AccountRow accountRow = ClientMarketData.Account.FindByAccountId(orderRow.AccountId);
                if (accountRow != null)
                {
                    orderRow.AccountMnemonic = accountRow.Mnemonic;
                    orderRow.AccountName     = accountRow.ObjectRow.Name;
                }
            }

            // SecurityId cross-referenced data is filled in here.
            if (!localOrder.IsSecurityIdNull())
            {
                ClientMarketData.SecurityRow securityRow = ClientMarketData.Security.FindBySecurityId(orderRow.SecurityId);
                if (securityRow != null)
                {
                    orderRow.SecuritySymbol = securityRow.Symbol;
                    orderRow.SecurityName   = securityRow.ObjectRow.Name;
                }
            }

            // CurrencyId cross-referenced data is filled in here.
            if (!localOrder.IsSettlementIdNull())
            {
                ClientMarketData.CurrencyRow currencyRow = ClientMarketData.Currency.FindByCurrencyId(orderRow.SettlementId);
                if (currencyRow != null)
                {
                    orderRow.SettlementSymbol = currencyRow.SecurityRow.Symbol;
                    orderRow.SettlementName   = currencyRow.SecurityRow.ObjectRow.Name;
                }
            }

            // BrokerId cross-referenced data is filled in here.
            if (!localOrder.IsBrokerIdNull())
            {
                ClientMarketData.BrokerRow brokerRow = ClientMarketData.Broker.FindByBrokerId(orderRow.BrokerId);
                if (brokerRow != null)
                {
                    orderRow.BrokerSymbol = brokerRow.Symbol;
                    orderRow.BrokerName   = brokerRow.ObjectRow.Name;
                }
            }

            // TransactionType cross-referenced data is filled in here.
            if (!localOrder.IsTransactionTypeCodeNull())
            {
                ClientMarketData.TransactionTypeRow transactionTypeRow = ClientMarketData.TransactionType.FindByTransactionTypeCode(orderRow.TransactionTypeCode);
                if (transactionTypeRow != null)
                {
                    orderRow.TransactionTypeMnemonic = transactionTypeRow.Mnemonic;
                }
            }

            // TimeInForce cross-referenced data is filled in here.
            if (!localOrder.IsTimeInForceCodeNull())
            {
                ClientMarketData.TimeInForceRow timeInForceRow = ClientMarketData.TimeInForce.FindByTimeInForceCode(orderRow.TimeInForceCode);
                if (timeInForceRow != null)
                {
                    orderRow.TimeInForceMnemonic = timeInForceRow.Mnemonic;
                }
            }

            // TimeInForce cross-referenced data is filled in here.
            if (!localOrder.IsOrderTypeCodeNull())
            {
                ClientMarketData.OrderTypeRow orderTypeRow = ClientMarketData.OrderType.FindByOrderTypeCode(orderRow.OrderTypeCode);
                if (orderTypeRow != null)
                {
                    orderRow.OrderTypeMnemonic = orderTypeRow.Mnemonic;
                }
            }

            // This is a complete record of the order, including the referenced data.
            return(orderRow);
        }
예제 #6
0
        /// <summary>
        /// Notifies the user that a match opportunity exists.
        /// </summary>
        /// <param name="parameter">The thread initialization parameters.</param>
        private void NotifyUser(object parameter)
        {
            // Extract the thread parameters.
            int matchId = (int)parameter;

            // The symbol, title and the bitmap for the corporate logo will be retrieved from the data model in the code below.
            // They will be used to initialize the pop-up dialog after the locks on the data model have been released.
            string symbol = string.Empty;
            string title  = string.Empty;
            Bitmap logo   = null;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // The match record, working order, order type and security records are used to construct the title, symbol and
                // logo used by the notification window.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

                // Get the security symbol.
                symbol = securityRow.Symbol;

                // Create a logo bitmap.
                if (!securityRow.IsLogoNull())
                {
                    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo));
                    logo = new Bitmap(memoryStream);
                }

                // Construct the title for the notification window.
                title = string.Format("{0} of {1}", orderTypeRow.Description, symbol);
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // The notification window looks and acts like the Microsoft Instant Messaging window.  It will pop up in the lower
            // right hand corner of the screen with a title, the corporate logo and a chance to either accept or decline the
            // opportunity for a match.
            NotificationWindow notificationWindow = new NotificationWindow();

            notificationWindow.MatchId        = matchId;
            notificationWindow.Symbol         = symbol;
            notificationWindow.Message        = title;
            notificationWindow.CompanyLogo    = logo;
            notificationWindow.Accept        += new MatchEventHandler(AcceptNegotiation);
            notificationWindow.Decline       += new MatchEventHandler(DeclineNegotiation);
            notificationWindow.ChangeOptions += new EventHandler(ChangeOptions);
            notificationWindow.Show();
        }