예제 #1
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();
        }
예제 #2
0
 /// <summary>Archives a Trader record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Archive(ParameterList parameters)
 {
     // Accessor for the Trader Table.
     ServerMarketData.TraderDataTable traderTable = ServerMarketData.Trader;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalTraderId = parameters["traderId"];
     // 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;
     // Find the internal identifier using the primary key elements.
     // identifier is used to determine if a record exists with the same key.
     int traderId = Trader.FindRequiredKey(configurationId, "traderId", externalTraderId);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerMarketData.TraderRow traderRow = traderTable.FindByTraderId(traderId);
     rowVersion = ((long)(traderRow[traderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Trader.Archive(adoTransaction, sqlTransaction, rowVersion, traderId);
 }
예제 #3
0
 /// <summary>Loads a Trader record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Load(ParameterList parameters)
 {
     // Accessor for the Trader Table.
     ServerMarketData.TraderDataTable traderTable = ServerMarketData.Trader;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     string name = parameters["name"];
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     object preferences = parameters["preferences"].Value;
     object externalSystemFolderId = parameters["systemFolderId"].Value;
     string userName = parameters["userName"];
     object accountIdDefault = parameters["accountIdDefault"].Value;
     object address1 = parameters["address1"].Value;
     object address2 = parameters["address2"].Value;
     object address3 = parameters["address3"].Value;
     object externalBlotterIdDefault = parameters["blotterIdDefault"].Value;
     object commissionMaximum = parameters["commissionMaximum"].Value;
     object commissionMinimum = parameters["commissionMinimum"].Value;
     object commissionRate = parameters["commissionRate"].Value;
     object commissionRateTypeCode = parameters["commissionRateTypeCode"].Value;
     object emailAddress = parameters["emailAddress"].Value;
     object fixAccountId = parameters["fixAccountId"].Value;
     object isAgencyMatch = parameters["isAgencyMatch"].Value;
     object isBrokerMatch = parameters["isBrokerMatch"].Value;
     object isCommissionChangeAllowed = parameters["isCommissionChangeAllowed"].Value;
     object isEditExecutionsAllowed = parameters["isEditExecutionsAllowed"].Value;
     object isHedgeMatch = parameters["isHedgeMatch"].Value;
     object isHeld = parameters["isHeld"].Value;
     object isInstitutionMatch = parameters["isInstitutionMatch"].Value;
     object lastDeletedOrder = parameters["lastDeletedOrder"].Value;
     object lastFilledOrder = parameters["lastFilledOrder"].Value;
     object lastFilledSourceOrder = parameters["lastFilledSourceOrder"].Value;
     object lastTrade = parameters["lastTrade"].Value;
     object lotSizeDefault = parameters["lotSizeDefault"].Value;
     object marketSleep = parameters["marketSleep"].Value;
     object maximumVolatilityDefault = parameters["maximumVolatilityDefault"].Value;
     object newsFreeTimeDefault = parameters["newsFreeTimeDefault"].Value;
     object oatsAccountType = parameters["oatsAccountType"].Value;
     object oatsOrigDeptId = parameters["oatsOrigDeptId"].Value;
     object orderMaximumLimitDelta = parameters["orderMaximumLimitDelta"].Value;
     object orderMaximumMarketValue = parameters["orderMaximumMarketValue"].Value;
     object orderMaximumQuantity = parameters["orderMaximumQuantity"].Value;
     object orderWarningMarketValue = parameters["orderWarningMarketValue"].Value;
     object orderWarningQuantity = parameters["orderWarningQuantity"].Value;
     object phone = parameters["phone"].Value;
     object reviewWindow = parameters["reviewWindow"].Value;
     object scraperConfigurationString = parameters["scraperConfigurationString"].Value;
     object startTimeDefault = parameters["startTimeDefault"].Value;
     object stopTimeDefault = parameters["stopTimeDefault"].Value;
     object submissionTypeCode = parameters["submissionTypeCode"].Value;
     object tagId = parameters["tagId"].Value;
     string externalTraderId = parameters["traderId"];
     object externalTypeCode = parameters["typeCode"].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
     object systemFolderId = SystemFolder.FindOptionalKey(configurationId, "systemFolderId", externalSystemFolderId);
     object blotterIdDefault = Blotter.FindOptionalKey(configurationId, "blotterIdDefault", externalBlotterIdDefault);
     int traderId = User.FindKey(configurationId, "traderId", externalTraderId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     ServerMarketData.TraderRow traderRow = traderTable.FindByTraderId(traderId);
     // 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 ((traderRow == null))
     {
         // 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 = Trader.GetExternalKeyIndex(configurationId, "traderId");
         object[] externalIdArray = new object[8];
         externalIdArray[externalKeyIndex] = externalTraderId;
         object externalId0 = externalIdArray[0];
         object externalId1 = externalIdArray[1];
         object externalId2 = externalIdArray[2];
         object externalId3 = externalIdArray[3];
         object externalId4 = externalIdArray[4];
         object externalId5 = externalIdArray[5];
         object externalId6 = externalIdArray[6];
         object externalId7 = externalIdArray[7];
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Trader.Insert(adoTransaction, sqlTransaction, ref rowVersion, description, externalId0, externalId1, externalId2, externalId3, externalId4, externalId5, externalId6, externalId7, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, userName, accountIdDefault, address1, address2, address3, blotterIdDefault, commissionMaximum, commissionMinimum, commissionRate, commissionRateTypeCode, emailAddress, fixAccountId, isAgencyMatch, isBrokerMatch, isCommissionChangeAllowed, isEditExecutionsAllowed, isHedgeMatch, isHeld, isInstitutionMatch, lastDeletedOrder, lastFilledOrder, lastFilledSourceOrder, lastTrade, lotSizeDefault, marketSleep, maximumVolatilityDefault, newsFreeTimeDefault, oatsAccountType, oatsOrigDeptId, orderMaximumLimitDelta, orderMaximumMarketValue, orderMaximumQuantity, orderWarningMarketValue, orderWarningQuantity, phone, reviewWindow, scraperConfigurationString, startTimeDefault, stopTimeDefault, submissionTypeCode, tagId, typeCode);
     }
     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.
         rowVersion = ((long)(traderRow[traderTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.Trader.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, userName, accountIdDefault, address1, address2, address3, blotterIdDefault, commissionMaximum, commissionMinimum, commissionRate, commissionRateTypeCode, emailAddress, fixAccountId, isAgencyMatch, isBrokerMatch, isCommissionChangeAllowed, isEditExecutionsAllowed, isHedgeMatch, isHeld, isInstitutionMatch, lastDeletedOrder, lastFilledOrder, lastFilledSourceOrder, lastTrade, lotSizeDefault, marketSleep, maximumVolatilityDefault, newsFreeTimeDefault, oatsAccountType, oatsOrigDeptId, orderMaximumLimitDelta, orderMaximumMarketValue, orderMaximumQuantity, orderWarningMarketValue, orderWarningQuantity, phone, reviewWindow, scraperConfigurationString, startTimeDefault, stopTimeDefault, submissionTypeCode, tagId, traderId, typeCode);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
예제 #4
0
 /// <summary>Updates a Trader record using Metadata Parameters.</summary>
 /// <param name="transaction">Contains the parameters and exceptions for this command.</param>
 public new static void Update(ParameterList parameters)
 {
     // Accessor for the Trader Table.
     ServerMarketData.TraderDataTable traderTable = ServerMarketData.Trader;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object description = parameters["description"].Value;
     object groupPermission = parameters["groupPermission"].Value;
     object hidden = parameters["hidden"].Value;
     object name = parameters["name"].Value;
     object owner = parameters["owner"].Value;
     object ownerPermission = parameters["ownerPermission"].Value;
     object readOnly = parameters["readOnly"].Value;
     object worldPermission = parameters["worldPermission"].Value;
     object preferences = parameters["preferences"].Value;
     object externalSystemFolderId = parameters["systemFolderId"].Value;
     object userName = parameters["userName"].Value;
     object accountIdDefault = parameters["accountIdDefault"].Value;
     object address1 = parameters["address1"].Value;
     object address2 = parameters["address2"].Value;
     object address3 = parameters["address3"].Value;
     object externalBlotterIdDefault = parameters["blotterIdDefault"].Value;
     object commissionMaximum = parameters["commissionMaximum"].Value;
     object commissionMinimum = parameters["commissionMinimum"].Value;
     object commissionRate = parameters["commissionRate"].Value;
     object commissionRateTypeCode = parameters["commissionRateTypeCode"].Value;
     object emailAddress = parameters["emailAddress"].Value;
     object fixAccountId = parameters["fixAccountId"].Value;
     object isAgencyMatch = parameters["isAgencyMatch"].Value;
     object isBrokerMatch = parameters["isBrokerMatch"].Value;
     object isCommissionChangeAllowed = parameters["isCommissionChangeAllowed"].Value;
     object isEditExecutionsAllowed = parameters["isEditExecutionsAllowed"].Value;
     object isHedgeMatch = parameters["isHedgeMatch"].Value;
     object isHeld = parameters["isHeld"].Value;
     object isInstitutionMatch = parameters["isInstitutionMatch"].Value;
     object lastDeletedOrder = parameters["lastDeletedOrder"].Value;
     object lastFilledOrder = parameters["lastFilledOrder"].Value;
     object lastFilledSourceOrder = parameters["lastFilledSourceOrder"].Value;
     object lastTrade = parameters["lastTrade"].Value;
     object lotSizeDefault = parameters["lotSizeDefault"].Value;
     object marketSleep = parameters["marketSleep"].Value;
     object maximumVolatilityDefault = parameters["maximumVolatilityDefault"].Value;
     object newsFreeTimeDefault = parameters["newsFreeTimeDefault"].Value;
     object oatsAccountType = parameters["oatsAccountType"].Value;
     object oatsOrigDeptId = parameters["oatsOrigDeptId"].Value;
     object orderMaximumLimitDelta = parameters["orderMaximumLimitDelta"].Value;
     object orderMaximumMarketValue = parameters["orderMaximumMarketValue"].Value;
     object orderMaximumQuantity = parameters["orderMaximumQuantity"].Value;
     object orderWarningMarketValue = parameters["orderWarningMarketValue"].Value;
     object orderWarningQuantity = parameters["orderWarningQuantity"].Value;
     object phone = parameters["phone"].Value;
     object reviewWindow = parameters["reviewWindow"].Value;
     object scraperConfigurationString = parameters["scraperConfigurationString"].Value;
     object startTimeDefault = parameters["startTimeDefault"].Value;
     object stopTimeDefault = parameters["stopTimeDefault"].Value;
     object submissionTypeCode = parameters["submissionTypeCode"].Value;
     object tagId = parameters["tagId"].Value;
     string externalTraderId = ((string)(parameters["traderId"]));
     object externalTypeCode = parameters["typeCode"].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
     object systemFolderId = SystemFolder.FindOptionalKey(configurationId, "systemFolderId", externalSystemFolderId);
     object blotterIdDefault = Blotter.FindOptionalKey(configurationId, "blotterIdDefault", externalBlotterIdDefault);
     int traderId = User.FindRequiredKey(configurationId, "traderId", externalTraderId);
     object typeCode = Type.FindOptionalKey(configurationId, "typeCode", externalTypeCode);
     // This disables the concurrency checking logic by finding the current row version and passing it to the
     // internal method.
     ServerMarketData.TraderRow traderRow = traderTable.FindByTraderId(traderId);
     rowVersion = ((long)(traderRow[traderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.Trader.Update(adoTransaction, sqlTransaction, ref rowVersion, description, null, null, null, null, null, null, null, null, groupPermission, hidden, name, owner, ownerPermission, readOnly, worldPermission, preferences, systemFolderId, userName, accountIdDefault, address1, address2, address3, blotterIdDefault, commissionMaximum, commissionMinimum, commissionRate, commissionRateTypeCode, emailAddress, fixAccountId, isAgencyMatch, isBrokerMatch, isCommissionChangeAllowed, isEditExecutionsAllowed, isHedgeMatch, isHeld, isInstitutionMatch, lastDeletedOrder, lastFilledOrder, lastFilledSourceOrder, lastTrade, lotSizeDefault, marketSleep, maximumVolatilityDefault, newsFreeTimeDefault, oatsAccountType, oatsOrigDeptId, orderMaximumLimitDelta, orderMaximumMarketValue, orderMaximumQuantity, orderWarningMarketValue, orderWarningQuantity, phone, reviewWindow, scraperConfigurationString, startTimeDefault, stopTimeDefault, submissionTypeCode, tagId, traderId, typeCode);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
예제 #5
0
        /// <summary>Inserts a SourceOrder 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 InsertFile(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         externalBlotterId          = parameters["blotterId"];
            object         externalDestinationId      = parameters["destinationId"].Value;
            string         externalWorkingOrderId     = parameters["workingOrderId"];
            string         externalOrderTypeCode      = parameters["orderTypeCode"];
            string         externalPriceTypeCode      = parameters["priceTypeCode"];
            string         externalSecurityId         = parameters["securityId"];
            object         externalSettlementId       = parameters["settlementId"].Value;
            object         externalSubmissionTypeCode = parameters["submissionTypeCode"].Value;
            object         submittedQuantity          = parameters["submittedQuantity"].Value;
            object         submittedTime           = parameters["submittedTime"].Value;
            string         externalTimeInForceCode = parameters["timeInForceCode"];
            object         uploadedTime            = parameters["uploadedTime"].Value;
            object         externalId0             = parameters["externalId0"].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          = External.Blotter.FindRequiredKey(configurationId, "blotterId", externalBlotterId);
            int    workingOrderId     = External.WorkingOrder.FindKey(configurationId, "workingOrderId", externalWorkingOrderId);
            object destinationId      = External.Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
            int    orderTypeCode      = External.OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
            int    priceTypeCode      = External.PriceType.FindRequiredKey(configurationId, "priceTypeCode", externalPriceTypeCode);
            int    securityId         = External.Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
            object submissionTypeCode = External.SubmissionType.FindOptionalKey(configurationId, "submissionTypeCode", externalSubmissionTypeCode);
            object settlementId       = External.Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
            int    timeInForceCode    = External.TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);

            // 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 isHeld = parameters["isHeld"] is MissingParameter ? (object)null :
                            Convert.ToBoolean(parameters["isHeld"].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      createdUserId  = ServerMarketData.UserId;
            DateTime createdTime    = DateTime.Now;
            int      modifiedUserId = ServerMarketData.UserId;
            DateTime modifiedTime   = createdTime;
            DateTime timeReceived   = createdTime;
            int      statusCode     = Status.New;

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

            // The Trader table contains additional defaults for incoming orders.
            int traderId = ServerMarketData.UserId;

            ServerMarketData.TraderRow traderRow = ServerMarketData.Trader.FindByTraderId(traderId);
            if (isAgencyMatch == null)
            {
                isAgencyMatch = traderRow.IsAgencyMatch;
            }
            if (isBrokerMatch == null)
            {
                isBrokerMatch = traderRow.IsBrokerMatch;
            }
            if (isHedgeMatch == null)
            {
                isHedgeMatch = traderRow.IsHedgeMatch;
            }
            if (isInstitutionMatch == null)
            {
                isInstitutionMatch = traderRow.IsInstitutionMatch;
            }
            if (maximumVolatility == null && !traderRow.IsMaximumVolatilityDefaultNull())
            {
                maximumVolatility = traderRow.MaximumVolatilityDefault;
            }
            if (startTime == null && !traderRow.IsStartTimeDefaultNull())
            {
                startTime = traderRow.StartTimeDefault;
            }
            if (stopTime == null && !traderRow.IsStopTimeDefaultNull())
            {
                stopTime = traderRow.StopTimeDefault;
            }
            if (newsFreeTime == null && !traderRow.IsNewsFreeTimeDefaultNull())
            {
                newsFreeTime = traderRow.NewsFreeTimeDefault;
            }

            // 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 = External.WorkingOrder.GetExternalKeyIndex(configurationId, "workingOrderId");
                object[] externalIdArray  = new object[1];
                externalIdArray[externalKeyIndex] = externalWorkingOrderId;
                externalId0 = externalIdArray[0];

                // Create a timer for this working order for sleeping while in the matching box.
                long timerRowVersion = long.MinValue;
                int  timerId         = Core.Timer.Insert(adoTransaction, sqlTransaction, ref timerRowVersion, DateTime.MinValue, null, false, DateTime.MinValue, 0);

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.WorkingOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, null, blotterId, createdTime,
                                                            createdUserId, destinationId, externalId0, isAgencyMatch, null, null, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice,
                                                            maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId,
                                                            settlementId, startTime, statusCode, stopPrice, stopTime, (int)submissionTypeCode, submittedQuantity,
                                                            submittedTime, timeInForceCode, timerId, uploadedTime);
            }
            else
            {
                throw new Exception(string.Format("There is already a working order with the identifier {0}", externalWorkingOrderId));
            }

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
예제 #6
0
파일: User.cs 프로젝트: DonaldAirey/quasar
        /// <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();
        }
예제 #7
0
        /// <summary>Inserts a SourceOrder 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 Insert(ParameterList parameters)
        {
            // Accessor for the SourceOrder Table.
            ServerMarketData.SourceOrderDataTable sourceOrderTable = ServerMarketData.SourceOrder;
            // Extract the parameters from the command batch.
            AdoTransaction adoTransaction        = parameters["adoTransaction"];
            SqlTransaction sqlTransaction        = parameters["sqlTransaction"];
            object         blotterId             = parameters["blotterId"].Value;
            object         configurationId       = parameters["configurationId"].Value;
            object         destinationId         = parameters["destinationId"].Value;
            object         externalBlotterId     = parameters["blotterId"].Value;
            object         externalSourceOrderId = parameters["sourceOrderId"].Value;
            object         externalDestinationId = parameters["destinationId"].Value;
            object         externalId0           = parameters["externalId0"].Value;
            object         isAdvertised          = parameters["isAdvertised"].Value;
            object         isAgencyMatch         = parameters["isAgencyMatch"].Value;
            object         isBrokerMatch         = parameters["isBrokerMatch"].Value;
            object         isCanceled            = parameters["isCanceled"].Value;
            object         isSteppedIn           = parameters["isSteppedIn"].Value;
            object         isHedgeMatch          = parameters["isHedgeMatch"].Value;
            object         isHeld             = parameters["isHeld"].Value;
            object         isInstitutionMatch = parameters["isInstitutionMatch"].Value;
            object         limitPrice         = parameters["limitPrice"].Value;
            object         maximumVolatility  = parameters["maximumVolatility"].Value;
            object         newsFreeTime       = parameters["newsFreeTime"].Value;

            System.Decimal orderedQuantity        = parameters["orderedQuantity"];
            int            orderTypeCode          = parameters["orderTypeCode"];
            int            priceTypeCode          = parameters["priceTypeCode"];
            object         receivedTime           = parameters["receivedTime"].Value;
            string         externalSecurityId     = parameters["securityId"];
            string         externalSettlementId   = parameters["settlementId"];
            object         workingOrderId         = parameters["workingOrderId"].Value;
            object         startTime              = parameters["startTime"].Value;
            object         stopTime               = parameters["stopTime"].Value;
            object         stopPrice              = parameters["stopPrice"].Value;
            object         submissionTypeCode     = parameters["submissionTypeCode"].Value;
            object         submittedQuantity      = parameters["submittedQuantity"].Value;
            object         targetPrice            = parameters["targetPrice"].Value;
            int            timeInForceCode        = parameters["timeInForceCode"];
            object         uploadedTime           = parameters["uploadedTime"].Value;
            object         externalWorkingOrderId = parameters["workingOrderId"].Value;

            // Look up the external values.
            int securityId   = External.Security.FindRequiredKey("US TICKER", "securityId", externalSecurityId);
            int settlementId = External.Security.FindRequiredKey("US TICKER", "settlementId", externalSettlementId);

            // This will get the row version of the newly added Source Order.
            long rowVersion = long.MinValue;

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

            // The Trader table contains additional defaults for incoming orders.
            int traderId = ServerMarketData.UserId;

            ServerMarketData.TraderRow traderRow = ServerMarketData.Trader.FindByTraderId(traderId);
            if (isAgencyMatch == null)
            {
                isAgencyMatch = traderRow.IsAgencyMatch;
            }
            if (isBrokerMatch == null)
            {
                isBrokerMatch = traderRow.IsBrokerMatch;
            }
            if (isHedgeMatch == null)
            {
                isHedgeMatch = traderRow.IsHedgeMatch;
            }
            if (isInstitutionMatch == null)
            {
                isInstitutionMatch = traderRow.IsInstitutionMatch;
            }
            if (maximumVolatility == null && !traderRow.IsMaximumVolatilityDefaultNull())
            {
                maximumVolatility = traderRow.MaximumVolatilityDefault;
            }
            if (startTime == null && !traderRow.IsStartTimeDefaultNull())
            {
                startTime = traderRow.StartTimeDefault;
            }
            if (stopTime == null && !traderRow.IsStopTimeDefaultNull())
            {
                stopTime = traderRow.StopTimeDefault;
            }
            if (newsFreeTime == null && !traderRow.IsNewsFreeTimeDefaultNull())
            {
                newsFreeTime = traderRow.NewsFreeTimeDefault;
            }

            // Rule #1 - Blotter must be specified if the working order is not specified.
            if (blotterId == null && workingOrderId == null)
            {
                throw new Exception("Either a blotter or a Working Order must be specified as a location for this Order");
            }

            // If the incoming order specified a submitted quantity, then automatically enter the order into the cross.
            if (submissionTypeCode == null)
            {
                submissionTypeCode = SubmissionType.NeverMatch;
            }

            object submittedTime = null;

            if ((int)submissionTypeCode != SubmissionType.NeverMatch)
            {
                submittedTime = DateTime.Now;
                if (submittedQuantity == null)
                {
                    submittedQuantity = orderedQuantity;
                }
            }

            // Update the rowversion of the object associated with this trade.
            ServerMarketData.SecurityRow securityRow = ServerMarketData.Security.FindBySecurityId(securityId);
            if (securityRow != null)
            {
                foreach (ServerMarketData.EquityRow equityRow in securityRow.GetEquityRowsBySecurityEquityEquityId())
                {
                    long equityRowVersion = equityRow.RowVersion;
                    Core.Equity.Update(adoTransaction, sqlTransaction, ref equityRowVersion, null, null, null, null, null,
                                       null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                                       equityRow.EquityId, null, null, null, null, null, null, null);
                }

                foreach (ServerMarketData.PriceRow priceRow in securityRow.GetPriceRows())
                {
                    long priceRowVersion = priceRow.RowVersion;
                    Core.Price.Update(adoTransaction, sqlTransaction, ref priceRowVersion, null, null, null, null, null, null, null,
                                      null, null, null, null, null, priceRow.SecurityId, null, null);
                }
            }

            ServerMarketData.SecurityRow settlementRow = ServerMarketData.Security.FindBySecurityId(settlementId);
            if (settlementRow != null)
            {
                foreach (ServerMarketData.CurrencyRow currencyRow in settlementRow.GetCurrencyRows())
                {
                    long currencyRowVersion = currencyRow.RowVersion;
                    Core.Currency.Update(adoTransaction, sqlTransaction, ref currencyRowVersion, null, null, null, null, null,
                                         null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                                         currencyRow.CurrencyId, null, null, null);
                }
            }

            // An order can be automatically associated with a working order if the working order is specified when the order is
            // created.
            if (workingOrderId == null)
            {
                long timerRowVersion = long.MinValue;
                int  timerId         = Core.Timer.Insert(adoTransaction, sqlTransaction, ref timerRowVersion, currentTime, null, false, currentTime, 0);
                workingOrderId = Core.WorkingOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, null, (int)blotterId,
                                                          createdTime, createdUserId, destinationId, null, isAgencyMatch, null, true, isBrokerMatch, isHedgeMatch, isInstitutionMatch, limitPrice,
                                                          maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId,
                                                          settlementId, startTime, statusCode, stopPrice, stopTime, (int)submissionTypeCode, submittedQuantity, submittedTime,
                                                          timeInForceCode, timerId, null);
            }

            // Call the internal method to complete the operation.
            MarkThree.Guardian.Core.SourceOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, createdTime, createdUserId,
                                                       destinationId, externalId0, isAdvertised, isHeld, isCanceled, isHeld, isSteppedIn, submissionTypeCode,
                                                       limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode,
                                                       orderedQuantity, priceTypeCode, receivedTime, securityId, settlementId, startTime, statusCode,
                                                       stopPrice, stopTime, submittedQuantity, submittedTime, targetPrice, timeInForceCode, (int)workingOrderId);

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
예제 #8
0
        /// <summary>Inserts a SourceOrder 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 InsertFile(ParameterList parameters)
        {
            // Accessor for the SourceOrder Table.
            ServerMarketData.SourceOrderDataTable sourceOrderTable = ServerMarketData.SourceOrder;
            // 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;
            object         externalSourceOrderId = parameters["sourceOrderId"].Value;
            object         externalDestinationId = parameters["destinationId"].Value;
            object         externalId0           = parameters["externalId0"].Value;
            object         isAdvertised          = parameters["isAdvertised"].Value;
            object         isCanceled            = parameters["isCanceled"].Value;
            object         isSteppedIn           = parameters["isSteppedIn"].Value;
            object         limitPrice            = parameters["limitPrice"].Value;

            System.Decimal orderedQuantity            = parameters["orderedQuantity"];
            string         externalOrderTypeCode      = parameters["orderTypeCode"];
            string         externalPriceTypeCode      = parameters["priceTypeCode"];
            object         receivedTime               = parameters["receivedTime"].Value;
            string         externalSecurityId         = parameters["securityId"];
            string         externalSettlementId       = parameters["settlementId"];
            object         stopPrice                  = parameters["stopPrice"].Value;
            object         targetPrice                = parameters["targetPrice"].Value;
            object         externalSubmissionTypeCode = parameters["submissionTypeCode"].Value;
            string         externalTimeInForceCode    = parameters["timeInForceCode"];
            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
            object blotterId          = External.Blotter.FindOptionalKey(configurationId, "blotterId", externalBlotterId);
            int    sourceOrderId      = External.SourceOrder.FindKey(configurationId, "sourceOrderId", (string)externalSourceOrderId);
            int    orderTypeCode      = External.OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
            object destinationId      = External.Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
            int    priceTypeCode      = External.PriceType.FindRequiredKey(configurationId, "priceTypeCode", externalPriceTypeCode);
            int    securityId         = External.Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
            int    settlementId       = External.Security.FindRequiredKey(configurationId, "settlementId", externalSettlementId);
            int    timeInForceCode    = External.TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
            object submissionTypeCode = External.SubmissionType.FindOptionalKey(configurationId, "submissionTypeCode", externalSubmissionTypeCode);
            object workingOrderId     = External.WorkingOrder.FindOptionalKey(configurationId, "workingOrderId", externalWorkingOrderId);

            // Optional Parameters
            object canceledQuantity = parameters["canceledQuantity"] is MissingParameter ? (object)null :
                                      Convert.ToDecimal(parameters["canceledQuantity"].Value);
            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 isHeld = parameters["isHeld"] is MissingParameter ? (object)null :
                            Convert.ToBoolean(parameters["isHeld"].Value);
            object isInstitutionMatch = parameters["isInstitutionMatch"] is MissingParameter ? (object)null :
                                        Convert.ToBoolean(parameters["isInstitutionMatch"].Value);
            object specifiedLimit = parameters["specifiedLimit"] is MissingParameter ? (object)null :
                                    Convert.ToDecimal(parameters["specifiedLimit"].Value);
            object maximumVolatility = parameters["maximumVolatility"] is MissingParameter ? (object)null :
                                       Convert.ToDecimal(parameters["maximumVolatility"].Value);
            object submittedQuantity = parameters["submittedQuantity"] is MissingParameter ? (object)null :
                                       Convert.ToDecimal(parameters["submittedQuantity"].Value);
            object startTime = parameters["startTime"] is MissingParameter ? (object)null :
                               Convert.ToDateTime(parameters["startTime"].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);

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

            // The Trader table contains additional defaults for incoming orders.
            int traderId = ServerMarketData.UserId;

            ServerMarketData.TraderRow traderRow = ServerMarketData.Trader.FindByTraderId(traderId);
            if (isAgencyMatch == null)
            {
                isAgencyMatch = traderRow.IsAgencyMatch;
            }
            if (isBrokerMatch == null)
            {
                isBrokerMatch = traderRow.IsBrokerMatch;
            }
            if (isHedgeMatch == null)
            {
                isHedgeMatch = traderRow.IsHedgeMatch;
            }
            if (isInstitutionMatch == null)
            {
                isInstitutionMatch = traderRow.IsInstitutionMatch;
            }
            if (maximumVolatility == null && !traderRow.IsMaximumVolatilityDefaultNull())
            {
                maximumVolatility = traderRow.MaximumVolatilityDefault;
            }
            if (startTime == null && !traderRow.IsStartTimeDefaultNull())
            {
                startTime = traderRow.StartTimeDefault;
            }
            if (stopTime == null && !traderRow.IsStopTimeDefaultNull())
            {
                stopTime = traderRow.StopTimeDefault;
            }
            if (newsFreeTime == null && !traderRow.IsNewsFreeTimeDefaultNull())
            {
                newsFreeTime = traderRow.NewsFreeTimeDefault;
            }

            // Rule #1 - Blotter must be specified if the working order is not specified.
            if (blotterId == null && workingOrderId == null)
            {
                throw new Exception("Either a blotter or a Working Order must be specified as a location for this Order");
            }

            // If the incoming order specified a submitted quantity, then automatically enter the order into the cross.
            if (submissionTypeCode == null)
            {
                submissionTypeCode = SubmissionType.NeverMatch;
            }

            object submittedTime = null;

            if ((int)submissionTypeCode != SubmissionType.NeverMatch)
            {
                submittedTime = DateTime.Now;
                if (submittedQuantity == null)
                {
                    submittedQuantity = orderedQuantity;
                }
            }

            // Update the rowversion of the object associated with this trade.
            ServerMarketData.SecurityRow securityRow = ServerMarketData.Security.FindBySecurityId(securityId);
            if (securityRow != null)
            {
                foreach (ServerMarketData.EquityRow equityRow in securityRow.GetEquityRowsBySecurityEquityEquityId())
                {
                    long equityRowVersion = equityRow.RowVersion;
                    Core.Equity.Update(adoTransaction, sqlTransaction, ref equityRowVersion, null, null, null, null, null,
                                       null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                                       null, equityRow.EquityId, null, null, null, null, null, null, null);
                }

                foreach (ServerMarketData.PriceRow priceRow in securityRow.GetPriceRows())
                {
                    long priceRowVersion = priceRow.RowVersion;
                    Core.Price.Update(adoTransaction, sqlTransaction, ref priceRowVersion, null, null, null, null, null, null, null,
                                      null, null, null, null, null, priceRow.SecurityId, null, null);
                }
            }

            ServerMarketData.SecurityRow settlementRow = ServerMarketData.Security.FindBySecurityId(settlementId);
            if (settlementRow != null)
            {
                foreach (ServerMarketData.CurrencyRow currencyRow in settlementRow.GetCurrencyRows())
                {
                    long currencyRowVersion = currencyRow.RowVersion;
                    Core.Currency.Update(adoTransaction, sqlTransaction, ref currencyRowVersion, null, null, null, null, null,
                                         null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                                         currencyRow.CurrencyId, null, null, null);
                }
            }

            // An order can be automatically associated with a working order if the working order is specified when the order is
            // created.
            if (workingOrderId == null)
            {
                long     timerRowVersion = long.MinValue;
                DateTime currentTime     = DateTime.Now;
                int      timerId         = Core.Timer.Insert(adoTransaction, sqlTransaction, ref timerRowVersion, currentTime, null, false, currentTime, 0);
                workingOrderId = Core.WorkingOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, null, (int)blotterId,
                                                          createdTime, createdUserId, destinationId, null, isAgencyMatch, null, true, isBrokerMatch, isHedgeMatch,
                                                          isInstitutionMatch, limitPrice, maximumVolatility,
                                                          modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode, priceTypeCode, securityId,
                                                          settlementId, startTime, statusCode, stopPrice, stopTime, (int)submissionTypeCode, submittedQuantity,
                                                          submittedTime, timeInForceCode, timerId, null);
            }

            // 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 (sourceOrderId == 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 = External.SourceOrder.GetExternalKeyIndex(configurationId, "sourceOrderId");
                object[] externalIdArray  = new object[1];
                externalIdArray[externalKeyIndex] = externalSourceOrderId;
                externalId0 = externalIdArray[0];

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.SourceOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, createdTime, createdUserId,
                                                           destinationId, externalId0, isAdvertised, isHeld, isCanceled, isHeld, isSteppedIn, submissionTypeCode,
                                                           limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime, orderTypeCode,
                                                           orderedQuantity, priceTypeCode, receivedTime, securityId, settlementId, startTime, statusCode,
                                                           stopPrice, stopTime, submittedQuantity, submittedTime, targetPrice, timeInForceCode, (int)workingOrderId);
            }
            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.SourceOrderRow sourceOrderRow = sourceOrderTable.FindBySourceOrderId((int)sourceOrderId);
                rowVersion = ((long)(sourceOrderRow[sourceOrderTable.RowVersionColumn]));

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.SourceOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, createdTime, createdUserId,
                                                           (int)sourceOrderId, destinationId, stopTime, externalId0, isAdvertised, isHeld, isCanceled, isHeld,
                                                           isSteppedIn, submissionTypeCode, limitPrice, maximumVolatility, modifiedTime, modifiedUserId, newsFreeTime,
                                                           orderTypeCode, orderedQuantity, priceTypeCode, receivedTime, securityId, settlementId,
                                                           startTime, statusCode, stopPrice, submittedQuantity, submittedTime, targetPrice, timeInForceCode,
                                                           workingOrderId);
            }

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