Example #1
0
        private static void Execution_ExecutionRowDeleted(object sender, MarkThree.Guardian.DataSetMarket.ExecutionRowChangeEvent e)
        {
            int destinationOrderId = (int)e.Row[ServerMarketData.Execution.DestinationOrderIdColumn,
                                                e.Row.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Current];

            ServerMarketData.DestinationOrderRow destinationOrderRow = ServerMarketData.DestinationOrder.FindByDestinationOrderId(destinationOrderId);
            if (destinationOrderRow == null)
            {
                return;
            }

            decimal orderQuantity = destinationOrderRow.OrderedQuantity - destinationOrderRow.CanceledQuantity;

            decimal executionQuantity = 0.0m;

            foreach (ServerMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
            {
                executionQuantity += executionRow.ExecutionQuantity;
            }

            if (executionQuantity < orderQuantity && executionQuantity != 0.0m && destinationOrderRow.StatusCode != Status.PartiallyFilled)
            {
                BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetDestinationOrderStatus),
                                                                         new object[] { destinationOrderId }, null, Status.PartiallyFilled));
            }

            if (executionQuantity == 0.0m && destinationOrderRow.StatusCode != Status.New)
            {
                BusinessRules.businessRuleQueue.Enqueue(new ObjectAction(new ObjectHandler(SetDestinationOrderStatus),
                                                                         new object[] { destinationOrderId }, null, Status.New));
            }
        }
Example #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 FilterDestinationOrder(DataRow userDataRow, DataRow destinationOrderDataRow)
 {
     // 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.DestinationOrderRow destinationOrderRow = (ServerMarketData.DestinationOrderRow)destinationOrderDataRow;
     return(Hierarchy.IsDescendant(userRow.SystemFolderRow.FolderRow.ObjectRow,
                                   destinationOrderRow.WorkingOrderRow.BlotterRow.ObjectRow));
 }
Example #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();
        }
Example #4
0
        /// <summary>
        /// Add a match of two orders to begin the negociation process.
        /// </summary>
        /// <param name="workingOrderId">The DestinationOrderId of the first order.</param>
        /// <param name="contraOrderId">The DestinationOrderId of the second order.</param>
        private static void SetDestinationOrderStatus(object[] key, params object[] parameters)
        {
            int    destinationOrderId = (int)key[0];
            object stateCode          = parameters[0];
            object statusCode         = parameters[1];

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

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

                // 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.DestinationOrder.PersistentStore];

                // Add the match of the primary order to the contra order.
                ServerMarketData.DestinationOrderRow destinationOrderRow = ServerMarketData.DestinationOrder.FindByDestinationOrderId(destinationOrderId);
                if (destinationOrderRow != null)
                {
                    long rowVersion = destinationOrderRow.RowVersion;
                    Core.DestinationOrder.Update(transaction.AdoTransaction, sqlInfo.Transaction, ref rowVersion, null, null, null, null, null,
                                                 destinationOrderId, null, null, null, null, null, null, null, null, null, stateCode, statusCode, null,
                                                 null, null, null);
                }

                // 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();
            }
        }
Example #5
0
 /// <summary>Updates a DestinationOrder 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 DestinationOrder Table.
     ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object canceledQuantity = parameters["canceledQuantity"].Value;
     object canceledTime = parameters["canceledTime"].Value;
     object createdTime = parameters["createdTime"].Value;
     object createdUserId = parameters["createdUserId"].Value;
     object externalDestinationId = parameters["destinationId"].Value;
     string externalDestinationOrderId = ((string)(parameters["destinationOrderId"]));
     object isCanceledByUser = parameters["isCanceledByUser"].Value;
     object isHidden = parameters["isHidden"].Value;
     object limitPrice = parameters["limitPrice"].Value;
     object modifiedTime = parameters["modifiedTime"].Value;
     object modifiedUserId = parameters["modifiedUserId"].Value;
     object orderTypeCode = parameters["orderTypeCode"].Value;
     object orderedQuantity = parameters["orderedQuantity"].Value;
     object externalPriceTypeCode = parameters["priceTypeCode"].Value;
     object externalStateCode = parameters["stateCode"].Value;
     object externalStatusCode = parameters["statusCode"].Value;
     object stopPrice = parameters["stopPrice"].Value;
     object externalTraderId = parameters["traderId"].Value;
     object externalTimeInForceCode = parameters["timeInForceCode"].Value;
     object externalWorkingOrderId = parameters["workingOrderId"].Value;
     // The row versioning is largely disabled for external operations.
     long rowVersion = long.MinValue;
     // Resolve External Identifiers
     object destinationId = Destination.FindOptionalKey(configurationId, "destinationId", externalDestinationId);
     int destinationOrderId = DestinationOrder.FindRequiredKey(configurationId, "destinationOrderId", externalDestinationOrderId);
     object priceTypeCode = PriceType.FindOptionalKey(configurationId, "priceTypeCode", externalPriceTypeCode);
     object stateCode = State.FindOptionalKey(configurationId, "stateCode", externalStateCode);
     object statusCode = Status.FindOptionalKey(configurationId, "statusCode", externalStatusCode);
     object traderId = Trader.FindOptionalKey(configurationId, "traderId", externalTraderId);
     object timeInForceCode = TimeInForce.FindOptionalKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     object workingOrderId = WorkingOrder.FindOptionalKey(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.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId(destinationOrderId);
     rowVersion = ((long)(destinationOrderRow[destinationOrderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.DestinationOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, canceledQuantity, canceledTime, createdTime, createdUserId, destinationId, destinationOrderId, null, isCanceledByUser, isHidden, limitPrice, modifiedTime, modifiedUserId, orderTypeCode, orderedQuantity, priceTypeCode, stateCode, statusCode, stopPrice, traderId, timeInForceCode, workingOrderId);
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }
Example #6
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();
        }
Example #7
0
 /// <summary>Archives a DestinationOrder 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 DestinationOrder Table.
     ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     string externalDestinationOrderId = parameters["destinationOrderId"];
     // 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 destinationOrderId = DestinationOrder.FindRequiredKey(configurationId, "destinationOrderId", externalDestinationOrderId);
     // 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.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId(destinationOrderId);
     rowVersion = ((long)(destinationOrderRow[destinationOrderTable.RowVersionColumn]));
     // Call the internal method to complete the operation.
     MarkThree.Guardian.Core.DestinationOrder.Archive(adoTransaction, sqlTransaction, rowVersion, destinationOrderId);
 }
Example #8
0
        /// <summary>Archives a DestinationOrder 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="destinationOrderId">The value for the DestinationOrderId 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 destinationOrderId)
        {
            // Accessor for the DestinationOrder Table.
            ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId(destinationOrderId);
            if ((destinationOrderRow == null))
            {
                throw new Exception(string.Format("The DestinationOrder table does not have an element identified by {0}", destinationOrderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((destinationOrderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Archive the child records.
            for (int index = 0; (index < destinationOrderRow.GetExecutionRows().Length); index = (index + 1))
            {
                ServerMarketData.ExecutionRow childExecutionRow = destinationOrderRow.GetExecutionRows()[index];
                Execution.Archive(adoTransaction, sqlTransaction, childExecutionRow.RowVersion, childExecutionRow.ExecutionId);
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Delete the record in the ADO database.
            destinationOrderRow[destinationOrderTable.RowVersionColumn] = rowVersion;
            adoTransaction.DataRows.Add(destinationOrderRow);
            destinationOrderRow.Delete();
            // Archive the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand("update \"DestinationOrder\" set \"IsArchived\" = 1 where \"DestinationOrderId\"=@destin" +
                                                   "ationOrderId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@destinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationOrderId));
            sqlCommand.ExecuteNonQuery();
        }
Example #9
0
        /// <summary>Updates a DestinationOrder record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="rowVersion">The version number of the row</param>
        /// <param name="canceledQuantity">The value for the CanceledQuantity column.</param>
        /// <param name="canceledTime">The value for the CanceledTime column.</param>
        /// <param name="createdTime">The value for the CreatedTime column.</param>
        /// <param name="createdUserId">The value for the CreatedUserId column.</param>
        /// <param name="destinationId">The value for the DestinationId column.</param>
        /// <param name="destinationOrderId">The value for the DestinationOrderId column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="isCanceledByUser">The value for the IsCanceledByUser column.</param>
        /// <param name="isHidden">The value for the IsHidden column.</param>
        /// <param name="limitPrice">The value for the LimitPrice column.</param>
        /// <param name="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param>
        /// <param name="orderedQuantity">The value for the OrderedQuantity column.</param>
        /// <param name="priceTypeCode">The value for the PriceTypeCode column.</param>
        /// <param name="stateCode">The value for the StateCode column.</param>
        /// <param name="statusCode">The value for the StatusCode column.</param>
        /// <param name="stopPrice">The value for the StopPrice column.</param>
        /// <param name="traderId">The value for the TraderId column.</param>
        /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param>
        /// <param name="workingOrderId">The value for the WorkingOrderId column.</param>
        public static void Update(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object canceledQuantity,
            object canceledTime,
            object createdTime,
            object createdUserId,
            object destinationId,
            int destinationOrderId,
            object externalId0,
            object isCanceledByUser,
            object isHidden,
            object limitPrice,
            object modifiedTime,
            object modifiedUserId,
            object orderTypeCode,
            object orderedQuantity,
            object priceTypeCode,
            object stateCode,
            object statusCode,
            object stopPrice,
            object traderId,
            object timeInForceCode,
            object workingOrderId)
        {
            // Accessor for the DestinationOrder Table.
            ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
            // Rule #1: Make sure the record exists before updating it.
            ServerMarketData.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId(destinationOrderId);
            if ((destinationOrderRow == null))
            {
                throw new Exception(string.Format("The DestinationOrder table does not have an element identified by {0}", destinationOrderId));
            }
            // Rule #2: Optimistic Concurrency Check
            if ((destinationOrderRow.RowVersion != rowVersion))
            {
                throw new System.Exception("This record is busy.  Please try again later.");
            }
            // Apply Defaults
            if ((canceledQuantity == null))
            {
                canceledQuantity = destinationOrderRow[destinationOrderTable.CanceledQuantityColumn];
            }
            if ((canceledTime == null))
            {
                canceledTime = destinationOrderRow[destinationOrderTable.CanceledTimeColumn];
            }
            if ((createdTime == null))
            {
                createdTime = destinationOrderRow[destinationOrderTable.CreatedTimeColumn];
            }
            if ((createdUserId == null))
            {
                createdUserId = destinationOrderRow[destinationOrderTable.CreatedUserIdColumn];
            }
            if ((destinationId == null))
            {
                destinationId = destinationOrderRow[destinationOrderTable.DestinationIdColumn];
            }
            if ((externalId0 == null))
            {
                externalId0 = destinationOrderRow[destinationOrderTable.ExternalId0Column];
            }
            if ((isCanceledByUser == null))
            {
                isCanceledByUser = destinationOrderRow[destinationOrderTable.IsCanceledByUserColumn];
            }
            if ((isHidden == null))
            {
                isHidden = destinationOrderRow[destinationOrderTable.IsHiddenColumn];
            }
            if ((limitPrice == null))
            {
                limitPrice = destinationOrderRow[destinationOrderTable.LimitPriceColumn];
            }
            if ((modifiedTime == null))
            {
                modifiedTime = destinationOrderRow[destinationOrderTable.ModifiedTimeColumn];
            }
            if ((modifiedUserId == null))
            {
                modifiedUserId = destinationOrderRow[destinationOrderTable.ModifiedUserIdColumn];
            }
            if ((orderTypeCode == null))
            {
                orderTypeCode = destinationOrderRow[destinationOrderTable.OrderTypeCodeColumn];
            }
            if ((orderedQuantity == null))
            {
                orderedQuantity = destinationOrderRow[destinationOrderTable.OrderedQuantityColumn];
            }
            if ((priceTypeCode == null))
            {
                priceTypeCode = destinationOrderRow[destinationOrderTable.PriceTypeCodeColumn];
            }
            if ((stateCode == null))
            {
                stateCode = destinationOrderRow[destinationOrderTable.StateCodeColumn];
            }
            if ((statusCode == null))
            {
                statusCode = destinationOrderRow[destinationOrderTable.StatusCodeColumn];
            }
            if ((stopPrice == null))
            {
                stopPrice = destinationOrderRow[destinationOrderTable.StopPriceColumn];
            }
            if ((traderId == null))
            {
                traderId = destinationOrderRow[destinationOrderTable.TraderIdColumn];
            }
            if ((timeInForceCode == null))
            {
                timeInForceCode = destinationOrderRow[destinationOrderTable.TimeInForceCodeColumn];
            }
            if ((workingOrderId == null))
            {
                workingOrderId = destinationOrderRow[destinationOrderTable.WorkingOrderIdColumn];
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Update the record in the ADO database.
            destinationOrderRow[destinationOrderTable.RowVersionColumn]       = rowVersion;
            destinationOrderRow[destinationOrderTable.CanceledQuantityColumn] = canceledQuantity;
            destinationOrderRow[destinationOrderTable.CanceledTimeColumn]     = canceledTime;
            destinationOrderRow[destinationOrderTable.CreatedTimeColumn]      = createdTime;
            destinationOrderRow[destinationOrderTable.CreatedUserIdColumn]    = createdUserId;
            destinationOrderRow[destinationOrderTable.DestinationIdColumn]    = destinationId;
            destinationOrderRow[destinationOrderTable.ExternalId0Column]      = externalId0;
            destinationOrderRow[destinationOrderTable.IsCanceledByUserColumn] = isCanceledByUser;
            destinationOrderRow[destinationOrderTable.IsHiddenColumn]         = isHidden;
            destinationOrderRow[destinationOrderTable.LimitPriceColumn]       = limitPrice;
            destinationOrderRow[destinationOrderTable.ModifiedTimeColumn]     = modifiedTime;
            destinationOrderRow[destinationOrderTable.ModifiedUserIdColumn]   = modifiedUserId;
            destinationOrderRow[destinationOrderTable.OrderTypeCodeColumn]    = orderTypeCode;
            destinationOrderRow[destinationOrderTable.OrderedQuantityColumn]  = orderedQuantity;
            destinationOrderRow[destinationOrderTable.PriceTypeCodeColumn]    = priceTypeCode;
            destinationOrderRow[destinationOrderTable.StateCodeColumn]        = stateCode;
            destinationOrderRow[destinationOrderTable.StatusCodeColumn]       = statusCode;
            destinationOrderRow[destinationOrderTable.StopPriceColumn]        = stopPrice;
            destinationOrderRow[destinationOrderTable.TraderIdColumn]         = traderId;
            destinationOrderRow[destinationOrderTable.TimeInForceCodeColumn]  = timeInForceCode;
            destinationOrderRow[destinationOrderTable.WorkingOrderIdColumn]   = workingOrderId;
            adoTransaction.DataRows.Add(destinationOrderRow);
            // Update the record in the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"update ""DestinationOrder"" set ""RowVersion""=@rowVersion,""CanceledQuantity""=@canceledQuantity,""CanceledTime""=@canceledTime,""CreatedTime""=@createdTime,""CreatedUserId""=@createdUserId,""DestinationId""=@destinationId,""ExternalId0""=@externalId0,""IsCanceledByUser""=@isCanceledByUser,""IsHidden""=@isHidden,""LimitPrice""=@limitPrice,""ModifiedTime""=@modifiedTime,""ModifiedUserId""=@modifiedUserId,""OrderTypeCode""=@orderTypeCode,""OrderedQuantity""=@orderedQuantity,""PriceTypeCode""=@priceTypeCode,""StateCode""=@stateCode,""StatusCode""=@statusCode,""StopPrice""=@stopPrice,""TraderId""=@traderId,""TimeInForceCode""=@timeInForceCode,""WorkingOrderId""=@workingOrderId where ""DestinationOrderId""=@destinationOrderId");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@canceledQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, canceledQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@canceledTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, canceledTime));
            sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime));
            sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationOrderId));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@isCanceledByUser", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isCanceledByUser));
            sqlCommand.Parameters.Add(new SqlParameter("@isHidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isHidden));
            sqlCommand.Parameters.Add(new SqlParameter("@limitPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, limitPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId));
            sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@orderedQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderedQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@priceTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, priceTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@stateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode));
            sqlCommand.Parameters.Add(new SqlParameter("@stopPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stopPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@traderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, traderId));
            sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode));
            sqlCommand.Parameters.Add(new SqlParameter("@workingOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, workingOrderId));
            // Update the record in the SQL database.
            sqlCommand.ExecuteNonQuery();
        }
Example #10
0
        /// <summary>Inserts a DestinationOrder record.</summary>
        /// <param name="transaction">Commits or rejects a set of commands as a unit</param>
        /// <param name="canceledQuantity">The value for the CanceledQuantity column.</param>
        /// <param name="canceledTime">The value for the CanceledTime column.</param>
        /// <param name="createdTime">The value for the CreatedTime column.</param>
        /// <param name="createdUserId">The value for the CreatedUserId column.</param>
        /// <param name="destinationId">The value for the DestinationId column.</param>
        /// <param name="externalId0">The value for the ExternalId0 column.</param>
        /// <param name="isCanceledByUser">The value for the IsCanceledByUser column.</param>
        /// <param name="isHidden">The value for the IsHidden column.</param>
        /// <param name="limitPrice">The value for the LimitPrice column.</param>
        /// <param name="modifiedTime">The value for the ModifiedTime column.</param>
        /// <param name="modifiedUserId">The value for the ModifiedUserId column.</param>
        /// <param name="orderTypeCode">The value for the OrderTypeCode column.</param>
        /// <param name="orderedQuantity">The value for the OrderedQuantity column.</param>
        /// <param name="priceTypeCode">The value for the PriceTypeCode column.</param>
        /// <param name="stateCode">The value for the StateCode column.</param>
        /// <param name="statusCode">The value for the StatusCode column.</param>
        /// <param name="stopPrice">The value for the StopPrice column.</param>
        /// <param name="traderId">The value for the TraderId column.</param>
        /// <param name="timeInForceCode">The value for the TimeInForceCode column.</param>
        /// <param name="workingOrderId">The value for the WorkingOrderId column.</param>
        public static int Insert(
            AdoTransaction adoTransaction,
            SqlTransaction sqlTransaction,
            ref long rowVersion,
            object canceledQuantity,
            object canceledTime,
            System.DateTime createdTime,
            int createdUserId,
            int destinationId,
            object externalId0,
            object isCanceledByUser,
            object isHidden,
            object limitPrice,
            System.DateTime modifiedTime,
            int modifiedUserId,
            int orderTypeCode,
            decimal orderedQuantity,
            int priceTypeCode,
            int stateCode,
            int statusCode,
            object stopPrice,
            object traderId,
            int timeInForceCode,
            int workingOrderId)
        {
            // Accessor for the DestinationOrder Table.
            ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
            // Apply Defaults
            if ((canceledQuantity == null))
            {
                canceledQuantity = 0m;
            }
            if ((canceledTime == null))
            {
                canceledTime = System.DBNull.Value;
            }
            if ((externalId0 == null))
            {
                externalId0 = System.DBNull.Value;
            }
            if ((isCanceledByUser == null))
            {
                isCanceledByUser = false;
            }
            if ((isHidden == null))
            {
                isHidden = false;
            }
            if ((limitPrice == null))
            {
                limitPrice = System.DBNull.Value;
            }
            if ((stopPrice == null))
            {
                stopPrice = System.DBNull.Value;
            }
            if ((traderId == null))
            {
                traderId = System.DBNull.Value;
            }
            // Increment the row version
            rowVersion = ServerMarketData.RowVersion.Increment();
            // Insert the record into the ADO database.
            ServerMarketData.DestinationOrderRow destinationOrderRow = destinationOrderTable.NewDestinationOrderRow();
            destinationOrderRow[destinationOrderTable.RowVersionColumn]       = rowVersion;
            destinationOrderRow[destinationOrderTable.CanceledQuantityColumn] = canceledQuantity;
            destinationOrderRow[destinationOrderTable.CanceledTimeColumn]     = canceledTime;
            destinationOrderRow[destinationOrderTable.CreatedTimeColumn]      = createdTime;
            destinationOrderRow[destinationOrderTable.CreatedUserIdColumn]    = createdUserId;
            destinationOrderRow[destinationOrderTable.DestinationIdColumn]    = destinationId;
            destinationOrderRow[destinationOrderTable.ExternalId0Column]      = externalId0;
            destinationOrderRow[destinationOrderTable.IsCanceledByUserColumn] = isCanceledByUser;
            destinationOrderRow[destinationOrderTable.IsHiddenColumn]         = isHidden;
            destinationOrderRow[destinationOrderTable.LimitPriceColumn]       = limitPrice;
            destinationOrderRow[destinationOrderTable.ModifiedTimeColumn]     = modifiedTime;
            destinationOrderRow[destinationOrderTable.ModifiedUserIdColumn]   = modifiedUserId;
            destinationOrderRow[destinationOrderTable.OrderTypeCodeColumn]    = orderTypeCode;
            destinationOrderRow[destinationOrderTable.OrderedQuantityColumn]  = orderedQuantity;
            destinationOrderRow[destinationOrderTable.PriceTypeCodeColumn]    = priceTypeCode;
            destinationOrderRow[destinationOrderTable.StateCodeColumn]        = stateCode;
            destinationOrderRow[destinationOrderTable.StatusCodeColumn]       = statusCode;
            destinationOrderRow[destinationOrderTable.StopPriceColumn]        = stopPrice;
            destinationOrderRow[destinationOrderTable.TraderIdColumn]         = traderId;
            destinationOrderRow[destinationOrderTable.TimeInForceCodeColumn]  = timeInForceCode;
            destinationOrderRow[destinationOrderTable.WorkingOrderIdColumn]   = workingOrderId;
            destinationOrderTable.AddDestinationOrderRow(destinationOrderRow);
            adoTransaction.DataRows.Add(destinationOrderRow);
            // Insert the record into the SQL database.
            SqlCommand sqlCommand = new SqlCommand(@"insert ""DestinationOrder"" (""rowVersion"",""CanceledQuantity"",""CanceledTime"",""CreatedTime"",""CreatedUserId"",""DestinationId"",""DestinationOrderId"",""ExternalId0"",""IsCanceledByUser"",""IsHidden"",""LimitPrice"",""ModifiedTime"",""ModifiedUserId"",""OrderTypeCode"",""OrderedQuantity"",""PriceTypeCode"",""StateCode"",""StatusCode"",""StopPrice"",""TraderId"",""TimeInForceCode"",""WorkingOrderId"") values (@rowVersion,@canceledQuantity,@canceledTime,@createdTime,@createdUserId,@destinationId,@destinationOrderId,@externalId0,@isCanceledByUser,@isHidden,@limitPrice,@modifiedTime,@modifiedUserId,@orderTypeCode,@orderedQuantity,@priceTypeCode,@stateCode,@statusCode,@stopPrice,@traderId,@timeInForceCode,@workingOrderId)");

            sqlCommand.Connection  = sqlTransaction.Connection;
            sqlCommand.Transaction = sqlTransaction;
            sqlCommand.Parameters.Add(new SqlParameter("@rowVersion", SqlDbType.BigInt, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, rowVersion));
            sqlCommand.Parameters.Add(new SqlParameter("@canceledQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, canceledQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@canceledTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, canceledTime));
            sqlCommand.Parameters.Add(new SqlParameter("@createdTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdTime));
            sqlCommand.Parameters.Add(new SqlParameter("@createdUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, createdUserId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationId));
            sqlCommand.Parameters.Add(new SqlParameter("@destinationOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, destinationOrderRow[destinationOrderTable.DestinationOrderIdColumn]));
            sqlCommand.Parameters.Add(new SqlParameter("@externalId0", SqlDbType.NVarChar, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, externalId0));
            sqlCommand.Parameters.Add(new SqlParameter("@isCanceledByUser", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isCanceledByUser));
            sqlCommand.Parameters.Add(new SqlParameter("@isHidden", SqlDbType.Bit, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, isHidden));
            sqlCommand.Parameters.Add(new SqlParameter("@limitPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, limitPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedTime", SqlDbType.DateTime, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedTime));
            sqlCommand.Parameters.Add(new SqlParameter("@modifiedUserId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, modifiedUserId));
            sqlCommand.Parameters.Add(new SqlParameter("@orderTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@orderedQuantity", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, orderedQuantity));
            sqlCommand.Parameters.Add(new SqlParameter("@priceTypeCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, priceTypeCode));
            sqlCommand.Parameters.Add(new SqlParameter("@stateCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stateCode));
            sqlCommand.Parameters.Add(new SqlParameter("@statusCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, statusCode));
            sqlCommand.Parameters.Add(new SqlParameter("@stopPrice", SqlDbType.Decimal, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, stopPrice));
            sqlCommand.Parameters.Add(new SqlParameter("@traderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, traderId));
            sqlCommand.Parameters.Add(new SqlParameter("@timeInForceCode", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, timeInForceCode));
            sqlCommand.Parameters.Add(new SqlParameter("@workingOrderId", SqlDbType.Int, 0, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, workingOrderId));
            sqlCommand.ExecuteNonQuery();
            // Return Statements
            return(destinationOrderRow.DestinationOrderId);
        }
Example #11
0
        /// <summary>Inserts a DestinationOrder 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 DestinationOrder Table.
            ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
            // 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         externalDestinationOrderId = parameters["destinationOrderId"];
            string         externalDestinationId      = parameters["destinationId"];
            object         externalId0   = parameters["externalId0"].Value;
            object         isAdvertised  = parameters["isAdvertised"].Value;
            object         isAutoExecute = parameters["isAutoExecute"].Value;
            object         isCanceled    = parameters["isCanceled"].Value;
            object         isSteppedIn   = parameters["isSteppedIn"].Value;

            System.Decimal orderedQuantity         = parameters["orderedQuantity"];
            string         externalOrderTypeCode   = parameters["orderTypeCode"];
            string         externalPriceTypeCode   = parameters["priceTypeCode"];
            object         receivedTime            = parameters["receivedTime"].Value;
            string         externalSecurityId      = parameters["securityId"];
            object         externalSettlementId    = parameters["settlementId"].Value;
            object         targetPrice             = parameters["targetPrice"].Value;
            string         externalTimeInForceCode = parameters["timeInForceCode"];
            object         uploadedTime            = parameters["uploadedTime"].Value;
            string         externalWorkingOrderId  = parameters["workingOrderId"];
            // 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    destinationOrderId = External.DestinationOrder.FindKey(configurationId, "destinationOrderId", externalDestinationOrderId);
            int    orderTypeCode      = External.OrderType.FindRequiredKey(configurationId, "orderTypeCode", externalOrderTypeCode);
            int    destinationId      = External.Destination.FindRequiredKey(configurationId, "destinationId", externalDestinationId);
            int    priceTypeCode      = External.PriceType.FindRequiredKey(configurationId, "priceTypeCode", externalPriceTypeCode);
            int    securityId         = External.Security.FindRequiredKey(configurationId, "securityId", externalSecurityId);
            object settlementId       = External.Security.FindOptionalKey(configurationId, "settlementId", externalSettlementId);
            int    timeInForceCode    = External.TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
            int    workingOrderId     = External.WorkingOrder.FindRequiredKey(configurationId, "workingOrderId", externalWorkingOrderId);

            // All parameters from the xml file arrive as strings.  Any required or optional parameter needs to be converted to a
            // native type here.
            decimal quantityOrdered = Convert.ToDecimal(parameters["quantity"].Value);

            // Optional Parameters
            object isHidden = parameters["isHidden"] is MissingParameter ? (object)null :
                              Convert.ToBoolean(parameters["isHidden"].Value);
            object limitPrice = parameters["limitPrice"] is MissingParameter ? (object)null :
                                Convert.ToDecimal(parameters["limitPrice"].Value);
            object stopPrice = parameters["stopPrice"] is MissingParameter ? (object)null :
                               Convert.ToDecimal(parameters["stopPrice"].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;
            int      stateCode      = State.Initial;

            // 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 (destinationOrderId == 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.DestinationOrder.GetExternalKeyIndex(configurationId, "destinationOrderId");
                object[] externalIdArray  = new object[1];
                externalIdArray[externalKeyIndex] = externalDestinationOrderId;
                externalId0 = externalIdArray[0];

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, null, null, createdTime,
                                                                createdUserId, destinationId, externalId0, null, isHidden, limitPrice, modifiedTime, modifiedUserId,
                                                                orderTypeCode, orderedQuantity, priceTypeCode, stateCode, statusCode, stopPrice, createdUserId, timeInForceCode,
                                                                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.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId((int)destinationOrderId);
                rowVersion = ((long)(destinationOrderRow[destinationOrderTable.RowVersionColumn]));

                // Call the internal method to complete the operation.
                MarkThree.Guardian.Core.DestinationOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, null, null, createdTime,
                                                                createdUserId, destinationId, (int)destinationOrderId, externalId0, null, isHidden, limitPrice, modifiedTime,
                                                                modifiedUserId, orderedQuantity, orderTypeCode, priceTypeCode, stateCode, statusCode, stopPrice, modifiedUserId,
                                                                timeInForceCode, workingOrderId);
            }

            // Return values.
            parameters["rowVersion"] = rowVersion;
        }
Example #12
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));
                        }
                    }
                }
            }
        }
Example #13
0
 /// <summary>Loads a DestinationOrder 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 DestinationOrder Table.
     ServerMarketData.DestinationOrderDataTable destinationOrderTable = ServerMarketData.DestinationOrder;
     // Extract the parameters from the command batch.
     AdoTransaction adoTransaction = parameters["adoTransaction"];
     SqlTransaction sqlTransaction = parameters["sqlTransaction"];
     object configurationId = parameters["configurationId"].Value;
     object canceledQuantity = parameters["canceledQuantity"].Value;
     object canceledTime = parameters["canceledTime"].Value;
     System.DateTime createdTime = parameters["createdTime"];
     int createdUserId = parameters["createdUserId"];
     string externalDestinationId = parameters["destinationId"];
     object externalDestinationOrderId = parameters["destinationOrderId"].Value;
     object externalId0 = parameters["externalId0"].Value;
     object isCanceledByUser = parameters["isCanceledByUser"].Value;
     object isHidden = parameters["isHidden"].Value;
     object limitPrice = parameters["limitPrice"].Value;
     System.DateTime modifiedTime = parameters["modifiedTime"];
     int modifiedUserId = parameters["modifiedUserId"];
     int orderTypeCode = parameters["orderTypeCode"];
     decimal orderedQuantity = parameters["orderedQuantity"];
     string externalPriceTypeCode = parameters["priceTypeCode"];
     string externalStateCode = parameters["stateCode"];
     string externalStatusCode = parameters["statusCode"];
     object stopPrice = parameters["stopPrice"].Value;
     object externalTraderId = parameters["traderId"].Value;
     string externalTimeInForceCode = parameters["timeInForceCode"];
     string externalWorkingOrderId = parameters["workingOrderId"];
     // 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 destinationId = Destination.FindRequiredKey(configurationId, "destinationId", externalDestinationId);
     int destinationOrderId = DestinationOrder.FindKey(configurationId, "destinationOrderId", externalDestinationOrderId);
     int priceTypeCode = PriceType.FindRequiredKey(configurationId, "priceTypeCode", externalPriceTypeCode);
     int stateCode = State.FindRequiredKey(configurationId, "stateCode", externalStateCode);
     int statusCode = Status.FindRequiredKey(configurationId, "statusCode", externalStatusCode);
     object traderId = Trader.FindOptionalKey(configurationId, "traderId", externalTraderId);
     int timeInForceCode = TimeInForce.FindRequiredKey(configurationId, "timeInForceCode", externalTimeInForceCode);
     int workingOrderId = WorkingOrder.FindRequiredKey(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 ((destinationOrderId == 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 = DestinationOrder.GetExternalKeyIndex(configurationId, "destinationOrderId");
         object[] externalIdArray = new object[1];
         externalIdArray[externalKeyIndex] = externalDestinationOrderId;
         externalId0 = externalIdArray[0];
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.DestinationOrder.Insert(adoTransaction, sqlTransaction, ref rowVersion, canceledQuantity, canceledTime, createdTime, createdUserId, destinationId, externalId0, isCanceledByUser, isHidden, limitPrice, modifiedTime, modifiedUserId, orderTypeCode, orderedQuantity, priceTypeCode, stateCode, statusCode, stopPrice, traderId, timeInForceCode, 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.DestinationOrderRow destinationOrderRow = destinationOrderTable.FindByDestinationOrderId(destinationOrderId);
         rowVersion = ((long)(destinationOrderRow[destinationOrderTable.RowVersionColumn]));
         // Call the internal method to complete the operation.
         MarkThree.Guardian.Core.DestinationOrder.Update(adoTransaction, sqlTransaction, ref rowVersion, canceledQuantity, canceledTime, createdTime, createdUserId, destinationId, destinationOrderId, externalId0, isCanceledByUser, isHidden, limitPrice, modifiedTime, modifiedUserId, orderTypeCode, orderedQuantity, priceTypeCode, stateCode, statusCode, stopPrice, traderId, timeInForceCode, workingOrderId);
     }
     // Return values.
     parameters["rowVersion"] = rowVersion;
 }