Table of Contents

Class MessageConverterHelper

Namespace
StockSharp.Algo
Assembly
StockSharp.Algo.dll

The auxiliary class for conversion of business-objects (StockSharp.BusinessEntities) into messages (StockSharp.Messages) and vice versa.

public static class MessageConverterHelper
Inheritance
MessageConverterHelper
Inherited Members

Properties

AllCandleMessageTypes

All registered candle message types.

public static IEnumerable<Type> AllCandleMessageTypes { get; }

Property Value

IEnumerable<Type>

AllCandleTypes

All registered candle types.

public static IEnumerable<Type> AllCandleTypes { get; }

Property Value

IEnumerable<Type>

Methods

ApplyChanges(ExchangeBoard, BoardMessage)

To convert the message into board.

public static ExchangeBoard ApplyChanges(this ExchangeBoard board, BoardMessage message)

Parameters

board ExchangeBoard

Board.

message BoardMessage

Message.

Returns

ExchangeBoard

Board.

CreateCancelMessage(Order, SecurityId, long)

To create the message of cancelling old order.

public static OrderCancelMessage CreateCancelMessage(this Order order, SecurityId securityId, long transactionId)

Parameters

order Order

Order.

securityId SecurityId

Security ID.

transactionId long

The transaction number.

Returns

OrderCancelMessage

Message.

CreateCandleMessage(Type)

Create instance of CandleMessage.

public static CandleMessage CreateCandleMessage(this Type messageType)

Parameters

messageType Type

The type of candle message.

Returns

CandleMessage

Instance of CandleMessage.

CreateRegisterMessage(Order, SecurityId?)

To create the message of new order registration.

public static OrderRegisterMessage CreateRegisterMessage(this Order order, SecurityId? securityId = null)

Parameters

order Order

Order.

securityId SecurityId?

Security ID.

Returns

OrderRegisterMessage

Message.

CreateReplaceMessage(Order, Order, SecurityId)

To create the message of replacing old order with new one.

public static OrderReplaceMessage CreateReplaceMessage(this Order oldOrder, Order newOrder, SecurityId securityId)

Parameters

oldOrder Order

Old order.

newOrder Order

New order.

securityId SecurityId

Security ID.

Returns

OrderReplaceMessage

Message.

CreateReplaceMessage(Order, Order, SecurityId, Order, Order, SecurityId)

To create the message of replacing pair of old orders to new ones.

public static OrderPairReplaceMessage CreateReplaceMessage(this Order oldOrder1, Order newOrder1, SecurityId security1, Order oldOrder2, Order newOrder2, SecurityId security2)

Parameters

oldOrder1 Order

Old order.

newOrder1 Order

New order.

security1 SecurityId

Security ID.

oldOrder2 Order

Old order.

newOrder2 Order

New order.

security2 SecurityId

Security ID.

Returns

OrderPairReplaceMessage

Message.

FillMessage<TMessage>(Security, TMessage)

To convert the instrument into message.

public static TMessage FillMessage<TMessage>(this Security security, TMessage message) where TMessage : SecurityMessage

Parameters

security Security

Security.

message TMessage

Message.

Returns

TMessage

Message.

Type Parameters

TMessage

Message type.

HasExternalId(SecurityId)

To check, if SecurityId contains identifiers of external sources.

public static bool HasExternalId(this SecurityId securityId)

Parameters

securityId SecurityId

Security ID.

Returns

bool

true, if there are identifiers of external sources, otherwise, false.

RegisterCandle(Type, Type, Func<Candle>, Func<CandleMessage>)

Register new candle type.

[Obsolete("Conversion reduce performance.")]
public static void RegisterCandle(Type candleType, Type messageType, Func<Candle> candleCreator, Func<CandleMessage> candleMessageCreator)

Parameters

candleType Type

Candle type.

messageType Type

The type of candle message.

candleCreator Func<Candle>

Candle instance creator.

candleMessageCreator Func<CandleMessage>

CandleMessage instance creator.

RegisterCandle<TCandle, TMessage>(Func<TCandle>, Func<TMessage>)

Register new candle type.

[Obsolete("Conversion reduce performance.")]
public static void RegisterCandle<TCandle, TMessage>(Func<TCandle> candleCreator, Func<TMessage> candleMessageCreator) where TCandle : Candle where TMessage : CandleMessage

Parameters

candleCreator Func<TCandle>

Candle instance creator.

candleMessageCreator Func<TMessage>

CandleMessage instance creator.

Type Parameters

TCandle

Candle type.

TMessage

The type of candle message.

ToBoard(BoardMessage)

To convert the message into board.

public static ExchangeBoard ToBoard(this BoardMessage message)

Parameters

message BoardMessage

Message.

Returns

ExchangeBoard

Board.

ToCandle(CandleMessage, CandleSeries)

To convert CandleMessage into candle.

[Obsolete("Conversion reduce performance.")]
public static Candle ToCandle(this CandleMessage message, CandleSeries series)

Parameters

message CandleMessage

Message.

series CandleSeries

Series.

Returns

Candle

Candle.

ToCandle(CandleMessage, Security)

To convert CandleMessage into candle.

[Obsolete("Conversion reduce performance.")]
public static Candle ToCandle(this CandleMessage message, Security security)

Parameters

message CandleMessage

Message.

security Security

Security.

Returns

Candle

Candle.

ToCandleMessageType(Type)

Cast candle type Candle to the message CandleMessage.

public static Type ToCandleMessageType(this Type candleType)

Parameters

candleType Type

The type of the candle Candle.

Returns

Type

The type of the message CandleMessage.

ToCandleSeries(DataType, Security)

Convert DataType to CandleSeries value.

public static CandleSeries ToCandleSeries(this DataType dataType, Security security)

Parameters

dataType DataType

Data type info.

security Security

The instrument to be used for candles formation.

Returns

CandleSeries

Candles series.

ToCandleSeries(MarketDataMessage, CandleSeries, bool)

public static void ToCandleSeries(this MarketDataMessage message, CandleSeries series, bool throwIfInvalidType)

Parameters

message MarketDataMessage

Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).

series CandleSeries

Candles series.

throwIfInvalidType bool

Throw an error if DataType2 isn't candle type.

ToCandleSeries(MarketDataMessage, Security, bool)

public static CandleSeries ToCandleSeries(this MarketDataMessage message, Security security, bool throwIfInvalidType)

Parameters

message MarketDataMessage

Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).

security Security

Security.

throwIfInvalidType bool

Throw an error if DataType2 isn't candle type.

Returns

CandleSeries

Candles series.

ToCandleType(Type)

Cast message type CandleMessage to the candle type Candle.

public static Type ToCandleType(this Type messageType)

Parameters

messageType Type

The type of the message CandleMessage.

Returns

Type

The type of the candle Candle.

ToCandle<TCandle>(CandleMessage, CandleSeries)

To convert CandleMessage into candle.

[Obsolete("Conversion reduce performance.")]
public static TCandle ToCandle<TCandle>(this CandleMessage message, CandleSeries series) where TCandle : Candle, new()

Parameters

message CandleMessage

Message.

series CandleSeries

Series.

Returns

TCandle

Candle.

Type Parameters

TCandle

The candle type.

ToCandles<TCandle>(IEnumerable<CandleMessage>, Security)

To convert messages into trading objects.

[Obsolete("Conversion reduce performance.")]
public static IEnumerable<TCandle> ToCandles<TCandle>(this IEnumerable<CandleMessage> messages, Security security)

Parameters

messages IEnumerable<CandleMessage>

Messages.

security Security

Security.

Returns

IEnumerable<TCandle>

Trading objects.

Type Parameters

TCandle

The candle type.

ToChangeMessage(Portfolio)

To convert the portfolio into message.

public static PositionChangeMessage ToChangeMessage(this Portfolio portfolio)

Parameters

portfolio Portfolio

Portfolio.

Returns

PositionChangeMessage

Message.

ToChangeMessage(Position, long)

To convert the position into message.

public static PositionChangeMessage ToChangeMessage(this Position position, long originalTransactionId = 0)

Parameters

position Position

Position.

originalTransactionId long

ID of original transaction, for which this message is the answer.

Returns

PositionChangeMessage

Message.

ToDataType(CandleSeries)

Convert DataType to CandleSeries value.

public static DataType ToDataType(this CandleSeries series)

Parameters

series CandleSeries

Candles series.

Returns

DataType

Data type info.

ToDataTypeString(MarketDataMessage)

Format data type into into human-readable string.

public static string ToDataTypeString(this MarketDataMessage message)

Parameters

message MarketDataMessage

Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).

Returns

string

String.

ToEntities<TMessage, TEntity>(IEnumerable<TMessage>, Security, IExchangeInfoProvider)

To convert messages into trading objects.

[Obsolete("Conversion reduce performance.")]
public static IEnumerable<TEntity> ToEntities<TMessage, TEntity>(this IEnumerable<TMessage> messages, Security security, IExchangeInfoProvider exchangeInfoProvider = null) where TMessage : Message

Parameters

messages IEnumerable<TMessage>

Messages.

security Security

Security.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

Returns

IEnumerable<TEntity>

Trading objects.

Type Parameters

TMessage

Message type.

TEntity

The type of trading object.

ToExchange(BoardMessage)

To convert the message into exchange.

public static Exchange ToExchange(this BoardMessage message)

Parameters

message BoardMessage

Message.

Returns

Exchange

Exchange.

ToExchange(BoardMessage, Exchange)

To convert the message into exchange.

public static Exchange ToExchange(this BoardMessage message, Exchange exchange)

Parameters

message BoardMessage

Message.

exchange Exchange

Exchange.

Returns

Exchange

Exchange.

ToExternalId(SecurityId)

public static SecurityExternalId ToExternalId(this SecurityId securityId)

Parameters

securityId SecurityId

SecurityId.

Returns

SecurityExternalId

SecurityExternalId.

ToLookupCriteria(Order, decimal?, Sides?)

Convert Order to OrderStatusMessage value.

public static OrderStatusMessage ToLookupCriteria(this Order criteria, decimal? volume, Sides? side)

Parameters

criteria Order

The criterion which fields will be used as a filter.

volume decimal?

Volume.

side Sides?

Order side.

Returns

OrderStatusMessage

A message requesting current registered orders and trades.

ToLookupCriteria(Portfolio)

public static PortfolioLookupMessage ToLookupCriteria(this Portfolio criteria)

Parameters

criteria Portfolio

The criterion which fields will be used as a filter.

Returns

PortfolioLookupMessage

Message portfolio lookup for specified criteria.

ToLookupCriteria(SecurityLookupMessage, IExchangeInfoProvider)

Convert SecurityLookupMessage message to Security criteria.

public static Security ToLookupCriteria(this SecurityLookupMessage message, IExchangeInfoProvider exchangeInfoProvider)

Parameters

message SecurityLookupMessage

Message.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

Returns

Security

Criteria.

ToLookupMessage(Security)

Convert Security criteria to SecurityLookupMessage.

public static SecurityLookupMessage ToLookupMessage(this Security criteria)

Parameters

criteria Security

Criteria.

Returns

SecurityLookupMessage

Message.

ToMarketDataMessage(CandleSeries, bool, DateTimeOffset?, DateTimeOffset?, long?, bool)

public static MarketDataMessage ToMarketDataMessage(this CandleSeries series, bool isSubscribe, DateTimeOffset? from = null, DateTimeOffset? to = null, long? count = null, bool throwIfInvalidType = true)

Parameters

series CandleSeries

Candles series.

isSubscribe bool

The message is subscription.

from DateTimeOffset?

The initial date from which you need to get data.

to DateTimeOffset?

The final date by which you need to get data.

count long?

Candles count.

throwIfInvalidType bool

Throw an error if DataType2 isn't candle type.

Returns

MarketDataMessage

Market-data message (uses as a subscribe/unsubscribe in outgoing case, confirmation event in incoming case).

ToMarketDepth(Level1ChangeMessage, Security)

[Obsolete("Use IOrderBookMessage.")]
public static MarketDepth ToMarketDepth(this Level1ChangeMessage message, Security security)

Parameters

message Level1ChangeMessage

Message.

security Security

Security.

Returns

MarketDepth

Market depth.

ToMarketDepth(QuoteChangeMessage, MarketDepth)

To convert the message into order book.

[Obsolete("Use IOrderBookMessage.")]
public static MarketDepth ToMarketDepth(this QuoteChangeMessage message, MarketDepth marketDepth)

Parameters

message QuoteChangeMessage

Message.

marketDepth MarketDepth

Market depth.

Returns

MarketDepth

Market depth.

ToMarketDepth(QuoteChangeMessage, Security)

To convert the message into order book.

[Obsolete("Use IOrderBookMessage.")]
public static MarketDepth ToMarketDepth(this QuoteChangeMessage message, Security security)

Parameters

message QuoteChangeMessage

Message.

security Security

Security.

Returns

MarketDepth

Market depth.

ToMessage(Candle)

To convert the candle into message.

[Obsolete("Conversion reduce performance.")]
public static CandleMessage ToMessage(this Candle candle)

Parameters

candle Candle

Candle.

Returns

CandleMessage

Message.

ToMessage(ExchangeBoard, long)

To convert the board into message.

public static BoardMessage ToMessage(this ExchangeBoard board, long originalTransactionId = 0)

Parameters

board ExchangeBoard

Board.

originalTransactionId long

ID of original transaction, for which this message is the answer.

Returns

BoardMessage

Message.

ToMessage(MarketDepth)

[Obsolete("Use IOrderBookMessage.")]
public static QuoteChangeMessage ToMessage(this MarketDepth depth)

Parameters

depth MarketDepth

MarketDepth.

Returns

QuoteChangeMessage

QuoteChangeMessage.

ToMessage(MyTrade)

To convert the own trade into message.

public static ExecutionMessage ToMessage(this MyTrade trade)

Parameters

trade MyTrade

Own trade.

Returns

ExecutionMessage

Message.

ToMessage(News)

To convert news into message.

public static NewsMessage ToMessage(this News news)

Parameters

news News

News.

Returns

NewsMessage

Message.

ToMessage(Order)

To convert the order into message.

public static ExecutionMessage ToMessage(this Order order)

Parameters

order Order

Order.

Returns

ExecutionMessage

Message.

ToMessage(OrderFail, long)

To convert the error description into message.

public static ExecutionMessage ToMessage(this OrderFail fail, long originalTransactionId)

Parameters

fail OrderFail

Error details.

originalTransactionId long

ID of original transaction, for which this message is the answer.

Returns

ExecutionMessage

Message.

ToMessage(OrderLogItem)

To convert the string of orders log onto message.

[Obsolete("Use OrderLogMessage.")]
public static ExecutionMessage ToMessage(this OrderLogItem item)

Parameters

item OrderLogItem

Order log item.

Returns

ExecutionMessage

Message.

ToMessage(Portfolio, long)

To convert the portfolio into message.

public static PortfolioMessage ToMessage(this Portfolio portfolio, long originalTransactionId = 0)

Parameters

portfolio Portfolio

Portfolio.

originalTransactionId long

ID of original transaction, for which this message is the answer.

Returns

PortfolioMessage

Message.

ToMessage(Security, SecurityId?, long, bool)

To convert the instrument into message.

public static SecurityMessage ToMessage(this Security security, SecurityId? securityId = null, long originalTransactionId = 0, bool copyExtendedId = false)

Parameters

security Security

Security.

securityId SecurityId?

Security ID.

originalTransactionId long

ID of original transaction, for which this message is the answer.

copyExtendedId bool

Copy ExternalId and Type.

Returns

SecurityMessage

Message.

ToMessage(Trade)

To convert the tick trade into message.

[Obsolete("Use ITickTradeMessage.")]
public static ExecutionMessage ToMessage(this Trade trade)

Parameters

trade Trade

Tick trade.

Returns

ExecutionMessage

Message.

ToMessageType(Type, ref object)

To convert the type of business object into type of message.

[Obsolete("Conversion reduce performance.")]
public static Type ToMessageType(this Type dataType, ref object arg)

Parameters

dataType Type

The type of business object.

arg object

The data parameter.

Returns

Type

Message type.

ToMessages<TEntity, TMessage>(IEnumerable<TEntity>)

To convert trading objects into messages.

[Obsolete("Conversion reduce performance.")]
public static IEnumerable<TMessage> ToMessages<TEntity, TMessage>(this IEnumerable<TEntity> entities)

Parameters

entities IEnumerable<TEntity>

Trading objects.

Returns

IEnumerable<TMessage>

Messages.

Type Parameters

TEntity

The type of trading object.

TMessage

Message type.

ToNews(NewsMessage, IExchangeInfoProvider)

Cast NewsMessage to the News.

public static News ToNews(this NewsMessage message, IExchangeInfoProvider exchangeInfoProvider)

Parameters

message NewsMessage

Message.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

Returns

News

News.

ToOrder(ExecutionMessage, Order)

To convert the message into order.

public static Order ToOrder(this ExecutionMessage message, Order order)

Parameters

message ExecutionMessage

Message.

order Order

The order.

Returns

Order

Order.

ToOrder(ExecutionMessage, Security)

To convert the message into order.

public static Order ToOrder(this ExecutionMessage message, Security security)

Parameters

message ExecutionMessage

Message.

security Security

Security.

Returns

Order

Order.

ToOrderLog(ExecutionMessage, OrderLogItem)

To convert the message into orders log string.

[Obsolete("Use IOrderLogMessage.")]
public static OrderLogItem ToOrderLog(this ExecutionMessage message, OrderLogItem item)

Parameters

message ExecutionMessage

Message.

item OrderLogItem

Order log item.

Returns

OrderLogItem

Order log item.

ToOrderLog(ExecutionMessage, Security)

To convert the message into orders log string.

[Obsolete("Use IOrderLogMessage.")]
public static OrderLogItem ToOrderLog(this ExecutionMessage message, Security security)

Parameters

message ExecutionMessage

Message.

security Security

Security.

Returns

OrderLogItem

Order log item.

ToPortfolio(PortfolioMessage, Portfolio, IExchangeInfoProvider)

public static Portfolio ToPortfolio(this PortfolioMessage message, Portfolio portfolio, IExchangeInfoProvider exchangeInfoProvider)

Parameters

message PortfolioMessage

Message.

portfolio Portfolio

Portfolio.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

Returns

Portfolio

Portfolio.

ToSecurity(SecurityMessage, IExchangeInfoProvider)

To convert the message into instrument.

public static Security ToSecurity(this SecurityMessage message, IExchangeInfoProvider exchangeInfoProvider)

Parameters

message SecurityMessage

Message.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

Returns

Security

Security.

ToSecurityId(Security, SecurityIdGenerator, bool, bool)

To convert the instrument into SecurityId.

public static SecurityId ToSecurityId(this Security security, SecurityIdGenerator idGenerator = null, bool boardIsRequired = true, bool copyExtended = false)

Parameters

security Security

Security.

idGenerator SecurityIdGenerator

The instrument identifiers generator Id.

boardIsRequired bool

Board is required.

copyExtended bool

Copy ExternalId and Type.

Returns

SecurityId

Security ID.

ToSecurityId(SecurityExternalId, SecurityId)

public static SecurityId ToSecurityId(this SecurityExternalId externalId, SecurityId secId)

Parameters

externalId SecurityExternalId

SecurityExternalId.

secId SecurityId

SecurityId.

Returns

SecurityId

SecurityId.

ToSecurityId(SecurityExternalId, string, string)

public static SecurityId ToSecurityId(this SecurityExternalId externalId, string securityCode, string boardCode)

Parameters

externalId SecurityExternalId

SecurityExternalId.

securityCode string

Security code.

boardCode string

Board code.

Returns

SecurityId

SecurityId.

ToSubscription(DataType)

Convert DataType to Subscription value.

public static Subscription ToSubscription(this DataType dataType)

Parameters

dataType DataType

Data type info.

Returns

Subscription

Subscription.

Update(Candle, CandleMessage)

Update candle from CandleMessage.

[Obsolete("Conversion reduce performance.")]
public static Candle Update(this Candle candle, CandleMessage message)

Parameters

candle Candle

Candle.

message CandleMessage

Message.

Returns

Candle

Candle.