public void Initialize(ClientMarketData.OrderRow orderRow) { this.orderId = orderRow.OrderId; this.transactionType = (TransactionType)orderRow.TransactionTypeCode; this.tif = (TIF)orderRow.TimeInForceCode; this.pricedAt = (PricedAt)orderRow.OrderTypeCode; this.quantity = orderRow.Quantity; this.price1 = orderRow.IsPrice1Null() ? (object)null : orderRow.Price1; this.price2 = orderRow.IsPrice2Null() ? (object)null : orderRow.Price2; }
/// <summary> /// Creates a proposed order record. /// </summary> /// <param name="proposedOrderId">The primary identifer of the record.</param> /// <param name="position">Identifies the account/security/position type code for the order.</param> /// <param name="tif">Time in Force</param> /// <param name="pricedAt">How the order is priced.</param> /// <param name="quantity">The number of units being purchased.</param> /// <param name="price1">The limit/stop price.</param> /// <param name="price2">The stop limit price.</param> public ProposedOrder(int proposedOrderId, Position position, TIF tif, PricedAt pricedAt, decimal quantity, object price1, object price2) { // Initialize the object. this.proposedOrderId = proposedOrderId; this.position = position; this.transactionType = transactionType; this.tif = tif; this.pricedAt = pricedAt; this.quantity = quantity; this.price1 = price1; this.price2 = price2; }
/// <summary> /// Executes a block order. /// </summary> /// <param name="configurationId">Defines which external fields are used to identify an object.</param> /// <param name="brokerId">The destination broker for the order.</param> /// <param name="tif">Specifies a time limit on the order.</param> /// <param name="quantity">The number of units to be traded.</param> /// <param name="pricedAt">Specifies how the order is to be priced.</param> /// <param name="limitPrice">A limit price for the order.</param> public void Execute(Broker broker, TIF tif, decimal quantity, PricedAt pricedAt, decimal limitPrice) { RemoteBatch remoteBatch = new RemoteBatch(); RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Trading"); RemoteType remoteType = remoteAssembly.Types.Add("Shadows.WebService.Trading.BlockOrder"); RemoteMethod remoteMethod = remoteType.Methods.Add("Execute"); remoteMethod.Parameters.Add("blockOrderId", this.blockOrderId); remoteMethod.Parameters.Add("brokerId", broker.BrokerId); remoteMethod.Parameters.Add("timeInForceCode", (int)tif); remoteMethod.Parameters.Add("quantity", quantity); remoteMethod.Parameters.Add("orderTypeCode", (int)pricedAt); remoteMethod.Parameters.Add("price1", limitPrice); ClientMarketData.Execute(remoteBatch); }
/// <summary> /// Creates a proposed order record. /// </summary> /// <param name="proposedOrderRow">A proposed order record from the primary ADO database.</param> /// <returns>A ProposedOrder record based on the ADO record.</returns> internal static ProposedOrder Make(ClientMarketData.ProposedOrderRow proposedOrderRow) { // Initialize the object DataRowVersion dataRowVersion = proposedOrderRow.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Current; // Extract the data from the ADO record. int proposedOrderId = (int)proposedOrderRow[ClientMarketData.ProposedOrder.ProposedOrderIdColumn, dataRowVersion]; TransactionType transactionType = (TransactionType)proposedOrderRow[ClientMarketData.ProposedOrder.TransactionTypeCodeColumn, dataRowVersion]; int accountId = (int)proposedOrderRow[ClientMarketData.ProposedOrder.AccountIdColumn, dataRowVersion]; int securityId = (int)proposedOrderRow[ClientMarketData.ProposedOrder.SecurityIdColumn, dataRowVersion]; int positionTypeCode = Common.TransactionType.GetPosition((int)transactionType); Position position = Position.Make(accountId, securityId, positionTypeCode); TIF tif = (TIF)proposedOrderRow[ClientMarketData.ProposedOrder.TimeInForceCodeColumn, dataRowVersion]; PricedAt pricedAt = (PricedAt)proposedOrderRow[ClientMarketData.ProposedOrder.OrderTypeCodeColumn, dataRowVersion]; decimal quantity = (decimal)proposedOrderRow[ClientMarketData.ProposedOrder.QuantityColumn, dataRowVersion]; object price1 = proposedOrderRow[ClientMarketData.ProposedOrder.Price1Column, dataRowVersion]; object price2 = proposedOrderRow[ClientMarketData.ProposedOrder.Price2Column, dataRowVersion]; // Create a new record based on the data extracted from the ADO database. return(new ProposedOrder(proposedOrderId, position, tif, pricedAt, quantity, price1, price2)); }
/// <summary> /// Adds an order to a block order. /// </summary> /// <param name="configurationId">Defines which external fields are used to identify an object.</param> /// <param name="accountId">The destination account for the order.</param> /// <param name="tif">Specifies a time limit on the order.</param> /// <param name="quantity">The number of units to be traded.</param> /// <param name="pricedAt">Specifies how the order is to be priced.</param> /// <param name="limitPrice">A limit price for the order.</param> /// <returns>An internal identifier used to track the order.</returns> public int AddOrder(Account account, TIF tif, decimal quantity, PricedAt pricedAt, decimal limitPrice) { RemoteBatch remoteBatch = new RemoteBatch(); RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Trading"); RemoteType remoteType = remoteAssembly.Types.Add("Shadows.WebService.Trading.Order"); RemoteMethod remoteMethod = remoteType.Methods.Add("Insert"); remoteMethod.Parameters.Add("orderId", DataType.Int, Direction.ReturnValue); remoteMethod.Parameters.Add("blockOrderId", this.blockOrderId); remoteMethod.Parameters.Add("accountId", account.AccountId); remoteMethod.Parameters.Add("securityId", this.Security.SecurityId); remoteMethod.Parameters.Add("settlementId", this.Settlement.SecurityId); remoteMethod.Parameters.Add("timeInForceCode", (int)tif); remoteMethod.Parameters.Add("transactionTypeCode", (int)this.transactionType); remoteMethod.Parameters.Add("orderTypeCode", (int)pricedAt); remoteMethod.Parameters.Add("quantity", quantity); remoteMethod.Parameters.Add("price1", limitPrice); remoteMethod.Parameters.Add("price2", limitPrice); ClientMarketData.Execute(remoteBatch); return (int)remoteMethod.Parameters["orderId"].Value; }
public Order(Account account, Security security, TransactionType transactionType, TIF tif, PricedAt pricedAt, decimal quantity, decimal limitPrice, decimal stopLimitPrice) { Initialize(account, security, transactionType, tif, pricedAt, quantity, limitPrice, stopLimitPrice); }
public void Initialize(Account account, Security security, TransactionType transactionType, TIF tif, PricedAt pricedAt, decimal quantity, object price1, object price2) { // Create a block order on the server. RemoteBatch remoteBatch = new RemoteBatch(); RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Trading"); RemoteType remoteType = remoteAssembly.Types.Add("Shadows.WebService.Trading.Order"); RemoteMethod remoteMethod = remoteType.Methods.Add("Insert"); remoteMethod.Parameters.Add("orderId", DataType.Int, Direction.ReturnValue); remoteMethod.Parameters.Add("accountId", account.AccountId); remoteMethod.Parameters.Add("securityId", security.SecurityId); remoteMethod.Parameters.Add("settlementId", security.SettlementId); remoteMethod.Parameters.Add("transactionTypeCode", (int)transactionType); remoteMethod.Parameters.Add("timeInForceCode", (int)tif); remoteMethod.Parameters.Add("orderTypeCode", (int)pricedAt); remoteMethod.Parameters.Add("quantity", quantity); remoteMethod.Parameters.Add("price1", price1 == null ? (object)DBNull.Value : price1); remoteMethod.Parameters.Add("price2", price2 == null ? (object)DBNull.Value : price2); ClientMarketData.Execute(remoteBatch); // Now that the block order is created, construct the in-memory version of the record. int orderId = (int)remoteMethod.Parameters["orderId"].Value; try { // Lock the tables. Debug.Assert(!ClientMarketData.AreLocksHeld); ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.OrderLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.OrderRow orderRow = ClientMarketData.Order.FindByOrderId(orderId); if (orderRow == null) { throw new Exception(String.Format("Order {0} doesn't exist", orderId)); } Initialize(orderRow); } finally { // Release the table locks. if (ClientMarketData.AccountLock.IsReaderLockHeld) { ClientMarketData.AccountLock.ReleaseReaderLock(); } if (ClientMarketData.OrderLock.IsReaderLockHeld) { ClientMarketData.OrderLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.SecurityLock.IsReaderLockHeld) { ClientMarketData.SecurityLock.ReleaseReaderLock(); } Debug.Assert(!ClientMarketData.AreLocksHeld); } }