Table of Contents

Class AsyncConnector<TPortfolioKey, TSecurityKey>

Namespace
ATAS.DataFeedsCore
Assembly
ATAS.DataFeedsCore.dll

Connector base that allows to use await to switch to the connector queue thread

This connector implements its own SynchronizationContext that allows to call await that will return to the connector thread. This works only if call is made from the connector queue thread

To move to the connector thread in the first place just call:

await SwitchToConnectorThreadAsync();

This class seals the OnProcess method.

public abstract class AsyncConnector<TPortfolioKey, TSecurityKey> : BaseConnector<AsyncConnectorMessage, TPortfolioKey, TSecurityKey>, IDataFeedConnector, ILoggerSource, ISupportChangePosition, IMarketDataPublisher where TPortfolioKey : notnull where TSecurityKey : notnull

Type Parameters

TPortfolioKey
TSecurityKey
Inheritance
object
BaseLoggerSource
BaseConnector<AsyncConnectorMessage, TPortfolioKey, TSecurityKey>
AsyncConnector<TPortfolioKey, TSecurityKey>
Implements
Extension Methods

Constructors

AsyncConnector()

Initializes the connector's synchronization context and sets the logging level of its queue to Info.

protected AsyncConnector()

Properties

ConnectorThreadId

Gets the ManagerThreadId of the Queue thread

public int ConnectorThreadId { get; }

Property Value

int

Methods

OnCancelOrder(Order, long)

Runs OnCancelOrderAsync(Order, long) without waiting for it; sealed.

protected override sealed void OnCancelOrder(Order order, long extId)

Parameters

order Order

The order to cancel.

extId long

The external id of the cancel request.

OnCancelOrderAsync(Order, long)

Sends the cancellation of an active order to the broker. A fault is logged and fails the cancellation.

protected abstract Task OnCancelOrderAsync(Order order, long extId)

Parameters

order Order

The order to cancel.

extId long

A new external id of the cancel request; it is mapped to the same order, so reports by either id find it.

Returns

Task

The task of the request.

OnConnectAsync()

Queues a setup message that makes the queue's thread the connector's thread (with the connector's synchronization context), then starts the connect attempt of the base. An override must call it.

protected override Task OnConnectAsync()

Returns

Task

The task of the connect attempt.

OnModifyOrder(Order, Order)

Runs OnModifyOrderAsync(Order, Order) without waiting for it, or modifies by cancel and register when it returns null; sealed.

protected override sealed void OnModifyOrder(Order order, Order newOrder)

Parameters

order Order

The order to modify.

newOrder Order

The order with the new parameters.

OnModifyOrderAsync(Order, Order)

Sends the replacement of an active order to the broker. Return null (the default) when the broker cannot modify orders: the order is then cancelled and the new one registered after the cancellation. A fault is logged and fails the modification.

Added in ATAS 8.0.15.

protected virtual Task? OnModifyOrderAsync(Order order, Order newOrder)

Parameters

order Order

The order to modify.

newOrder Order

The order with the new parameters; its external id is set.

Returns

Task

The task of the request, or null to modify by cancel and register.

OnProcess(AsyncConnectorMessage?)

Runs a queued callback on the connector's thread and signals a waiting Send. Sealed: an async connector does its work in async methods on the connector's thread instead of handling messages.

protected override sealed void OnProcess(AsyncConnectorMessage? message)

Parameters

message AsyncConnectorMessage

The queued callback; a setup message only makes the current thread the connector's thread.

Exceptions

InvalidOperationException

The message has no callback.

OnRegisterOrder(Order)

Runs OnRegisterOrderAsync(Order) without waiting for it; sealed.

protected override sealed void OnRegisterOrder(Order order)

Parameters

order Order

The order.

OnRegisterOrderAsync(Order)

Sends a new order to the broker. The order has its external id set; the connector reports its state with ProcessOrder. A fault is logged and fails the order.

protected abstract Task OnRegisterOrderAsync(Order filter)

Parameters

filter Order

The order.

Returns

Task

The task of the request.

OnSearchSecurities(SecurityFilter)

Runs OnSearchSecuritiesAsync(SecurityFilter) without waiting for it; sealed.

protected override sealed void OnSearchSecurities(SecurityFilter filter)

Parameters

filter SecurityFilter

The search filter.

OnSearchSecuritiesAsync(SecurityFilter)

Searches the broker for the securities matching the filter. The connector reports the result with RaiseSearchSecuritiesResult for the same filter; a fault is logged and reported as the result's error.

protected abstract Task OnSearchSecuritiesAsync(SecurityFilter filter)

Parameters

filter SecurityFilter

The search filter.

Returns

Task

The task of the request.

OnSubscribeMarketData(Security, SubscriptionType)

Runs OnSubscribeMarketDataAsync(Security, SubscriptionType) without waiting for it; sealed.

protected override sealed void OnSubscribeMarketData(Security security, SubscriptionType subscriptionTypes)

Parameters

security Security

The security.

subscriptionTypes SubscriptionType

The subscription types to request.

OnSubscribeMarketDataAsync(Security, SubscriptionType)

Subscribes to the market data of a security at the broker. Called on the thread that subscribes; the types are the ones nobody held before. A fault is logged and reported through SubscribeMarketDataResult.

protected abstract Task OnSubscribeMarketDataAsync(Security security, SubscriptionType subscriptionTypes)

Parameters

security Security

The security.

subscriptionTypes SubscriptionType

The subscription types to request.

Returns

Task

The task of the request.

OnUnsubscribeMarketData(Security, SubscriptionType)

Runs OnUnsubscribeMarketDataAsync(Security, SubscriptionType) without waiting for it; sealed.

protected override sealed void OnUnsubscribeMarketData(Security security, SubscriptionType subscriptionTypes)

Parameters

security Security

The security.

subscriptionTypes SubscriptionType

The subscription types to cancel.

OnUnsubscribeMarketDataAsync(Security, SubscriptionType)

Unsubscribes from the market data of a security at the broker. Called on the thread that unsubscribes; the types are the ones nobody holds anymore. A fault is logged and reported through UnsubscribeMarketDataResult.

protected abstract Task OnUnsubscribeMarketDataAsync(Security security, SubscriptionType subscriptionTypes)

Parameters

security Security

The security.

subscriptionTypes SubscriptionType

The subscription types to cancel.

Returns

Task

The task of the request.

ProcessMyTrade(long, string, Action<MyTrade>)

Creates an own trade of the order with the external id and raises NewMyTrades; the positions of the order's portfolio and security are updated by it. A trade id seen already is ignored, and a trade of an unknown order is skipped. Call it on the connector's thread.

protected void ProcessMyTrade(long extId, string tradeId, Action<MyTrade> update)

Parameters

extId long

The external (ATAS) id of the order.

tradeId string

The broker's id of the trade.

update Action<MyTrade>

Fills the new trade.

ProcessMyTrade(string, string, Action<MyTrade>)

Creates an own trade of the order with the broker's id and raises NewMyTrades; the positions of the order's portfolio and security are updated by it. A trade id seen already is ignored, and a trade of an unknown order is skipped. Call it on the connector's thread.

protected void ProcessMyTrade(string orderId, string tradeId, Action<MyTrade> update)

Parameters

orderId string

The broker's id of the order (Id).

tradeId string

The broker's id of the trade.

update Action<MyTrade>

Fills the new trade.

ProcessOrder(long, Action<Order>)

Updates the known order with the external id and raises OrderChanged, completing a pending action of the order when the update settles it. Unlike the base method it hides, it raises the events. Call it on the connector's thread.

Added in ATAS 8.0.15.

protected void ProcessOrder(long extId, Action<Order> update)

Parameters

extId long

The external (ATAS) id of the order.

update Action<Order>

Updates the order.

Exceptions

InvalidOperationException

No order has the external id.

ProcessOrder(TPortfolioKey, TSecurityKey, long, Action<bool, Order>)

Creates or updates the order with the external id and raises NewOrders or OrderChanged, completing a pending register, modify or cancel of the order when the update settles it. Call it on the connector's thread. The portfolio and the security must be known already: without a message to delay, an update for an unknown one is skipped.

protected void ProcessOrder(TPortfolioKey accountId, TSecurityKey securityId, long extId, Action<bool, Order> update)

Parameters

accountId TPortfolioKey

The connector's key of the order's portfolio.

securityId TSecurityKey

The connector's key of the order's security.

extId long

The external (ATAS) id of the order; an order the platform placed has it set already.

update Action<bool, Order>

Updates the order; gets whether the order is new to the connector.

ProcessPortfolio(TPortfolioKey, string, Action<Portfolio>)

Creates or updates a portfolio and raises NewPortfolios or PortfoliosChanged. Call it on the connector's thread.

protected void ProcessPortfolio(TPortfolioKey portfolioKey, string accountId, Action<Portfolio> update)

Parameters

portfolioKey TPortfolioKey

The connector's key of the portfolio.

accountId string

The account id of a new portfolio.

update Action<Portfolio>

Fills the portfolio.

ProcessPosition(TPortfolioKey, TSecurityKey, Func<bool, ISecurityPositionManager, bool>)

Creates or updates the position of a portfolio in a security and raises NewPositions or PositionsChanged. Call it on the connector's thread. The portfolio and the security must be known already: without a message to delay, an update for an unknown one is skipped.

protected void ProcessPosition(TPortfolioKey portfolioKey, TSecurityKey securityId, Func<bool, ISecurityPositionManager, bool> update)

Parameters

portfolioKey TPortfolioKey

The connector's key of the portfolio.

securityId TSecurityKey

The connector's key of the security.

update Func<bool, ISecurityPositionManager, bool>

Updates the position through its manager; gets whether the position is new and returns whether it changed. A new position is raised in any case.

SwitchToConnectorThreadAsync()

Await it to switch to the connector queue thread, does nothing if we on the connector thread already

public AsyncConnector<TPortfolioKey, TSecurityKey>.AsyncAwaiterFacade SwitchToConnectorThreadAsync()

Returns

AsyncConnector<TPortfolioKey, TSecurityKey>.AsyncAwaiterFacade

WaitConnectorQueueAsync()

Schedules continuation when all other tasks are done on connector's queue (adds a task itself to the end of the queue)

public AsyncConnector<TPortfolioKey, TSecurityKey>.AsyncAwaiterQueueFacade WaitConnectorQueueAsync()

Returns

AsyncConnector<TPortfolioKey, TSecurityKey>.AsyncAwaiterQueueFacade