Files
StockSharp/Messages/OrderMessage.cs
T
mika@stocksharp.com 94f38b440e Add IOwnerMessage carrying numeric owner identity on messages
Introduce IOwnerMessage with OwnerUserId / OwnerPortfolioId — the numeric
primary keys of the owning user and portfolio. Implement it on OrderMessage,
ExecutionMessage, PositionChangeMessage and PortfolioMessage, copying both
fields in their CopyTo so the identity survives Clone. Order subtypes
(register/replace/cancel/group-cancel and order-status) inherit it from
OrderMessage, and PortfolioLookupMessage inherits it from PortfolioMessage.

This lets a downstream carry the owner identity on the message itself rather
than in an external instance-keyed side table that was lost on a clone.
2026-06-22 17:08:57 +03:00

159 lines
4.4 KiB
C#

namespace StockSharp.Messages;
/// <summary>
/// A message containing info about the order.
/// </summary>
/// <remarks>
/// Initialize <see cref="OrderMessage"/>.
/// </remarks>
/// <param name="type">Message type.</param>
[DataContract]
[Serializable]
public abstract class OrderMessage(MessageTypes type) : SecurityMessage(type),
ITransactionIdMessage, IPortfolioNameMessage, IClientCodeMessage, IBrokerCodeMessage, IStrategyIdMessage, IOwnerMessage
{
/// <inheritdoc />
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.TransactionKey,
Description = LocalizedStrings.TransactionIdKey,
GroupName = LocalizedStrings.GeneralKey)]
public long TransactionId { get; set; }
/// <inheritdoc />
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.PortfolioKey,
Description = LocalizedStrings.OrderPortfolioNameKey,
GroupName = LocalizedStrings.GeneralKey)]
public string PortfolioName { get; set; }
/// <summary>
/// Order type.
/// </summary>
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.OrderTypeKey,
Description = LocalizedStrings.OrderTypeDescKey,
GroupName = LocalizedStrings.GeneralKey)]
public OrderTypes? OrderType { get; set; }
/// <summary>
/// User's order ID.
/// </summary>
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.UserIdKey,
Description = LocalizedStrings.UserOrderIdKey,
GroupName = LocalizedStrings.GeneralKey)]
public string UserOrderId { get; set; }
/// <inheritdoc />
[DataMember]
public string StrategyId { get; set; }
/// <summary>
/// Broker firm code.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.BrokerKey,
Description = LocalizedStrings.BrokerCodeKey,
GroupName = LocalizedStrings.GeneralKey)]
public string BrokerCode { get; set; }
/// <summary>
/// Client code assigned by the broker.
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.ClientCodeKey,
Description = LocalizedStrings.ClientCodeDescKey,
GroupName = LocalizedStrings.GeneralKey)]
public string ClientCode { get; set; }
/// <summary>
/// Order condition (e.g., stop- and algo- orders parameters).
/// </summary>
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.ConditionKey,
Description = LocalizedStrings.OrderConditionDescKey,
GroupName = LocalizedStrings.GeneralKey)]
[XmlIgnore]
public OrderCondition Condition { get; set; }
/// <summary>
/// Placed order comment.
/// </summary>
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.CommentKey,
Description = LocalizedStrings.OrderCommentKey,
GroupName = LocalizedStrings.GeneralKey)]
public string Comment { get; set; }
/// <summary>
/// Margin mode.
/// </summary>
[DataMember]
[Display(
ResourceType = typeof(LocalizedStrings),
Name = LocalizedStrings.MarginKey,
Description = LocalizedStrings.MarginModeKey,
GroupName = LocalizedStrings.GeneralKey)]
public MarginModes? MarginMode { get; set; }
/// <inheritdoc />
public long OwnerUserId { get; set; }
/// <inheritdoc />
public long OwnerPortfolioId { get; set; }
/// <summary>
/// Copy the message into the <paramref name="destination" />.
/// </summary>
/// <param name="destination">The object, to which copied information.</param>
public void CopyTo(OrderMessage destination)
{
base.CopyTo(destination);
destination.TransactionId = TransactionId;
destination.PortfolioName = PortfolioName;
destination.OrderType = OrderType;
destination.UserOrderId = UserOrderId;
destination.StrategyId = StrategyId;
destination.BrokerCode = BrokerCode;
destination.ClientCode = ClientCode;
destination.Condition = Condition?.Clone();
destination.Comment = Comment;
destination.MarginMode = MarginMode;
destination.OwnerUserId = OwnerUserId;
destination.OwnerPortfolioId = OwnerPortfolioId;
}
/// <inheritdoc />
public override string ToString()
{
var str = base.ToString() + $",TransId={TransactionId},OrdType={OrderType},Pf={PortfolioName}(ClCode={ClientCode}),Cond={Condition},MR={MarginMode}";
if (!Comment.IsEmpty())
str += $",Comment={Comment}";
if (!UserOrderId.IsEmpty())
str += $",UID={UserOrderId}";
if (!StrategyId.IsEmpty())
str += $",Strategy={StrategyId}";
if (!BrokerCode.IsEmpty())
str += $",BrID={BrokerCode}";
return str;
}
}