mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 00:21:31 +00:00
The manager already indexes its stops by security for CheckPrice, but the interface offered no way to read that index, so every caller that needs to walk the stops of one instrument had to keep a second index of its own over the very same objects. GetStopIds hands out the transaction ids resting on a security, copied out under the same lock every other operation runs under and filtered to the stops that are still registered, since CheckPrice prunes its per-security list lazily.
134 lines
4.1 KiB
C#
134 lines
4.1 KiB
C#
namespace StockSharp.MatchingEngine;
|
|
|
|
/// <summary>
|
|
/// Stop order information.
|
|
/// </summary>
|
|
public class StopOrderInfo
|
|
{
|
|
/// <summary>
|
|
/// Transaction ID.
|
|
/// </summary>
|
|
public long TransactionId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Security ID.
|
|
/// </summary>
|
|
public SecurityId SecurityId { get; set; }
|
|
|
|
/// <summary>
|
|
/// Order side.
|
|
/// </summary>
|
|
public Sides Side { get; set; }
|
|
|
|
/// <summary>
|
|
/// Order volume.
|
|
/// </summary>
|
|
public decimal Volume { get; set; }
|
|
|
|
/// <summary>
|
|
/// Portfolio name.
|
|
/// </summary>
|
|
public string PortfolioName { get; set; }
|
|
|
|
/// <summary>
|
|
/// Stop activation price.
|
|
/// </summary>
|
|
public decimal StopPrice { get; set; }
|
|
|
|
/// <summary>
|
|
/// Limit price for stop-limit orders. <see langword="null"/> means market order.
|
|
/// </summary>
|
|
public decimal? LimitPrice { get; set; }
|
|
|
|
/// <summary>
|
|
/// Whether this is a trailing stop.
|
|
/// </summary>
|
|
public bool IsTrailing { get; set; }
|
|
|
|
/// <summary>
|
|
/// Trailing offset from extremum.
|
|
/// </summary>
|
|
public decimal? TrailingOffset { get; set; }
|
|
|
|
/// <summary>
|
|
/// Best seen price for trailing stop (max for sell, min for buy).
|
|
/// </summary>
|
|
public decimal? BestSeenPrice { get; set; }
|
|
|
|
/// <summary>
|
|
/// When <see langword="true"/>, trigger logic is inverted (TakeProfit mode):
|
|
/// Buy triggers when price <= StopPrice, Sell triggers when price >= StopPrice.
|
|
/// </summary>
|
|
public bool InvertTrigger { get; set; }
|
|
|
|
/// <summary>
|
|
/// When <see langword="true"/>, <see cref="LimitPrice"/> is a percent of <see cref="StopPrice"/>;
|
|
/// the absolute limit price is computed at trigger time
|
|
/// (Buy: stop*(1+pct/100), Sell: stop*(1-pct/100)).
|
|
/// </summary>
|
|
public bool IsLimitPricePercent { get; set; }
|
|
|
|
/// <summary>
|
|
/// When <see langword="true"/>, <see cref="TrailingOffset"/> is a percent of the
|
|
/// high/low watermark; the stop price is recomputed on each tick as
|
|
/// Sell: high*(1-pct/100), Buy: low*(1+pct/100).
|
|
/// </summary>
|
|
public bool IsTrailingOffsetPercent { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Triggered stop order result.
|
|
/// </summary>
|
|
/// <param name="Info">Stop order info.</param>
|
|
/// <param name="TriggerPrice">The price that triggered the stop.</param>
|
|
/// <param name="ResultingOrder">The order to submit to the matcher.</param>
|
|
public record StopOrderTrigger(StopOrderInfo Info, decimal TriggerPrice, OrderRegisterMessage ResultingOrder);
|
|
|
|
/// <summary>
|
|
/// Interface for managing stop orders.
|
|
/// </summary>
|
|
public interface IStopOrderManager
|
|
{
|
|
/// <summary>
|
|
/// Register a new stop order.
|
|
/// </summary>
|
|
void Register(StopOrderInfo info);
|
|
|
|
/// <summary>
|
|
/// Cancel a stop order.
|
|
/// </summary>
|
|
/// <param name="transactionId">Transaction ID of the stop order.</param>
|
|
/// <param name="info">Cancelled stop order info.</param>
|
|
/// <returns><see langword="true"/> if the stop order was found and cancelled.</returns>
|
|
bool Cancel(long transactionId, out StopOrderInfo info);
|
|
|
|
/// <summary>
|
|
/// Atomically replace an existing stop order with a new one.
|
|
/// </summary>
|
|
/// <param name="origTransactionId">Transaction ID of the stop order to replace.</param>
|
|
/// <param name="newInfo">New stop order info.</param>
|
|
/// <returns><see langword="true"/> if the old stop order was found and replaced.</returns>
|
|
bool Replace(long origTransactionId, StopOrderInfo newInfo);
|
|
|
|
/// <summary>
|
|
/// Check price against all registered stop orders for the given security.
|
|
/// </summary>
|
|
/// <param name="securityId">Security ID.</param>
|
|
/// <param name="price">Current market price.</param>
|
|
/// <param name="time">Current time.</param>
|
|
/// <returns>List of triggered stop orders with resulting orders to submit.</returns>
|
|
IReadOnlyList<StopOrderTrigger> CheckPrice(SecurityId securityId, decimal price, DateTime time);
|
|
|
|
/// <summary>
|
|
/// Get the stop orders resting on the given security.
|
|
/// </summary>
|
|
/// <param name="securityId">Security ID.</param>
|
|
/// <returns>Transaction IDs of the stop orders registered for the security, empty when none rest on it.</returns>
|
|
IReadOnlyList<long> GetStopIds(SecurityId securityId);
|
|
|
|
/// <summary>
|
|
/// Clear all stop orders.
|
|
/// </summary>
|
|
void Clear();
|
|
}
|