StrategyEngine
State machine + message processing. Handles ProcessState transitions and market data routing to PnLManager.
Construtores
public StrategyEngine(IStrategyHost host, IPnLManager pnlManager)
strategyEngine = StrategyEngine(host, pnlManager)
Initializes a new instance of the StrategyEngine.
- host
- Strategy host.
- pnlManager
- PnL manager.
Propriedades
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.
public DateTime LastPnLRefreshTime { get; }
value = strategyEngine.LastPnLRefreshTime
Market time of the last unrealized-PnL refresh. The next one is due UnrealizedPnLInterval after it.
public ProcessStates ProcessState { get; }
value = strategyEngine.ProcessState
Current process state.
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.
Métodos
public void OnMessage(Message message)
strategyEngine.OnMessage(message)
Process incoming message — state transitions + market data routing.
public ValueTask OnMessageAsync(Message message, CancellationToken cancellationToken)
result = strategyEngine.OnMessageAsync(message, cancellationToken)
Process incoming message asynchronously.
- message
- Incoming message.
- cancellationToken
- Cancellation token.
Retorna: A task representing message processing.
public ValueTask RequestStartAsync(CancellationToken cancellationToken)
result = strategyEngine.RequestStartAsync(cancellationToken)
Request strategy start. Sends state change message through host.
public ValueTask RequestStopAsync(CancellationToken cancellationToken)
result = strategyEngine.RequestStopAsync(cancellationToken)
Request strategy stop. Sends state change message through host.
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.
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).
Eventos
public event Action<SecurityId, decimal, DateTime, DateTime> CurrentPriceUpdated
strategyEngine.CurrentPriceUpdated += handler
Fires when current price updates from market data.
public event Action<DateTime> PnLRefreshRequired
strategyEngine.PnLRefreshRequired += handler
Fires when PnL should be recalculated.
public event Action<ProcessStates> StateChanged
strategyEngine.StateChanged += handler
Fires when ProcessState changes.