Table of Contents

Class OrderInterceptor

Namespace
ATAS.Indicators.Trading
Assembly
ATAS.Indicators.dll

Base class of an order interceptor written in a custom assembly: a rule that sees every trading operation of the platform before it reaches the broker and may allow or reject it — a daily loss limit, a maximum size, trading hours, a cool-down after a loss, a check against a server of a prop firm. Derive from it, mark the class with OrderInterceptorAttribute, give it a public parameterless constructor and override OnCheckAsync(TradeOperation, CancellationToken); the other hooks are optional.

Not in ATAS 8.0.15 yet: available from the next version.

[Obfuscation(Feature = "renaming", ApplyToMembers = true, Exclude = true)]
public abstract class OrderInterceptor
Inheritance
object
OrderInterceptor
Extension Methods

Remarks

A newly installed interceptor is switched off: the trader enables it in the list of order interceptors, where the order of the list, the timeout and what happens when the interceptor cannot answer are set too. The platform keeps one instance of an enabled interceptor for the whole session, whatever panels or workspaces are open.

The platform never calls one instance concurrently: checks, reports, completions and settings changes are queued and delivered one at a time in the order they happened, on a thread-pool thread (never the thread of a window or of a data feed), so the interceptor needs no locks for its own fields.

Public read/write properties are the interceptor's settings: they are shown in its settings window (use [Display] for names, groups and order, [Browsable(false)] to hide one) and saved by the platform. OnSettingsChanged() is called after the trader changed them.

An exception thrown by a hook, or a check that does not answer within the timeout, counts against the interceptor; after five within a minute the platform stops the instance and restarts it later. While an enabled interceptor cannot answer, the trader's choice decides: reject every operation (the default) or let them pass.

An interceptor runs inside the platform with the trader's rights: it is a discipline and risk tool, not a guarantee against the trader. Rules that must hold against the trader (prop-firm challenges, compliance) must also be enforced by the broker or a server.

Constructors

OrderInterceptor()

Initializes the interceptor. The platform creates it with its parameterless constructor and starts it afterwards, so do not use Context here.

protected OrderInterceptor()

Properties

Context

The state of the accounts and the platform log. Available from OnInitialize() on.

protected IOrderInterceptorContext Context { get; }

Property Value

IOrderInterceptorContext

Exceptions

InvalidOperationException

The interceptor is not started yet.

Methods

OnCheckAsync(TradeOperation, CancellationToken)

Decides an operation before it is sent: return Allow or Reject(string). The first interceptor of the list that rejects ends the check; the operation is then not sent and the trader sees the reason. Only operations with IsRejectable are passed here.

protected abstract ValueTask<OrderCheckResult> OnCheckAsync(TradeOperation operation, CancellationToken token)

Parameters

operation TradeOperation

The operation.

token CancellationToken

Cancelled when the interceptor's timeout is over; the operation is then decided without it.

Returns

ValueTask<OrderCheckResult>

The decision. A null result counts as a failure of the interceptor.

OnDispose()

The platform stops using this instance: the trader switched the interceptor off, it was stopped after failures, its library was reloaded, or the platform exits. Called exactly once for every instance whose constructor completed, after its last running call returned; no other method is called afterwards. An exception thrown here is logged and ignored.

protected virtual void OnDispose()

OnInitialize()

Called once per instance when it starts, after its saved settings were restored. Context is available from here on. Throw to refuse the settings (for example, a limit that is not set): the instance does not start and the trader sees the message.

protected virtual void OnInitialize()

OnOperationCompleted(OperationOutcome)

Reports what happened to an operation this interceptor allowed: called once for each, also when the operation was not sent after all. An interceptor that reserves a limit when it allows an operation releases it here.

protected virtual void OnOperationCompleted(OperationOutcome outcome)

Parameters

outcome OperationOutcome

The outcome.

Remarks

Only an answer given within the timeout counts as allowing: a check that answers after its token was cancelled gets no completion, so do not reserve anything after the token is cancelled. When the instance is disposed while operations it allowed are still being decided or sent, their completions are not delivered: release what is still reserved in OnDispose() (a new instance starts from the state of the accounts).

OnOperationObserved(TradeOperation)

Reports an operation the interceptor could not reject: a close, Go flat, or a protective order of the platform. Called after the operation was sent.

protected virtual void OnOperationObserved(TradeOperation operation)

Parameters

operation TradeOperation

The operation.

OnSettingsChanged()

Called after the trader changed the settings (and once after OnInitialize()).

protected virtual void OnSettingsChanged()