Пример #1
0
        /// <summary>Archives a Price record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int securityId)
        {
            // Accessor for the Price Table.
            ServerMarketData.PriceDataTable priceTable = ServerMarketData.Price;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.PriceRow priceRow = priceTable.FindBySecurityId(securityId);
            if ((priceRow == null))
            {
                throw new Exception(string.Format("The Price table does not have an element identified by {0}", securityId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((priceRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < priceRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = priceRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            priceRow[priceTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(priceRow);
            priceRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Price\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #2
0
 /// <summary>
 /// Authorizes a WorkingOrder to be returned to the client.
 /// </summary>
 /// <param name="userDataRow">Identifies the current user.</param>
 /// <param name="workingOrderDataRow">The record to be tested for authorization.</param>
 /// <returns>true if the record belongs in the user's hierarchy.</returns>
 public static bool FilterWorkingOrder(DataRow userDataRow, DataRow workingOrderDataRow)
 {
     // This will test the record and return true if it belongs to the hierarchies this user is authorized to view.  False
     // if the record should not be included in the user's data model.
     ServerMarketData.UserRow         userRow         = (ServerMarketData.UserRow)userDataRow;
     ServerMarketData.WorkingOrderRow workingOrderRow = (ServerMarketData.WorkingOrderRow)workingOrderDataRow;
     return(Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow,
                                   workingOrderRow.BlotterRow.ObjectRow));
 }
Пример #3
0
        /// <summary>Archives a Status record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="statusCode">The value for the StatusCode column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Archive(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int statusCode)
        {
            // Accessor for the Status Table.
            ServerMarketData.StatusDataTable statusTable = ServerMarketData.Status;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.StatusRow statusRow = statusTable.FindByStatusCode(statusCode);
            if ((statusRow == null))
            {
                throw new Exception(string.Format("The Status table does not have an element identified by {0}", statusCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((statusRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < statusRow.GetDestinationOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.DestinationOrderRow childDestinationOrderRow = statusRow.GetDestinationOrderRows()[index];
                DestinationOrder.Archive(adoTransaction, sqlTransaction, childDestinationOrderRow.RowVersion, childDestinationOrderRow.DestinationOrderId);
            }
            for (int index = 0; (index < statusRow.GetMatchRows().Length); index = (index + 1))
            {
                ServerMarketData.MatchRow childMatchRow = statusRow.GetMatchRows()[index];
                Match.Archive(adoTransaction, sqlTransaction, childMatchRow.RowVersion, childMatchRow.MatchId);
            }
            for (int index = 0; (index < statusRow.GetNegotiationRows().Length); index = (index + 1))
            {
                ServerMarketData.NegotiationRow childNegotiationRow = statusRow.GetNegotiationRows()[index];
                Negotiation.Archive(adoTransaction, sqlTransaction, childNegotiationRow.RowVersion, childNegotiationRow.NegotiationId);
            }
            for (int index = 0; (index < statusRow.GetSourceOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = statusRow.GetSourceOrderRows()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < statusRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = statusRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            statusRow[statusTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(statusRow);
            statusRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Status\" set \"IsArchived\" = 1 where \"StatusCode\"=@statusCode");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode));
            sqlCommand.ExecuteNonQuery();
        }
Пример #4
0
        /// <summary>
        /// Add a match of two orders to begin the negociation process.
        /// </summary>
        /// <param name="workingOrderId">The WorkingOrderId of the first order.</param>
        /// <param name="contraOrderId">The WorkingOrderId of the second order.</param>
        private static void SetWorkingOrderStatus(object[] key, params object[] parameters)
        {
            int workingOrderId = (int)key[0];
            int statusCode     = (int)parameters[0];

            // Create a transaction for adding the Match.
            Transaction transaction = new Transaction(Core.WorkingOrder.PersistentStore);

            try
            {
                // These tables are needed for the transaction.
                transaction.AdoTransaction.LockRequests.AddWriterLock(ServerMarketData.DestinationOrderLock);
                transaction.AdoTransaction.LockRequests.AddWriterLock(ServerMarketData.ExecutionLock);
                transaction.AdoTransaction.LockRequests.AddReaderLock(ServerMarketData.MatchLock);
                transaction.AdoTransaction.LockRequests.AddWriterLock(ServerMarketData.SourceOrderLock);
                transaction.AdoTransaction.LockRequests.AddWriterLock(ServerMarketData.WorkingOrderLock);

                // Start the Transaction.
                transaction.Begin();

                // The SqlInfo contains information about the SQL transaction which must be passed on to the method during a
                // transaction.  There is only one ADO.NET store, but there can be one or more persistent stores.  In this case,
                // the ‘Core.Match’ class specifies where to store the data permanently.
                SqlInfo sqlInfo = transaction.SqlInfoList[Core.WorkingOrder.PersistentStore];

                // Add the match of the primary order to the contra order.
                ServerMarketData.WorkingOrderRow workingOrderRow = ServerMarketData.WorkingOrder.FindByWorkingOrderId(workingOrderId);
                if (workingOrderRow != null)
                {
                    long   rowVersion    = workingOrderRow.RowVersion;
                    object submittedTime = statusCode == Status.Submitted ? (object)DateTime.Now : (object)DBNull.Value;
                    Core.WorkingOrder.Update(transaction.AdoTransaction, sqlInfo.Transaction, ref rowVersion, null, null, null, null,
                                             null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, statusCode,
                                             null, null, null, null, submittedTime, null, null, null, workingOrderId);
                }

                // These two methods can now be committed to the ADO.NET and SQL data stores.  They will be added as a unit or
                // rolled back as a unit.
                transaction.Commit();
            }
            catch (Exception exception)
            {
                // Log the error.
                EventLog.Error("{0}: {1}", exception.Message, exception.StackTrace);

                // Any errors will cause the transaction to be rolled back.
                transaction.Rollback();
            }
            finally
            {
                // Whether successful or not, this will close out the resources for the transaction and end it.
                transaction.EndTransaction();
            }
        }
Пример #5
0
        /// <summary>Deletes a TimeInForce record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="RowVersion">The version number of this row.</param>
        /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        public static void Delete(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int timeInForceCode)
        {
            // Accessor for the TimeInForce Table.
            ServerMarketData.TimeInForceDataTable timeInForceTable = ServerMarketData.TimeInForce;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.TimeInForceRow timeInForceRow = timeInForceTable.FindByTimeInForceCode(timeInForceCode);
            if ((timeInForceRow == null))
            {
                throw new Exception(string.Format("The TimeInForce table does not have an element identified by {0}", timeInForceCode));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((timeInForceRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Delete the child records.
            for (int index = 0; (index < timeInForceRow.GetDestinationOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.DestinationOrderRow childDestinationOrderRow = timeInForceRow.GetDestinationOrderRows()[index];
                DestinationOrder.Delete(adoTransaction, sqlTransaction, childDestinationOrderRow.RowVersion, childDestinationOrderRow.DestinationOrderId);
            }
            for (int index = 0; (index < timeInForceRow.GetSourceOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = timeInForceRow.GetSourceOrderRows()[index];
                SourceOrder.Delete(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < timeInForceRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = timeInForceRow.GetWorkingOrderRows()[index];
                WorkingOrder.Delete(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            timeInForceRow[timeInForceTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(timeInForceRow);
            timeInForceRow.Delete();
            // Delete the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"TimeInForce\" set \"IsDeleted\" = 1 where \"TimeInForceCode\"=@timeInForceCode" +
                                                   "");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode));
            sqlCommand.ExecuteNonQuery();
        }
Пример #6
0
        /// <summary>ArchiveChildrens a Blotter record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">the version number of this row.</param>
        /// <param name="blotterId">The value for the BlotterId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int blotterId)
        {
            // Accessor for the Blotter Table.
            ServerMarketData.BlotterDataTable blotterTable = ServerMarketData.Blotter;
            // This record can be used to iterate through all the children.
            ServerMarketData.BlotterRow blotterRow = blotterTable.FindByBlotterId(blotterId);
            // Archive the child records.
            for (int index = 0; (index < blotterRow.GetBranchRows().Length); index = (index + 1))
            {
                ServerMarketData.BranchRow childBranchRow = blotterRow.GetBranchRows()[index];
                Branch.ArchiveChildren(adoTransaction, sqlTransaction, childBranchRow.RowVersion, childBranchRow.BranchId);
            }
            for (int index = 0; (index < blotterRow.GetSourceRows().Length); index = (index + 1))
            {
                ServerMarketData.SourceRow childSourceRow = blotterRow.GetSourceRows()[index];
                Source.ArchiveChildren(adoTransaction, sqlTransaction, childSourceRow.RowVersion, childSourceRow.SourceId);
            }
            for (int index = 0; (index < blotterRow.GetTraderRows().Length); index = (index + 1))
            {
                ServerMarketData.TraderRow childTraderRow = blotterRow.GetTraderRows()[index];
                Trader.ArchiveChildren(adoTransaction, sqlTransaction, childTraderRow.RowVersion, childTraderRow.TraderId);
            }
            for (int index = 0; (index < blotterRow.GetWorkingOrderRows().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = blotterRow.GetWorkingOrderRows()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            blotterRow[blotterTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(blotterRow);
            blotterRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Blotter\" set \"IsArchived\" = 1 where \"BlotterId\"=@blotterId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@blotterId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, blotterId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #7
0
 /// <summary>Archives a WorkingOrder record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Archive(ParameterList parameters)
 {
     // Accessor for the WorkingOrder Table.
     ServerMarketData.WorkingOrderDataTable workingOrderTable = ServerMarketData.WorkingOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalWorkingOrderId = parameters["workingOrderId"];
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Find the internal identifier using the primar key elements.
     // identifier is used to determine if a record exists with the same key.
     int workingOrderId = WorkingOrder.FindRequiredKey(configurationId, "workingOrderId", externalWorkingOrderId);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerMarketData.WorkingOrderRow workingOrderRow = workingOrderTable.FindByWorkingOrderId(workingOrderId);
     rowVersion = ((long)(workingOrderRow[workingOrderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.WorkingOrder.Archive(adoTransaction, sqlTransaction, rowVersion, workingOrderId);
 }
Пример #8
0
        /// <summary>Updates a WorkingOrder record using Metadata Parameters.</summary>
        /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
        public static void UpdateFile(ParameterList parameters)
        {
            // Accessor for the WorkingOrder Table.
            ServerMarketData.WorkingOrderDataTable workingOrderTable = ServerMarketData.WorkingOrder;

            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction             = parameters["adoTransaction"];
            SqlTransaction sqlTransaction             = parameters["sqlTransaction"];
            object         configurationId            = parameters["configurationId"].Value;
            object         externalBlotterId          = parameters["blotterId"].Value;
            string         externalWorkingOrderId     = ((string)(parameters["workingOrderId"]));
            object         externalDestinationId      = parameters["destinationId"].Value;
            object         externalOrderTypeCode      = parameters["orderTypeCode"].Value;
            object         externalPriceTypeCode      = parameters["priceTypeCode"].Value;
            object         externalSecurityId         = parameters["securityId"].Value;
            object         externalSubmissionTypeCode = parameters["submissionTypeCode"].Value;
            object         externalSettlementId       = parameters["settlementId"].Value;
            object         submittedQuantity          = parameters["submittedQuantity"].Value;
            object         submittedTime           = parameters["submittedTime"].Value;
            object         externalTimeInForceCode = parameters["timeInForceCode"].Value;
            object         uploadedTime            = parameters["uploadedTime"].Value;

            // The row versioning is largely disabled for external operations.
            long rowVersion = long.MinValue;

            // Resolve External Identifiers
            object blotterId          = External.Blotter.FindOptionalKey(configurationId, "blotterId", externalBlotterId);
            object destinationId      = External.Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
            object orderTypeCode      = External.OrderType.FindOptionalKey(configurationId, "orderTypeCode", externalOrderTypeCode);
            object priceTypeCode      = External.PriceType.FindOptionalKey(configurationId, "priceTypeCode", externalPriceTypeCode);
            object securityId         = External.Security.FindOptionalKey(configurationId, "securityId", externalSecurityId);
            object settlementId       = External.Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
            object timeInForceCode    = External.TimeInForce.FindOptionalKey(configurationId, "timeInForceCode", externalTimeInForceCode);
            object submissionTypeCode = External.SubmissionType.FindOptionalKey(configurationId, "submissionTypeCode", externalSubmissionTypeCode);
            int    workingOrderId     = External.WorkingOrder.FindRequiredKey(configurationId, "workingOrderId", externalWorkingOrderId);

            // Convert the parameters into binary values.
            object isAgencyMatch = parameters["isAgencyMatch"] is MissingParameter ? (object)null :
                                   Convert.ToBoolean(parameters["isAgencyMatch"].Value);
            object isBrokerMatch = parameters["isBrokerMatch"] is MissingParameter ? (object)null :
                                   Convert.ToBoolean(parameters["isBrokerMatch"].Value);
            object isHedgeMatch = parameters["isHedgeMatch"] is MissingParameter ? (object)null :
                                  Convert.ToBoolean(parameters["isHedgeMatch"].Value);
            object isInstitutionMatch = parameters["isInstitutionMatch"] is MissingParameter ? (object)null :
                                        Convert.ToBoolean(parameters["isInstitutionMatch"].Value);
            object limitPrice = parameters["limitPrice"] is MissingParameter ? (object)null :
                                Convert.ToDecimal(parameters["limitPrice"].Value);
            object maximumVolatility = parameters["maximumVolatility"] is MissingParameter ? (object)null :
                                       Convert.ToDecimal(parameters["maximumVolatility"].Value);
            object startTime = parameters["startTime"] is MissingParameter ? (object)null :
                               Convert.ToDateTime(parameters["startTime"].Value);
            object stopPrice = parameters["stopPrice"] is MissingParameter ? (object)null :
                               Convert.ToDecimal(parameters["stopPrice"].Value);
            object stopTime = parameters["stopTime"] is MissingParameter ? (object)null :
                              Convert.ToDateTime(parameters["stopTime"].Value);
            object newsFreeTime = parameters["newsFreeTime"] is MissingParameter ? (object)null :
                                  Convert.ToInt32(parameters["newsFreeTime"].Value);

            // Defaults
            int      statusCode     = Status.New;
            int      modifiedUserId = ServerMarketData.UserId;
            DateTime modifiedTime   = DateTime.Now;
            DateTime timeReceived   = modifiedTime;

            // Provide a default for the submission type code.
            if (submissionTypeCode == null)
            {
                submissionTypeCode = SubmissionType.NeverMatch;
            }

            // While the optimistic concurrency checking is disabled for the external methods, the internal methods
            // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
            // will bypass the coused when the internal method is called.
            ServerMarketData.WorkingOrderRow workingOrderRow = workingOrderTable.FindByWorkingOrderId(workingOrderId);
            rowVersion = ((long)(workingOrderRow[workingOrderTable.RowVersionColumn]));

            // Call the internal method to complete the operation.
            MarkThree.Guardian.Core.WorkingOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, null, blotterId, null, null, destinationId,
                                                        null, isAgencyMatch, null, null, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice, maximumVolatility, newsFreeTime, modifiedUserId,
                                                        modifiedTime, orderTypeCode, priceTypeCode, securityId, settlementId, startTime, statusCode, stopPrice, stopTime, null,
                                                        submittedQuantity, submittedTime, timeInForceCode, null, uploadedTime, workingOrderId);

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
Пример #9
0
 /// <summary>Updates a WorkingOrder record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Update(ParameterList parameters)
 {
     // Accessor for the WorkingOrder Table.
     ServerMarketData.WorkingOrderDataTable workingOrderTable = ServerMarketData.WorkingOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object automaticQuantity = parameters["automaticQuantity"].Value;
     object externalBlotterId = parameters["blotterId"].Value;
     object createdTime = parameters["createdTime"].Value;
     object externalCreatedUserId = parameters["createdUserId"].Value;
     object externalDestinationId = parameters["destinationId"].Value;
     object isAgencyMatch = parameters["isAgencyMatch"].Value;
     object isAutomatic = parameters["isAutomatic"].Value;
     object isAwake = parameters["isAwake"].Value;
     object isBrokerMatch = parameters["isBrokerMatch"].Value;
     object isHedgeMatch = parameters["isHedgeMatch"].Value;
     object isInstitutionMatch = parameters["isInstitutionMatch"].Value;
     object limitPrice = parameters["limitPrice"].Value;
     object maximumVolatility = parameters["maximumVolatility"].Value;
     object modifiedTime = parameters["modifiedTime"].Value;
     object externalModifiedUserId = parameters["modifiedUserId"].Value;
     object newsFreeTime = parameters["newsFreeTime"].Value;
     object externalOrderTypeCode = parameters["orderTypeCode"].Value;
     object externalPriceTypeCode = parameters["priceTypeCode"].Value;
     object externalSecurityId = parameters["securityId"].Value;
     object externalSettlementId = parameters["settlementId"].Value;
     object startTime = parameters["startTime"].Value;
     object externalStatusCode = parameters["statusCode"].Value;
     object stopPrice = parameters["stopPrice"].Value;
     object stopTime = parameters["stopTime"].Value;
     object externalSubmissionTypeCode = parameters["submissionTypeCode"].Value;
     object submittedQuantity = parameters["submittedQuantity"].Value;
     object submittedTime = parameters["submittedTime"].Value;
     object externalTimeInForceCode = parameters["timeInForceCode"].Value;
     object externalTimerId = parameters["timerId"].Value;
     object uploadedTime = parameters["uploadedTime"].Value;
     string externalWorkingOrderId = ((string)(parameters["workingOrderId"]));
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     object blotterId = Blotter.FindOptionalKey(configurationId, "blotterId", externalBlotterId);
     object createdUserId = User.FindOptionalKey(configurationId, "createdUserId", externalCreatedUserId);
     object destinationId = Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
     object modifiedUserId = User.FindOptionalKey(configurationId, "modifiedUserId", externalModifiedUserId);
     object orderTypeCode = OrderType.FindOptionalKey(configurationId, "orderTypeCode", externalOrderTypeCode);
     object priceTypeCode = PriceType.FindOptionalKey(configurationId, "priceTypeCode", externalPriceTypeCode);
     object securityId = Security.FindOptionalKey(configurationId, "securityId", externalSecurityId);
     object settlementId = Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
     object statusCode = Status.FindOptionalKey(configurationId, "statusCode", externalStatusCode);
     object submissionTypeCode = SubmissionType.FindOptionalKey(configurationId, "submissionTypeCode", externalSubmissionTypeCode);
     object timeInForceCode = TimeInForce.FindOptionalKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     object timerId = Timer.FindOptionalKey(configurationId, "timerId", externalTimerId);
     int workingOrderId = WorkingOrder.FindRequiredKey(configurationId, "workingOrderId", externalWorkingOrderId);
     // While the optimistic concurrency checking is disabled for the external methods, the internal methods
     // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
     // will bypass the coused when the internal method is called.
     ServerMarketData.WorkingOrderRow workingOrderRow = workingOrderTable.FindByWorkingOrderId(workingOrderId);
     rowVersion = ((long)(workingOrderRow[workingOrderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.WorkingOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, automaticQuantity, blotterId, createdTime, createdUserId, destinationId, null, isAgencyMatch, isAutomatic, isAwake, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId, settlementId, startTime, statusCode, stopPrice, stopTime, submissionTypeCode, submittedQuantity, submittedTime, timeInForceCode, timerId, uploadedTime, workingOrderId);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Пример #10
0
 /// <summary>Loads a WorkingOrder record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public static void Load(ParameterList parameters)
 {
     // Accessor for the WorkingOrder Table.
     ServerMarketData.WorkingOrderDataTable workingOrderTable = ServerMarketData.WorkingOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object automaticQuantity = parameters["automaticQuantity"].Value;
     string externalBlotterId = parameters["blotterId"];
     System.DateTime createdTime = parameters["createdTime"];
     string externalCreatedUserId = parameters["createdUserId"];
     object externalDestinationId = parameters["destinationId"].Value;
     object externalId0 = parameters["externalId0"].Value;
     object isAgencyMatch = parameters["isAgencyMatch"].Value;
     object isAutomatic = parameters["isAutomatic"].Value;
     object isAwake = parameters["isAwake"].Value;
     object isBrokerMatch = parameters["isBrokerMatch"].Value;
     object isHedgeMatch = parameters["isHedgeMatch"].Value;
     object isInstitutionMatch = parameters["isInstitutionMatch"].Value;
     object limitPrice = parameters["limitPrice"].Value;
     object maximumVolatility = parameters["maximumVolatility"].Value;
     System.DateTime modifiedTime = parameters["modifiedTime"];
     string externalModifiedUserId = parameters["modifiedUserId"];
     object newsFreeTime = parameters["newsFreeTime"].Value;
     string externalOrderTypeCode = parameters["orderTypeCode"];
     string externalPriceTypeCode = parameters["priceTypeCode"];
     string externalSecurityId = parameters["securityId"];
     object externalSettlementId = parameters["settlementId"].Value;
     object startTime = parameters["startTime"].Value;
     string externalStatusCode = parameters["statusCode"];
     object stopPrice = parameters["stopPrice"].Value;
     object stopTime = parameters["stopTime"].Value;
     string externalSubmissionTypeCode = parameters["submissionTypeCode"];
     object submittedQuantity = parameters["submittedQuantity"].Value;
     object submittedTime = parameters["submittedTime"].Value;
     string externalTimeInForceCode = parameters["timeInForceCode"];
     object externalTimerId = parameters["timerId"].Value;
     object uploadedTime = parameters["uploadedTime"].Value;
     object externalWorkingOrderId = parameters["workingOrderId"].Value;
     // The row versioning is largely disabled for external operations.  The value is returned to the caller in the
     // event it's needed for operations within the batch.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     int blotterId = Blotter.FindRequiredKey(configurationId, "blotterId", externalBlotterId);
     int createdUserId = User.FindRequiredKey(configurationId, "createdUserId", externalCreatedUserId);
     object destinationId = Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
     int modifiedUserId = User.FindRequiredKey(configurationId, "modifiedUserId", externalModifiedUserId);
     int orderTypeCode = OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
     int priceTypeCode = PriceType.FindRequiredKey(configurationId, "priceTypeCode", externalPriceTypeCode);
     int securityId = Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
     object settlementId = Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
     int statusCode = Status.FindRequiredKey(configurationId, "statusCode", externalStatusCode);
     int submissionTypeCode = SubmissionType.FindRequiredKey(configurationId, "submissionTypeCode", externalSubmissionTypeCode);
     int timeInForceCode = TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     object timerId = Timer.FindOptionalKey(configurationId, "timerId", externalTimerId);
     int workingOrderId = WorkingOrder.FindKey(configurationId, "workingOrderId", externalWorkingOrderId);
     // The load operation will create a record if it doesn't exist, or update an existing record.  The external
     // identifier is used to determine if a record exists with the same key.
     if ((workingOrderId == int.MinValue))
     {
         // Populate the 'externalId' varaibles so that the external identifier can be used to find the row when an
         // external method is called with the same 'configurationId' parameter.
         int externalKeyIndex = WorkingOrder.GetExternalKeyIndex(configurationId, "workingOrderId");
         object[] externalIdArray = new object[1];
         externalIdArray[externalKeyIndex] = externalWorkingOrderId;
         externalId0 = externalIdArray[0];
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.WorkingOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, automaticQuantity, blotterId, createdTime, createdUserId, destinationId, externalId0, isAgencyMatch, isAutomatic, isAwake, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId, settlementId, startTime, statusCode, stopPrice, stopTime, submissionTypeCode, submittedQuantity, submittedTime, timeInForceCode, timerId, uploadedTime);
     }
     else
     {
         // While the optimistic concurrency checking is disabled for the external methods, the internal methods
         // still need to perform the check.  This ncurrency checking logic by finding the current row version to be
         // will bypass the coused when the internal method is called.
         ServerMarketData.WorkingOrderRow workingOrderRow = workingOrderTable.FindByWorkingOrderId(workingOrderId);
         rowVersion = ((long)(workingOrderRow[workingOrderTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.WorkingOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, automaticQuantity, blotterId, createdTime, createdUserId, destinationId, externalId0, isAgencyMatch, isAutomatic, isAwake, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId, settlementId, startTime, statusCode, stopPrice, stopTime, submissionTypeCode, submittedQuantity, submittedTime, timeInForceCode, timerId, uploadedTime, workingOrderId);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Пример #11
0
        /// <summary>ArchiveChildrens a Security record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">the version number of this row.</param>
        /// <param name="securityId">The value for the SecurityId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int securityId)
        {
            // Accessor for the Security Table.
            ServerMarketData.SecurityDataTable securityTable = ServerMarketData.Security;
            // This record can be used to iterate through all the children.
            ServerMarketData.SecurityRow securityRow = securityTable.FindBySecurityId(securityId);
            // Archive the child records.
            for (int index = 0; (index < securityRow.GetAccountBaseRows().Length); index = (index + 1))
            {
                ServerMarketData.AccountBaseRow childAccountBaseRow = securityRow.GetAccountBaseRows()[index];
                AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSecurityId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetAllocationRowsBySecurityAllocationSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = securityRow.GetAllocationRowsBySecurityAllocationSettlementId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < securityRow.GetCurrencyRows().Length); index = (index + 1))
            {
                ServerMarketData.CurrencyRow childCurrencyRow = securityRow.GetCurrencyRows()[index];
                Currency.ArchiveChildren(adoTransaction, sqlTransaction, childCurrencyRow.RowVersion, childCurrencyRow.CurrencyId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtDebtId().Length); index = (index + 1))
            {
                ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtDebtId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetDebtRowsBySecurityDebtSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.DebtRow childDebtRow = securityRow.GetDebtRowsBySecurityDebtSettlementId()[index];
                Debt.ArchiveChildren(adoTransaction, sqlTransaction, childDebtRow.RowVersion, childDebtRow.DebtId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquityEquityId().Length); index = (index + 1))
            {
                ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquityEquityId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetEquityRowsBySecurityEquitySettlementId().Length); index = (index + 1))
            {
                ServerMarketData.EquityRow childEquityRow = securityRow.GetEquityRowsBySecurityEquitySettlementId()[index];
                Equity.ArchiveChildren(adoTransaction, sqlTransaction, childEquityRow.RowVersion, childEquityRow.EquityId);
            }
            for (int index = 0; (index < securityRow.GetPositionRows().Length); index = (index + 1))
            {
                ServerMarketData.PositionRow childPositionRow = securityRow.GetPositionRows()[index];
                Position.Archive(adoTransaction, sqlTransaction, childPositionRow.RowVersion, childPositionRow.AccountId, childPositionRow.SecurityId, childPositionRow.PositionTypeCode);
            }
            for (int index = 0; (index < securityRow.GetPriceRows().Length); index = (index + 1))
            {
                ServerMarketData.PriceRow childPriceRow = securityRow.GetPriceRows()[index];
                Price.Archive(adoTransaction, sqlTransaction, childPriceRow.RowVersion, childPriceRow.SecurityId);
            }
            for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSecurityId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = securityRow.GetSourceOrderRowsBySecuritySourceOrderSettlementId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < securityRow.GetTaxLotRows().Length); index = (index + 1))
            {
                ServerMarketData.TaxLotRow childTaxLotRow = securityRow.GetTaxLotRows()[index];
                TaxLot.Archive(adoTransaction, sqlTransaction, childTaxLotRow.RowVersion, childTaxLotRow.TaxLotId);
            }
            for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSecurityId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            for (int index = 0; (index < securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = securityRow.GetWorkingOrderRowsBySecurityWorkingOrderSettlementId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            securityRow[securityTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(securityRow);
            securityRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"Security\" set \"IsArchived\" = 1 where \"SecurityId\"=@securityId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@securityId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, securityId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #12
0
        /// <summary>ArchiveChildrens a User record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">the version number of this row.</param>
        /// <param name="userId">The value for the UserId column.</param>
        /// <param name="archive">true to archive the object, false to unarchive it.</param>
        internal static void ArchiveChildren(AdoTransaction adoTransaction, SqlTransaction sqlTransaction, long rowVersion, int userId)
        {
            // Accessor for the User Table.
            ServerMarketData.UserDataTable userTable = ServerMarketData.User;
            // This record can be used to iterate through all the children.
            ServerMarketData.UserRow userRow = userTable.FindByUserId(userId);
            // Archive the child records.
            for (int index = 0; (index < userRow.GetAccountBaseRows().Length); index = (index + 1))
            {
                ServerMarketData.AccountBaseRow childAccountBaseRow = userRow.GetAccountBaseRows()[index];
                AccountBase.ArchiveChildren(adoTransaction, sqlTransaction, childAccountBaseRow.RowVersion, childAccountBaseRow.AccountBaseId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByUserAllocationCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = userRow.GetAllocationRowsByUserAllocationCreatedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetAllocationRowsByUserAllocationModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.AllocationRow childAllocationRow = userRow.GetAllocationRowsByUserAllocationModifiedUserId()[index];
                Allocation.Archive(adoTransaction, sqlTransaction, childAllocationRow.RowVersion, childAllocationRow.AllocationId);
            }
            for (int index = 0; (index < userRow.GetComplianceOfficerRows().Length); index = (index + 1))
            {
                ServerMarketData.ComplianceOfficerRow childComplianceOfficerRow = userRow.GetComplianceOfficerRows()[index];
                ComplianceOfficer.ArchiveChildren(adoTransaction, sqlTransaction, childComplianceOfficerRow.RowVersion, childComplianceOfficerRow.ComplianceOfficerId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByUserExecutionCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByUserExecutionCreatedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetExecutionRowsByUserExecutionModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = userRow.GetExecutionRowsByUserExecutionModifiedUserId()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            for (int index = 0; (index < userRow.GetSourceOrderRowsByUserSourceOrderCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = userRow.GetSourceOrderRowsByUserSourceOrderCreatedUserId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < userRow.GetSourceOrderRowsByUserSourceOrderModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.SourceOrderRow childSourceOrderRow = userRow.GetSourceOrderRowsByUserSourceOrderModifiedUserId()[index];
                SourceOrder.Archive(adoTransaction, sqlTransaction, childSourceOrderRow.RowVersion, childSourceOrderRow.SourceOrderId);
            }
            for (int index = 0; (index < userRow.GetTraderRows().Length); index = (index + 1))
            {
                ServerMarketData.TraderRow childTraderRow = userRow.GetTraderRows()[index];
                Trader.ArchiveChildren(adoTransaction, sqlTransaction, childTraderRow.RowVersion, childTraderRow.TraderId);
            }
            for (int index = 0; (index < userRow.GetWorkingOrderRowsByUserWorkingOrderCreatedUserId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = userRow.GetWorkingOrderRowsByUserWorkingOrderCreatedUserId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            for (int index = 0; (index < userRow.GetWorkingOrderRowsByUserWorkingOrderModifiedUserId().Length); index = (index + 1))
            {
                ServerMarketData.WorkingOrderRow childWorkingOrderRow = userRow.GetWorkingOrderRowsByUserWorkingOrderModifiedUserId()[index];
                WorkingOrder.Archive(adoTransaction, sqlTransaction, childWorkingOrderRow.RowVersion, childWorkingOrderRow.WorkingOrderId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            userRow[userTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(userRow);
            userRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"User\" set \"IsArchived\" = 1 where \"UserId\"=@userId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@userId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, userId));
            sqlCommand.ExecuteNonQuery();
        }
Пример #13
0
        private static void DestinationOrder_DestinationOrderRowChanging(object sender, MarkThree.Guardian.DataSetMarket.DestinationOrderRowChangeEvent e)
        {
            if (e.Action == DataRowAction.Commit)
            {
                ServerMarketData.DestinationOrderRow destinationOrderRow = e.Row;

                int currentStatusCode  = destinationOrderRow.StatusCode;
                int previousStatusCode = destinationOrderRow.HasVersion(DataRowVersion.Original) ?
                                         (int)destinationOrderRow[ServerMarketData.DestinationOrder.StatusCodeColumn, DataRowVersion.Original] :
                                         destinationOrderRow.StatusCode;

                if (currentStatusCode != previousStatusCode)
                {
                    ServerMarketData.WorkingOrderRow workingOrderRow = e.Row.WorkingOrderRow;

                    if (destinationOrderRow.StatusCode == Status.Error)
                    {
                        BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetWorkingOrderStatus),
                                                                                 new object[] { workingOrderRow.WorkingOrderId }, Status.Error));
                    }

                    if ((workingOrderRow.StatusCode == Status.New || workingOrderRow.StatusCode == Status.Filled) &&
                        destinationOrderRow.StatusCode == Status.PartiallyFilled)
                    {
                        BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetWorkingOrderStatus),
                                                                                 new object[] { workingOrderRow.WorkingOrderId }, Status.PartiallyFilled));
                    }

                    if ((workingOrderRow.StatusCode == Status.New || workingOrderRow.StatusCode == Status.PartiallyFilled) &&
                        destinationOrderRow.StatusCode == Status.Filled)
                    {
                        bool isFilled = true;
                        foreach (ServerMarketData.DestinationOrderRow innerDestinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                        {
                            if (innerDestinationOrderRow.StatusCode != Status.Filled)
                            {
                                isFilled = false;
                                break;
                            }
                        }

                        if (isFilled)
                        {
                            BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetWorkingOrderStatus),
                                                                                     new object[] { workingOrderRow.WorkingOrderId }, Status.Filled));
                        }
                    }

                    if (previousStatusCode != Status.New && currentStatusCode == Status.New)
                    {
                        bool isNew = true;
                        foreach (ServerMarketData.DestinationOrderRow innerDestinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                        {
                            if (innerDestinationOrderRow.StatusCode != Status.New)
                            {
                                isNew = false;
                                break;
                            }
                        }

                        if (isNew)
                        {
                            BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetWorkingOrderStatus),
                                                                                     new object[] { workingOrderRow.WorkingOrderId }, Status.New));
                        }
                    }

                    if (previousStatusCode == Status.Error && workingOrderRow.StatusCode == Status.Error)
                    {
                        int statusCode = Status.New;

                        foreach (ServerMarketData.DestinationOrderRow innerDestinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                        {
                            if (innerDestinationOrderRow.StatusCode == Status.Error)
                            {
                                statusCode = Status.Error;
                                break;
                            }

                            if (innerDestinationOrderRow.StatusCode == Status.PartiallyFilled && (statusCode == Status.New || statusCode == Status.Filled))
                            {
                                statusCode = Status.PartiallyFilled;
                            }

                            if (innerDestinationOrderRow.StatusCode == Status.Filled && statusCode == Status.New)
                            {
                                statusCode = Status.Filled;
                            }
                        }

                        if (statusCode != Status.Error)
                        {
                            BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetWorkingOrderStatus),
                                                                                     new object[] { workingOrderRow.WorkingOrderId }, statusCode));
                        }
                    }
                }
            }
        }
Пример #14
0
        /// <summary>Inserts a Negotiation record using Metadata Parameters.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit.</param>
        /// <param name="remoteMethod">Contains the metadata parameters and exceptions for this command.</param>
        public static void Offer(ParameterList parameters)
        {
            // Accessor for the Match Table.
            ServerMarketData.MatchDataTable matchTable = ServerMarketData.Match;

            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction = parameters["adoTransaction"];
            SqlTransaction sqlTransaction = parameters["sqlTransaction"];
            int            matchId        = parameters["matchId"];
            decimal        quantity       = parameters["quantity"];

            int  negotiationId = int.MinValue;
            long rowVersion    = long.MinValue;

            ServerMarketData.MatchRow matchRow = matchTable.FindByMatchId(matchId);
            if (matchRow != null)
            {
                // Rule #1: Insure that there are no pending offers.
                foreach (ServerMarketData.NegotiationRow innerNegotiationRow in matchRow.GetNegotiationRows())
                {
                    if (innerNegotiationRow.StatusCode == Status.Pending)
                    {
                        throw new Exception("There is already an offer pending.");
                    }

                    if (innerNegotiationRow.StatusCode == Status.Declined)
                    {
                        throw new Exception("This offer has previously been declined.");
                    }
                }

                // Time stamps and user stamps
                int      createdUserId  = ServerMarketData.UserId;
                DateTime createdTime    = DateTime.Now;
                int      modifiedUserId = ServerMarketData.UserId;
                DateTime modifiedTime   = DateTime.Now;

                // This will find the contra matching record.
                int contraMatchIndex =
                    ServerMarketData.Match.KeyMatchWorkingOrderIdContraOrderId.Find(new object[] { matchRow.ContraOrderId, matchRow.WorkingOrderId });
                if (contraMatchIndex == -1)
                {
                    throw new Exception(string.Format("Corruption: the match record for {0}, {1} can't be found", matchRow.ContraOrderId, matchRow.WorkingOrderId));
                }
                ServerMarketData.MatchRow contraMatchRow =
                    (ServerMarketData.MatchRow)ServerMarketData.Match.KeyMatchWorkingOrderIdContraOrderId[contraMatchIndex].Row;

                // When both sides have agreed to the Negotiation, the Destination Orders are generated.
                ServerMarketData.NegotiationRow contraNegotiationRow = null;
                foreach (MarketData.NegotiationRow innerNegotiationRow in contraMatchRow.GetNegotiationRows())
                {
                    if (innerNegotiationRow.StatusCode == Status.Pending)
                    {
                        contraNegotiationRow = innerNegotiationRow;
                        break;
                    }
                }

                // This means that there's an offer on the other side.
                if (contraNegotiationRow == null)
                {
                    // There is no opposite side of this transaction yet.  It will be placed in the negotation table and wait there
                    // until it times out, or the other side accepts the offer.
                    long negotiationRowVersion = long.MinValue;
                    negotiationId = MarkThree.Guardian.Core.Negotiation.Insert(adoTransaction, sqlTransaction, ref negotiationRowVersion,
                                                                               null, matchId, quantity, Status.Pending);
                }
                else
                {
                    // At this point, there is an offer on both sides of the match for a follow-on order.  We'll create orders and
                    // executions for both sides of the trade for the minimum agreed upon quantity.
                    ServerMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                    ServerMarketData.WorkingOrderRow contraOrderRow  = contraNegotiationRow.MatchRow.WorkingOrderRow;

                    // The quantity of this negotiation will be the minimum of the two offers.
                    decimal matchedQuantity = quantity < contraNegotiationRow.Quantity ? quantity : contraNegotiationRow.Quantity;

                    // Create the order on this side of the trade.
                    long rowVersionDestionation = long.MinValue;
                    int  destinationOrderId     = MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction,
                                                                                                  ref rowVersionDestionation, null, null, createdTime, createdUserId, Negotiation.destinationId, null, null,
                                                                                                  null, workingOrderRow[ServerMarketData.WorkingOrder.LimitPriceColumn], modifiedTime, modifiedUserId,
                                                                                                  workingOrderRow.OrderTypeCode, matchedQuantity, workingOrderRow.PriceTypeCode, State.Acknowledged, Status.New,
                                                                                                  workingOrderRow[ServerMarketData.WorkingOrder.StopPriceColumn], createdUserId, workingOrderRow.TimeInForceCode,
                                                                                                  workingOrderRow.WorkingOrderId);

                    // Create the Execution for this side of the trade.
                    long rowVersionExecution = long.MinValue;
                    int  executionId         = MarkThree.Guardian.Core.Execution.Insert(adoTransaction, sqlTransaction,
                                                                                        ref rowVersionExecution, null, null, createdTime, createdUserId, destinationOrderId, State.Acknowledged,
                                                                                        workingOrderRow.PriceRow.LastPrice, matchedQuantity, null, null, null, modifiedTime, modifiedUserId,
                                                                                        null, null, null, DateTime.Now, null, State.Sent, DateTime.Now, null, null, null, null);

                    // There is no opposite side of this transaction yet.  It will be placed in the negotation table and wait there
                    // until it times out, or the other side accepts the offer.
                    long negotiationRowVersion = long.MinValue;
                    negotiationId = MarkThree.Guardian.Core.Negotiation.Insert(adoTransaction, sqlTransaction, ref negotiationRowVersion,
                                                                               executionId, matchId, quantity, Status.Accepted);

                    // Create an order for the agreed upon quantity.
                    int contraDestinationOrderId = MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction,
                                                                                                   ref rowVersionDestionation, null, null, createdTime, createdUserId, Negotiation.destinationId, null, null,
                                                                                                   null, contraOrderRow[ServerMarketData.WorkingOrder.LimitPriceColumn], modifiedTime, modifiedUserId,
                                                                                                   contraOrderRow.OrderTypeCode, matchedQuantity, contraOrderRow.PriceTypeCode, State.Acknowledged, Status.New,
                                                                                                   contraOrderRow[ServerMarketData.WorkingOrder.StopPriceColumn], createdUserId, contraOrderRow.TimeInForceCode,
                                                                                                   contraOrderRow.WorkingOrderId);

                    // Create an execution for the agreed upon quantity
                    int contraExecutionId = MarkThree.Guardian.Core.Execution.Insert(adoTransaction, sqlTransaction,
                                                                                     ref rowVersionExecution, null, null, createdTime, createdUserId, contraDestinationOrderId,
                                                                                     State.Acknowledged, contraOrderRow.PriceRow.LastPrice, matchedQuantity, null, null, null, modifiedTime,
                                                                                     modifiedUserId, null, null, null, DateTime.Now, null, State.Sent, DateTime.Now, null, null, null, null);

                    // Update the contra offer.
                    long contraNegotiationRowVersion = contraNegotiationRow.RowVersion;
                    MarkThree.Guardian.Core.Negotiation.Update(adoTransaction, sqlTransaction, ref contraNegotiationRowVersion, contraExecutionId, null,
                                                               contraNegotiationRow.NegotiationId, null, Status.Accepted);
                }
            }

            // Return values.
            parameters["rowVersion"] = rowVersion;
            parameters.Return        = negotiationId;
        }
Пример #15
0
        /// <summary>Inserts a Match record using Metadata Parameters.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit.</param>
        /// <param name="remoteMethod">Contains the metadata parameters and exceptions for this command.</param>
        public static void Accept(ParameterList parameters)
        {
            // Accessor for the Match Table.
            ServerMarketData.MatchDataTable matchTable = ServerMarketData.Match;

            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction = parameters["adoTransaction"];
            SqlTransaction sqlTransaction = parameters["sqlTransaction"];
            int            matchId        = parameters["matchId"];
            long           rowVersion     = parameters["rowVersion"];

            ServerMarketData.MatchRow matchRow = matchTable.FindByMatchId(matchId);
            if (matchRow != null)
            {
                // Time stamps and user stamps
                int      createdUserId  = ServerMarketData.UserId;
                DateTime createdTime    = DateTime.Now;
                int      modifiedUserId = ServerMarketData.UserId;
                DateTime modifiedTime   = DateTime.Now;

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.Match.Update(adoTransaction, sqlTransaction, ref rowVersion, null, null,
                                                     matchRow.MatchId, null, Status.Accepted, null);

                // This is the working order associated with the match.
                ServerMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;

                // This will find the contra order.
                int contraMatchIndex =
                    ServerMarketData.Match.KeyMatchWorkingOrderIdContraOrderId.Find(new object[] { matchRow.ContraOrderId, matchRow.WorkingOrderId });
                if (contraMatchIndex == -1)
                {
                    throw new Exception(string.Format("Corruption: the match record for {0}, {1} can't be found", matchRow.ContraOrderId, matchRow.WorkingOrderId));
                }
                ServerMarketData.MatchRow contraMatchRow =
                    (ServerMarketData.MatchRow)ServerMarketData.Match.KeyMatchWorkingOrderIdContraOrderId[contraMatchIndex].Row;

                // When both sides have agreed to the match, the Destination Orders are generated.
                if (contraMatchRow.StatusCode != Status.Accepted)
                {
                    return;
                }

                ServerMarketData.WorkingOrderRow contraOrderRow = contraMatchRow.WorkingOrderRow;

                decimal quantity = workingOrderRow.SubmittedQuantity < contraOrderRow.SubmittedQuantity ? workingOrderRow.SubmittedQuantity : contraOrderRow.SubmittedQuantity;

                long rowVersionDestionation = long.MinValue;
                int  destinationOrderId     = MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction,
                                                                                              ref rowVersionDestionation, null, null, createdTime, createdUserId, Match.destinationId, null, null,
                                                                                              null, workingOrderRow[ServerMarketData.WorkingOrder.LimitPriceColumn], modifiedTime, modifiedUserId,
                                                                                              workingOrderRow.OrderTypeCode, quantity, workingOrderRow.PriceTypeCode, State.Acknowledged, Status.New,
                                                                                              workingOrderRow[ServerMarketData.WorkingOrder.StopPriceColumn], createdUserId, workingOrderRow.TimeInForceCode,
                                                                                              workingOrderRow.WorkingOrderId);

                long rowVersionExecution = long.MinValue;
                MarkThree.Guardian.Core.Execution.Insert(adoTransaction, sqlTransaction, ref rowVersionExecution, null, null, null,
                                                         null, createdTime, createdUserId, destinationOrderId, State.Acknowledged, workingOrderRow.PriceRow.LastPrice,
                                                         quantity, null, null, null, modifiedTime, modifiedUserId, null, null, null, DateTime.Now, null, State.Sent,
                                                         DateTime.Now, null, null, null, null);

                rowVersion = contraMatchRow.RowVersion;
                MarkThree.Guardian.Core.Match.Update(adoTransaction, sqlTransaction, ref rowVersion, null, null,
                                                     contraMatchRow.MatchId, null, Status.Accepted, null);

                int contraDestinationOrderId = MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction,
                                                                                               ref rowVersionDestionation, null, null, createdTime, createdUserId, Match.destinationId, null, null,
                                                                                               null, contraOrderRow[ServerMarketData.WorkingOrder.LimitPriceColumn], modifiedTime, modifiedUserId,
                                                                                               contraOrderRow.OrderTypeCode, quantity, contraOrderRow.PriceTypeCode, State.Acknowledged, Status.New,
                                                                                               contraOrderRow[ServerMarketData.WorkingOrder.StopPriceColumn], createdUserId, contraOrderRow.TimeInForceCode,
                                                                                               contraOrderRow.WorkingOrderId);

                MarkThree.Guardian.Core.Execution.Insert(adoTransaction, sqlTransaction, ref rowVersionExecution, null, null, null,
                                                         null, createdTime, createdUserId, contraDestinationOrderId, State.Acknowledged,
                                                         contraOrderRow.PriceRow.LastPrice, quantity, null, null, null, modifiedTime, modifiedUserId, null, null, null,
                                                         DateTime.Now, null, State.Sent, DateTime.Now, null, null, null, null);
            }

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }