StrategyEngine

StockSharp.Algo.Strategies

State machine + message processing. Handles ProcessState transitions and market data routing to PnLManager.

Konstruktoren

StrategyEngine
public StrategyEngine(IStrategyHost host, IPnLManager pnlManager)
strategyEngine = StrategyEngine(host, pnlManager)

Initializes a new instance of the StrategyEngine.

host
Strategy host.
pnlManager
PnL manager.

Eigenschaften

CanFinalStop
public Func<bool> CanFinalStop { get; set; }
value = strategyEngine.CanFinalStop
strategyEngine.CanFinalStop = value

Gate for the final Stopping -> Stopped transition. While it returns the strategy stays in Stopping (e.g. outstanding rules under WaitRulesOnStop). When unset the transition is never gated.

LastPnLRefreshTime
public DateTime LastPnLRefreshTime { get; }
value = strategyEngine.LastPnLRefreshTime

Market time of the last unrealized-PnL refresh. The next one is due UnrealizedPnLInterval after it.

ProcessState
public ProcessStates ProcessState { get; }
value = strategyEngine.ProcessState

Current process state.

UnrealizedPnLInterval
public TimeSpan UnrealizedPnLInterval { get; set; }
value = strategyEngine.UnrealizedPnLInterval
strategyEngine.UnrealizedPnLInterval = value

Interval for unrealized PnL refresh. The default value is 1 minute, applied until the public UnrealizedPnLInterval setter runs.

Methoden

ForceStop
public void ForceStop()
strategyEngine.ForceStop()

Force state to Stopped (for reset).

OnMessage
public void OnMessage(Message message)
strategyEngine.OnMessage(message)

Process incoming message — state transitions + market data routing.

OnMessageAsync
public ValueTask OnMessageAsync(Message message, CancellationToken cancellationToken)
result = strategyEngine.OnMessageAsync(message, cancellationToken)

Process incoming message asynchronously.

message
Incoming message.
cancellationToken
Cancellation token.

Rückgabe: A task representing message processing.

RequestStartAsync
public ValueTask RequestStartAsync(CancellationToken cancellationToken)
result = strategyEngine.RequestStartAsync(cancellationToken)

Request strategy start. Sends state change message through host.

RequestStopAsync
public ValueTask RequestStopAsync(CancellationToken cancellationToken)
result = strategyEngine.RequestStopAsync(cancellationToken)

Request strategy stop. Sends state change message through host.

SetPnLManager
public void SetPnLManager(IPnLManager pnlManager)
strategyEngine.SetPnLManager(pnlManager)

Swap the PnL manager used for market-data routing. Used when PnLManager is reassigned so the engine routes quotes/ticks into the new manager.

pnlManager
The new PnL manager.
TryFinalStopAsync
public ValueTask TryFinalStopAsync(CancellationToken cancellationToken)
result = strategyEngine.TryFinalStopAsync(cancellationToken)

Attempt the final Stopping -> Stopped transition, honouring CanFinalStop. While the gate denies it the strategy stays in Stopping; the method is re-driven once the gating condition clears (e.g. on rule completion).

Ereignisse

CurrentPriceUpdated
public event Action<SecurityId, decimal, DateTime, DateTime> CurrentPriceUpdated
strategyEngine.CurrentPriceUpdated += handler

Fires when current price updates from market data.

PnLRefreshRequired
public event Action<DateTime> PnLRefreshRequired
strategyEngine.PnLRefreshRequired += handler

Fires when PnL should be recalculated.

StateChanged
public event Action<ProcessStates> StateChanged
strategyEngine.StateChanged += handler

Fires when ProcessState changes.