Table of Contents

Class MessageAdapter

Namespace
StockSharp.Messages
Assembly
StockSharp.Messages.dll

The base adapter converts messages Message to the command of the trading system and back.

public abstract class MessageAdapter : BaseLogReceiver, IMessageAdapter, IMessageTransport, IPersistable, ILogReceiver, ILogSource, IDisposable, ICloneable<IMessageAdapter>, ICloneable, INotifyPropertyChanged
Inheritance
MessageAdapter
Implements
Derived
Inherited Members
Extension Methods

Constructors

MessageAdapter(IdGenerator)

Initialize MessageAdapter.

protected MessageAdapter(IdGenerator transactionIdGenerator)

Parameters

transactionIdGenerator IdGenerator

Transaction id generator.

Properties

AssociatedBoards

The adapter can process subscription only with instruments associated with the specified board.

[Browsable(false)]
public virtual string[] AssociatedBoards { get; }

Property Value

string[]

CandlesBuildFrom

Possible options for candles building.

[Browsable(false)]
public virtual IEnumerable<Level1Fields> CandlesBuildFrom { get; }

Property Value

IEnumerable<Level1Fields>

Categories

Message adapter categories.

[Browsable(false)]
public virtual MessageAdapterCategories Categories { get; }

Property Value

MessageAdapterCategories

CheckTimeFrameByRequest

Check possible time-frame by request.

[Browsable(false)]
public virtual bool CheckTimeFrameByRequest { get; }

Property Value

bool

DisconnectTimeout

Gets the timeout to wait for a graceful disconnect.

[Browsable(false)]
public virtual TimeSpan DisconnectTimeout { get; }

Property Value

TimeSpan

EnqueueSubscriptions

Enqueue subscriptions.

[Display(ResourceType = typeof(LocalizedStrings), Name = "EnqueueSubscriptions", Description = "EnqueueSubscriptionsDesc", GroupName = "Adapters", Order = 301)]
public virtual bool EnqueueSubscriptions { get; set; }

Property Value

bool

Remarks

Do not send new request before received confirmation for previous.

ExtraSetup

The adapter requires extra setup.

[Browsable(false)]
public virtual bool ExtraSetup { get; }

Property Value

bool

FaultDelay

Gets or sets the delay applied between faulted iterations.

[Display(ResourceType = typeof(LocalizedStrings), Name = "FaultDelay", Description = "FaultDelayDesc", GroupName = "Adapters", Order = 310)]
public TimeSpan FaultDelay { get; set; }

Property Value

TimeSpan

FeatureName

Feature name.

[Browsable(false)]
public virtual string FeatureName { get; }

Property Value

string

FileSystem

Ecng.IO.IFileSystem

[Browsable(false)]
public IFileSystem FileSystem { get; set; }

Property Value

IFileSystem

HeartbeatBeforeConnect

Start sending TimeMessage before connection established.

[Browsable(false)]
public virtual bool HeartbeatBeforeConnect { get; }

Property Value

bool

HeartbeatInterval

Server check interval for track the connection alive. The value is Zero turned off tracking.

[Display(ResourceType = typeof(LocalizedStrings), Name = "HeartBeat", Description = "HeartBeatDesc", GroupName = "Adapters", Order = 300)]
public TimeSpan HeartbeatInterval { get; set; }

Property Value

TimeSpan

Icon

Icon.

[Browsable(false)]
public virtual Uri Icon { get; }

Property Value

Uri

IsAutoReplyOnTransactonalUnsubscription

Send auto response for OrderStatusMessage and PortfolioLookupMessage unsubscribes.

[Browsable(false)]
public virtual bool IsAutoReplyOnTransactonalUnsubscription { get; }

Property Value

bool

IsFullCandlesOnly

Translates CandleMessage as only fully filled.

[Browsable(false)]
public virtual bool IsFullCandlesOnly { get; }

Property Value

bool

IsNativeIdentifiers

Identify security in messages by native identifier Native.

[Browsable(false)]
public virtual bool IsNativeIdentifiers { get; }

Property Value

bool

IsNativeIdentifiersPersistable

Native identifier can be stored.

[Browsable(false)]
public virtual bool IsNativeIdentifiersPersistable { get; }

Property Value

bool

IsPositionsEmulationRequired

Adapter required emulation PositionChangeMessage.

[Browsable(false)]
public virtual bool? IsPositionsEmulationRequired { get; }

Property Value

bool?

Remarks

null means no emulatior, true by order balance, false by trades.

IsReplaceCommandEditCurrent

Is the OrderReplaceMessage command edit a current order.

[Browsable(false)]
public virtual bool IsReplaceCommandEditCurrent { get; }

Property Value

bool

IsSecurityNewsOnly

Adapter provides news related with specified security.

[Browsable(false)]
public virtual bool IsSecurityNewsOnly { get; }

Property Value

bool

IsSupportExecutionsPnL

Adapter fills PnL.

[Browsable(false)]
public virtual bool IsSupportExecutionsPnL { get; }

Property Value

bool

IsSupportOrderBookIncrements

Adapter translates incremental order books.

[Browsable(false)]
public virtual bool IsSupportOrderBookIncrements { get; }

Property Value

bool

IsSupportSubscriptions

Support any subscriptions (ticks, order books etc.).

[Browsable(false)]
public virtual bool IsSupportSubscriptions { get; }

Property Value

bool

IsSupportTransactionLog

Adapter translates orders changes on reply of OrderStatusMessage.

[Browsable(false)]
public virtual bool IsSupportTransactionLog { get; }

Property Value

bool

IterationInterval

Interval between iterations.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Iterations", Description = "IterationInterval", GroupName = "Adapters", Order = 304)]
public virtual TimeSpan IterationInterval { get; set; }

Property Value

TimeSpan

LookupTimeout

Lookup timeout.

[Browsable(false)]
public virtual TimeSpan? LookupTimeout { get; }

Property Value

TimeSpan?

MaxParallelMessages

Gets or sets the maximum number of parallel (non-control) messages that can be processed. Must be greater than or equal to1.

[Display(ResourceType = typeof(LocalizedStrings), Name = "Parallel", Description = "ParallelDesc", GroupName = "Adapters", Order = 310)]
public int MaxParallelMessages { get; set; }

Property Value

int

Name

The source name.

public override string Name { get; set; }

Property Value

string

NotSupportedResultMessages

Not supported by adapter result message types.

[Browsable(false)]
public virtual IEnumerable<MessageTypes> NotSupportedResultMessages { get; set; }

Property Value

IEnumerable<MessageTypes>

OrderConditionType

Type of OrderCondition.

[Browsable(false)]
public virtual Type OrderConditionType { get; }

Property Value

Type

Remarks

If the connection does not support the order type Conditional, it will be returned null.

Platform

Bit process, which can run the adapter.

[Browsable(false)]
public Platforms Platform { get; protected set; }

Property Value

Platforms

PossibleSupportedMessages

Possible supported by adapter message types.

[Browsable(false)]
public virtual IEnumerable<MessageTypeInfo> PossibleSupportedMessages { get; set; }

Property Value

IEnumerable<MessageTypeInfo>

ReConnectionSettings

Connection tracking settings IMessageAdapter with a server.

[Display(ResourceType = typeof(LocalizedStrings), Name = "ReConnectionSettings", Description = "ReConnectionDesc", GroupName = "Connection")]
public ReConnectionSettings ReConnectionSettings { get; }

Property Value

ReConnectionSettings

SecurityExtendedFields

Names of extended security fields in SecurityMessage.

[Browsable(false)]
public virtual IEnumerable<(string, Type)> SecurityExtendedFields { get; }

Property Value

IEnumerable<(string name, Type type)>

StorageName

The storage name, associated with the adapter.

[Browsable(false)]
public virtual string StorageName { get; }

Property Value

string

SupportedInMessages

Supported by adapter message types.

[Browsable(false)]
public virtual IEnumerable<MessageTypes> SupportedInMessages { get; set; }

Property Value

IEnumerable<MessageTypes>

SupportedOrderBookDepths

Available options for MaxDepth.

[Browsable(false)]
public virtual IEnumerable<int> SupportedOrderBookDepths { get; }

Property Value

IEnumerable<int>

TransactionIdGenerator

Transaction id generator.

[Browsable(false)]
public IdGenerator TransactionIdGenerator { get; set; }

Property Value

IdGenerator

UseInChannel

Use channels for in messages.

[Browsable(false)]
public virtual bool UseInChannel { get; }

Property Value

bool

UseOutChannel

Use channels for out messages.

[Browsable(false)]
public virtual bool UseOutChannel { get; }

Property Value

bool

Methods

BoardLookupAsync(BoardLookupMessage, CancellationToken)

protected virtual ValueTask BoardLookupAsync(BoardLookupMessage lookupMsg, CancellationToken cancellationToken)

Parameters

lookupMsg BoardLookupMessage
cancellationToken CancellationToken

Returns

ValueTask

CancelOrderAsync(OrderCancelMessage, CancellationToken)

protected virtual ValueTask CancelOrderAsync(OrderCancelMessage cancelMsg, CancellationToken cancellationToken)

Parameters

cancelMsg OrderCancelMessage
cancellationToken CancellationToken

Returns

ValueTask

CancelOrderGroupAsync(OrderGroupCancelMessage, CancellationToken)

protected virtual ValueTask CancelOrderGroupAsync(OrderGroupCancelMessage cancelMsg, CancellationToken cancellationToken)

Parameters

cancelMsg OrderGroupCancelMessage
cancellationToken CancellationToken

Returns

ValueTask

ChangePasswordAsync(ChangePasswordMessage, CancellationToken)

protected virtual ValueTask ChangePasswordAsync(ChangePasswordMessage pwdMsg, CancellationToken cancellationToken)

Parameters

pwdMsg ChangePasswordMessage
cancellationToken CancellationToken

Returns

ValueTask

Clone()

Create a copy of MessageAdapter.

public virtual IMessageAdapter Clone()

Returns

IMessageAdapter

Copy.

ConnectAsync(ConnectMessage, CancellationToken)

protected virtual ValueTask ConnectAsync(ConnectMessage connectMsg, CancellationToken cancellationToken)

Parameters

connectMsg ConnectMessage
cancellationToken CancellationToken

Returns

ValueTask

CreateOrderLogMarketDepthBuilder(SecurityId)

Create market depth builder.

public virtual IOrderLogMarketDepthBuilder CreateOrderLogMarketDepthBuilder(SecurityId securityId)

Parameters

securityId SecurityId

Security ID.

Returns

IOrderLogMarketDepthBuilder

Order log to market depth builder.

DisconnectAsync(DisconnectMessage, CancellationToken)

protected virtual ValueTask DisconnectAsync(DisconnectMessage disconnectMsg, CancellationToken cancellationToken)

Parameters

disconnectMsg DisconnectMessage
cancellationToken CancellationToken

Returns

ValueTask

GetSupportedMarketDataTypesAsync(SecurityId, DateTime?, DateTime?)

Get supported by adapter message types.

public virtual IAsyncEnumerable<DataType> GetSupportedMarketDataTypesAsync(SecurityId securityId, DateTime? from, DateTime? to)

Parameters

securityId SecurityId

SecurityId

from DateTime?

Start date for request. If null, then all available messages will be returned.

to DateTime?

End date for request. If null, then all available messages will be returned.

Returns

IAsyncEnumerable<DataType>

Supported by adapter market data types.

IsAllDownloadingSupported(DataType)

Is for the specified dataType all securities downloading enabled.

public virtual bool IsAllDownloadingSupported(DataType dataType)

Parameters

dataType DataType

Data type info.

Returns

bool

Check result.

IsSecurityRequired(DataType)

Support filtering subscriptions (subscribe/unsubscribe for specified security).

public virtual bool IsSecurityRequired(DataType dataType)

Parameters

dataType DataType

Data type info.

Returns

bool

Check result.

IsSupportCandlesPriceLevels(MarketDataMessage)

Support candles PriceLevels.

public virtual bool IsSupportCandlesPriceLevels(MarketDataMessage subscription)

Parameters

subscription MarketDataMessage

MarketDataMessage

Returns

bool

Check result.

IsSupportCandlesUpdates(MarketDataMessage)

Support candles subscription and live updates.

public virtual bool IsSupportCandlesUpdates(MarketDataMessage subscription)

Parameters

subscription MarketDataMessage

MarketDataMessage

Returns

bool

Check result.

Load(SettingsStorage)

Load settings.

public override void Load(SettingsStorage storage)

Parameters

storage SettingsStorage

Settings storage.

MarketDataAsync(MarketDataMessage, CancellationToken)

protected virtual ValueTask MarketDataAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage
cancellationToken CancellationToken

Returns

ValueTask

OnCandlesSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for candles data. Override to provide implementation for candles subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnCandlesSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnLevel1SubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for level1 data. Override to provide implementation for level1 subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnLevel1SubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnMarketDepthSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for market depth data. Override to provide implementation for market depth subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnMarketDepthSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnNewsSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for news data. Override to provide implementation for news subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnNewsSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnOrderLogSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for order log (trades/transactions) data. Override to provide implementation for order log subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnOrderLogSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnPropertyChanged(string)

Raise PropertyChanged event.

protected void OnPropertyChanged(string propertyName = null)

Parameters

propertyName string

The name of the property that changed.

OnSendInMessageAsync(Message, CancellationToken)

Send in message handler.

protected virtual ValueTask OnSendInMessageAsync(Message message, CancellationToken cancellationToken)

Parameters

message Message

Message

cancellationToken CancellationToken

CancellationToken

Returns

ValueTask

ValueTask

OnTFCandlesSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for time-frame candles (TF candles) data. Override to provide implementation for TF candles subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnTFCandlesSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OnTicksSubscriptionAsync(MarketDataMessage, CancellationToken)

Handles subscription request for ticks data. Override to provide implementation for ticks subscription processing. The default implementation throws NotSupported.

protected virtual ValueTask OnTicksSubscriptionAsync(MarketDataMessage mdMsg, CancellationToken cancellationToken)

Parameters

mdMsg MarketDataMessage

Market data subscription message.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

OrderStatusAsync(OrderStatusMessage, CancellationToken)

protected virtual ValueTask OrderStatusAsync(OrderStatusMessage statusMsg, CancellationToken cancellationToken)

Parameters

statusMsg OrderStatusMessage
cancellationToken CancellationToken

Returns

ValueTask

PortfolioLookupAsync(PortfolioLookupMessage, CancellationToken)

protected virtual ValueTask PortfolioLookupAsync(PortfolioLookupMessage lookupMsg, CancellationToken cancellationToken)

Parameters

lookupMsg PortfolioLookupMessage
cancellationToken CancellationToken

Returns

ValueTask

RegisterOrderAsync(OrderRegisterMessage, CancellationToken)

protected virtual ValueTask RegisterOrderAsync(OrderRegisterMessage regMsg, CancellationToken cancellationToken)

Parameters

regMsg OrderRegisterMessage
cancellationToken CancellationToken

Returns

ValueTask

ReplaceOrderAsync(OrderReplaceMessage, CancellationToken)

protected virtual ValueTask ReplaceOrderAsync(OrderReplaceMessage replaceMsg, CancellationToken cancellationToken)

Parameters

replaceMsg OrderReplaceMessage
cancellationToken CancellationToken

Returns

ValueTask

ResetAsync(ResetMessage, CancellationToken)

protected virtual ValueTask ResetAsync(ResetMessage resetMsg, CancellationToken cancellationToken)

Parameters

resetMsg ResetMessage
cancellationToken CancellationToken

Returns

ValueTask

Save(SettingsStorage)

Save settings.

public override void Save(SettingsStorage storage)

Parameters

storage SettingsStorage

Settings storage.

SecurityLookupAsync(SecurityLookupMessage, CancellationToken)

protected virtual ValueTask SecurityLookupAsync(SecurityLookupMessage lookupMsg, CancellationToken cancellationToken)

Parameters

lookupMsg SecurityLookupMessage
cancellationToken CancellationToken

Returns

ValueTask

SendInMessageAsync(Message, CancellationToken)

Processes a generic message asynchronously.

public virtual ValueTask SendInMessageAsync(Message message, CancellationToken cancellationToken)

Parameters

message Message

The message to process.

cancellationToken CancellationToken

CancellationToken

Returns

ValueTask

SendOutConnectionStateAsync(ConnectionStates, CancellationToken)

Send to SendOutMessageAsync(Message, CancellationToken) connection state message.

protected ValueTask SendOutConnectionStateAsync(ConnectionStates state, CancellationToken cancellationToken)

Parameters

state ConnectionStates

ConnectionStates

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendOutDisconnectMessageAsync(bool, CancellationToken)

protected ValueTask SendOutDisconnectMessageAsync(bool expected, CancellationToken cancellationToken)

Parameters

expected bool

Is disconnect expected.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendOutDisconnectMessageAsync(Exception, CancellationToken)

protected ValueTask SendOutDisconnectMessageAsync(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

Error info. Can be null.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendOutErrorAsync(Exception, CancellationToken)

Initialize a new message ErrorMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendOutErrorAsync(Exception error, CancellationToken cancellationToken)

Parameters

error Exception

Error details.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendOutErrorAsync(string, CancellationToken)

Initialize a new message ErrorMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendOutErrorAsync(string description, CancellationToken cancellationToken)

Parameters

description string

Error details.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendOutMessageAsync(Message, CancellationToken)

Send outgoing message and raise NewOutMessageAsync event.

public virtual ValueTask SendOutMessageAsync(Message message, CancellationToken cancellationToken)

Parameters

message Message

Message.

cancellationToken CancellationToken

CancellationToken

Returns

ValueTask

SendSubscriptionFinishedAsync(long, CancellationToken, DateTime?)

Initialize a new message SubscriptionFinishedMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendSubscriptionFinishedAsync(long originalTransactionId, CancellationToken cancellationToken, DateTime? nextFrom = null)

Parameters

originalTransactionId long

ID of the original message for which this message is a response.

cancellationToken CancellationToken

Cancellation token.

nextFrom DateTime?

NextFrom.

Returns

ValueTask

SendSubscriptionNotSupportedAsync(long, CancellationToken)

Initialize a new message SubscriptionResponseMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendSubscriptionNotSupportedAsync(long originalTransactionId, CancellationToken cancellationToken)

Parameters

originalTransactionId long

ID of the original message for which this message is a response.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendSubscriptionOnlineAsync(long, CancellationToken)

Initialize a new message SubscriptionOnlineMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendSubscriptionOnlineAsync(long originalTransactionId, CancellationToken cancellationToken)

Parameters

originalTransactionId long

ID of the original message for which this message is a response.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

SendSubscriptionReplyAsync(long, CancellationToken, Exception)

Initialize a new message SubscriptionResponseMessage and pass it to the method SendOutMessageAsync(Message, CancellationToken).

protected ValueTask SendSubscriptionReplyAsync(long originalTransactionId, CancellationToken cancellationToken, Exception error = null)

Parameters

originalTransactionId long

ID of the original message for which this message is a response.

cancellationToken CancellationToken

Cancellation token.

error Exception

Subscribe or unsubscribe error info. To be set if the answer.

Returns

ValueTask

SendSubscriptionResultAsync(ISubscriptionMessage, CancellationToken)

protected ValueTask SendSubscriptionResultAsync(ISubscriptionMessage message, CancellationToken cancellationToken)

Parameters

message ISubscriptionMessage

Subscription.

cancellationToken CancellationToken

Cancellation token.

Returns

ValueTask

TimeAsync(TimeMessage, CancellationToken)

protected virtual ValueTask TimeAsync(TimeMessage timeMsg, CancellationToken cancellationToken)

Parameters

timeMsg TimeMessage
cancellationToken CancellationToken

Returns

ValueTask

ValidateSecurityId(SecurityId)

Validate the specified security id is supported by the adapter and subscription can be done.

protected virtual bool ValidateSecurityId(SecurityId secId)

Parameters

secId SecurityId

SecurityId.

Returns

bool

Check result.

Events

NewOutMessageAsync

New message event.

public event Func<Message, CancellationToken, ValueTask> NewOutMessageAsync

Event Type

Func<Message, CancellationToken, ValueTask>