Table of Contents

Class Extensions

Namespace
ATAS.DataFeedsCore
Assembly
ATAS.DataFeedsCore.dll

Helper extension methods for orders, positions, securities, trades, connectors and price/money formatting.

public static class Extensions
Inheritance
object
Extensions

Methods

CalcTickerSegmentsLengths(string)

Calculates the lengths of the segments of a futures ticker from its trailing digits: the root code, the day, the month letter and the year.

Added in ATAS 8.0.15.

public static (int codeLength, int daysLen, int monthLength, int yearsLength) CalcTickerSegmentsLengths(this string ticker)

Parameters

ticker string

The ticker.

Returns

(int codeLength, int daysLen, int monthLength, int yearsLength)

For a ticker of at most two characters or without trailing digits: the whole length as the code and zeros for the rest. For one or two trailing digits: a one-letter month and the digits as the year. For three or more trailing digits: a one-letter month, two day digits and the remaining digits as the year.

CanSubscribeMarketData(IDataFeedConnector)

Checks whether market data subscriptions can be requested: the connector is connected, connecting or reconnecting.

Added in ATAS 8.0.15.

public static bool CanSubscribeMarketData(this IDataFeedConnector connector)

Parameters

connector IDataFeedConnector

The connector.

Returns

bool

Exceptions

ArgumentNullException

connector is null.

CheckKind(DateTime)

Marks the time as System.DateTimeKind.Local by relabelling its ticks; the value itself is not converted.

public static DateTime CheckKind(this DateTime time)

Parameters

time DateTime

The time.

Returns

DateTime

The time with System.DateTimeKind.Local kind.

CompareCodes(string?, string, bool)

Matches a value against a lower-case search code, ignoring the case of the value.

Added in ATAS 8.0.15.

public static bool CompareCodes(string? code, string value, bool fullMatch)

Parameters

code string

The search code, already in lower case; null matches any value.

value string

The value to check; an empty value matches any code.

fullMatch bool

true to require equality; otherwise the value must contain the code.

Returns

bool

ConvertToMyTrade<T>(T, Portfolio, Security, Action<MyTrade, T>)

Creates a MyTrade for the portfolio and security and lets update fill it from a connector-specific execution.

public static MyTrade ConvertToMyTrade<T>(this T execution, Portfolio portfolio, Security security, Action<MyTrade, T> update)

Parameters

execution T

The execution.

portfolio Portfolio

The portfolio of the trade.

security Security

The security of the trade.

update Action<MyTrade, T>

Copies the execution data into the new trade.

Returns

MyTrade

The new trade.

Type Parameters

T

The connector-specific execution type.

Exceptions

ArgumentNullException

Any argument is null.

ConvertToMyTrdes<T>(IEnumerable<T>, Portfolio, Security, Action<MyTrade, T>)

public static IEnumerable<MyTrade> ConvertToMyTrdes<T>(this IEnumerable<T> executions, Portfolio portfolio, Security security, Action<MyTrade, T> update)

Parameters

executions IEnumerable<T>

The executions.

portfolio Portfolio

The portfolio of the trades.

security Security

The security of the trades.

update Action<MyTrade, T>

Copies the execution data into each new trade.

Returns

IEnumerable<MyTrade>

A materialized array of the new trades.

Type Parameters

T

The connector-specific execution type.

Exceptions

ArgumentNullException

Any argument is null.

CreateExtendedOptions(ISecurityTradingOptions, OrderTypes)

Creates the connector-specific extended options object for an order of the given type.

Added in ATAS 8.0.15.

public static OrderExtendedOptions? CreateExtendedOptions(this ISecurityTradingOptions tradingOptions, OrderTypes type)

Parameters

tradingOptions ISecurityTradingOptions

The trading options of the security.

type OrderTypes

The order type.

Returns

OrderExtendedOptions

The options object, or null when the connector has no extended options for this order type.

Exceptions

ArgumentOutOfRangeException

type is not Limit, Market, Stop or StopLimit.

CreateOrderToClosePosition(IDataFeedConnector, Position, decimal?, bool)

Creates (but does not send) a market order that closes the position or a part of it. The order expires today unless the security's trading options do not support Day, and it is marked reduce-only when the connector's market order options support it.

public static Order CreateOrderToClosePosition(this IDataFeedConnector connector, Position position, decimal? volume, bool allowReduceOnly = true)

Parameters

connector IDataFeedConnector

The connector that provides the security's trading options.

position Position

The position to close.

volume decimal?

The signed volume to close, in lots, with the sign of the position (positive closes a long by selling); null closes the whole position.

allowReduceOnly bool

Currently not used: reduce-only is set whenever the connector supports it.

Returns

Order

The new order.

Exceptions

ArgumentNullException

connector or position is null.

Filled(Order)

Returns the volume filled so far: QuantityToFill - Unfilled.

public static decimal Filled(this Order order)

Parameters

order Order

The order.

Returns

decimal

The executed volume, in lots.

Filter(IEnumerable<Security>, SecurityFilter, bool, bool, bool)

Selects the securities whose code and exchange match Code and Exchange, ignoring case. An empty filter value matches any security, and a security with an empty code or exchange matches any filter value.

public static IEnumerable<Security> Filter(this IEnumerable<Security> securities, SecurityFilter filter, bool useExchange = true, bool codeFullMatch = false, bool exchangeFullMatch = false)

Parameters

securities IEnumerable<Security>

The securities to filter.

filter SecurityFilter

The filter; only its Code and Exchange are used.

useExchange bool

false to ignore the exchange.

codeFullMatch bool

true to require an exact code match; otherwise the security code must contain the filter code.

exchangeFullMatch bool

true to require an exact exchange match; otherwise the security exchange must contain the filter exchange.

Returns

IEnumerable<Security>

A materialized array of the matching securities.

GetCurrencyString(Position?)

Returns the currency symbol of the position's portfolio currency ($, €, £, ¥, ₣).

Added in ATAS 8.0.15.

public static string GetCurrencyString(this Position? position)

Parameters

position Position

The position; may be null.

Returns

string

The symbol, or an empty string when the position or its portfolio is null, for RUB and for other currencies.

GetDecimalDigits(decimal)

Returns the position of the first significant decimal digit of a fractional step, for example 2 for 0.01 and 0.025, 1 for 0.5.

public static int GetDecimalDigits(this decimal value)

Parameters

value decimal

The step; the sign is ignored.

Returns

int

0 when the absolute value is 0 or not less than 1.

GetExtendedInfo<T>(Portfolio)

Gets or creates an extended info instance of the specified type for the portfolio.

Added in ATAS 8.0.15.

public static T GetExtendedInfo<T>(this Portfolio portfolio) where T : IPortfolioExtendedInfo, new()

Parameters

portfolio Portfolio

The portfolio to get extended info from.

Returns

T

The existing or newly created extended info instance.

Type Parameters

T

The type of extended info to get or create.

GetMarketPrice(Security)

Returns the current market price of the security: the last trade price; otherwise the mid price of the best bid and ask; otherwise whichever of them is non-zero.

public static decimal? GetMarketPrice(this Security security)

Parameters

security Security

The security.

Returns

decimal?

The price, or null when there is neither a last trade nor a best bid or ask.

GetMoneyMultiplier(Security)

Returns the money value of a price move of one unit for one lot: TickCost / TickSize.

public static decimal GetMoneyMultiplier(this Security security)

Parameters

security Security

The security.

Returns

decimal

The multiplier, or 1 when the tick size is 0.

Exceptions

ArgumentNullException

security is null.

GetPositionInTicks(Position)

Calculates the position's unrealized profit/loss in ticks.

Added in ATAS 8.0.15.

public static decimal GetPositionInTicks(this Position position)

Parameters

position Position

The position to calculate ticks for.

Returns

decimal

The unrealized PnL expressed in ticks. Returns 0 if the position volume is zero.

Exceptions

ArgumentNullException

Thrown when position or position.Security.Security is null.

InvalidOperationException

Thrown when the security's TickCost is zero, making the calculation impossible.

GetSecurityCode(string)

public static string GetSecurityCode(this string ticker)

Parameters

ticker string

Returns

string

Security code part of the ticker. Example: NQH5 in -> NQ out

GetStatisticsServerUrl(Portfolio)

Builds the statistics server URL of the portfolio: takes StatisticsServerUrl from the user's group or its nearest ancestor that has one and formats it with the encrypted account ID as argument 0.

public static string? GetStatisticsServerUrl(this Portfolio portfolio)

Parameters

portfolio Portfolio

The portfolio.

Returns

string

The URL, or null when the portfolio has no user or group, or no group in the chain defines the URL.

Exceptions

ArgumentNullException

portfolio is null.

GetSubscriptionTypes(SubscriptionType)

Splits a combination of SubscriptionType flags into the individual flags it contains, excluding None.

public static IEnumerable<SubscriptionType> GetSubscriptionTypes(this SubscriptionType subscriptionTypes)

Parameters

subscriptionTypes SubscriptionType

The flags combination.

Returns

IEnumerable<SubscriptionType>

IsLong(HistoryMyTrade)

Checks whether the historical trade was a long trade: a positive opening volume, or a negative (sell) closing volume when the opening part is missing (Opening).

Added in ATAS 8.0.15.

public static bool IsLong(this HistoryMyTrade trade)

Parameters

trade HistoryMyTrade

The historical trade.

Returns

bool

IsMoexCurrencies(string)

Checks whether the exchange code is a Moscow Exchange currency board: CETS or CETS_MTL (case-sensitive).

public static bool IsMoexCurrencies(this string exchangeCode)

Parameters

exchangeCode string

The exchange (board) code.

Returns

bool

Exceptions

ArgumentNullException

exchangeCode is null.

IsMoexExchange(string)

Checks whether the exchange code is a Moscow Exchange futures, stocks or currency board.

public static bool IsMoexExchange(this string exchangeCode)

Parameters

exchangeCode string

The exchange (board) code.

Returns

bool

Exceptions

ArgumentNullException

exchangeCode is null.

IsMoexFutures(Security)

Checks whether the security belongs to a Moscow Exchange futures board; see IsMoexFutures(string).

public static bool IsMoexFutures(this Security security)

Parameters

security Security

The security.

Returns

bool

Exceptions

ArgumentNullException

security is null.

IsMoexFutures(string)

Checks whether the exchange code is a Moscow Exchange futures board: FORTS, SPBFUT or FUTEVN (case-sensitive).

public static bool IsMoexFutures(this string exchangeCode)

Parameters

exchangeCode string

The exchange (board) code.

Returns

bool

Exceptions

ArgumentNullException

exchangeCode is null.

IsMoexStocks(string)

Checks whether the exchange code is a Moscow Exchange stocks board: TQBR, TQPI, TQTF, TQTF_F or FQBR (case-sensitive).

public static bool IsMoexStocks(this string exchangeCode)

Parameters

exchangeCode string

The exchange (board) code.

Returns

bool

Exceptions

ArgumentNullException

exchangeCode is null.

IsReduceOnly(Order)

Checks whether the order's extended options request a reduce-only order.

public static bool IsReduceOnly(this Order order)

Parameters

order Order

The order.

Returns

bool

false when the extended options do not implement IOrderOptionReduceOnly.

Exceptions

ArgumentNullException

order is null.

IsReducingPosition(Position, OrderDirections)

Checks whether an order in the given direction would reduce the open position: selling a long or buying a short.

public static bool IsReducingPosition(this Position position, OrderDirections direction)

Parameters

position Position

The position.

direction OrderDirections

The direction of the order.

Returns

bool

false when the position is flat.

IsReplay(HistoryMyTrade)

Checks whether the historical trade belongs to the Replay account; false when it has no portfolio.

public static bool IsReplay(this HistoryMyTrade match)

Parameters

match HistoryMyTrade

The historical trade.

Returns

bool

IsReplay(MyTrade)

Checks whether the trade belongs to the Replay account; false when it has no portfolio.

public static bool IsReplay(this MyTrade trade)

Parameters

trade MyTrade

The trade.

Returns

bool

IsReplay(Order)

Checks whether the order belongs to the Replay account; see IsReplay(Portfolio).

public static bool? IsReplay(this Order order)

Parameters

order Order

The order.

Returns

bool?

null when the order has no portfolio.

IsReplay(Portfolio)

Checks whether the portfolio is the Replay account, i.e. its account ID is Replay.

public static bool IsReplay(this Portfolio portfolio)

Parameters

portfolio Portfolio

The portfolio.

Returns

bool

IsReplay(Position)

Checks whether the position belongs to the Replay account; false when it has no portfolio.

public static bool IsReplay(this Position position)

Parameters

position Position

The position.

Returns

bool

IsStopOrder(Order)

Returns true for Stop and StopLimit orders.

public static bool IsStopOrder(this Order order)

Parameters

order Order

The order.

Returns

bool

IsUsBond(IPriceFormatter)

Checks whether the security is a US Treasury futures contract whose prices are shown in fractional notation; see IsUsBond(string). Always false on Moscow Exchange futures boards.

Added in ATAS 8.0.15.

public static bool IsUsBond(this IPriceFormatter formatter)

Parameters

formatter IPriceFormatter

The price formatter of the security; its code is reduced to the root code before the check.

Returns

bool

Exceptions

ArgumentNullException

formatter is null.

IsUsBond(string)

Checks whether the root code is a US Treasury futures root: ZF, ZB, ZN, ZT, UB or TN.

Added in ATAS 8.0.15.

public static bool IsUsBond(this string code)

Parameters

code string

The root code, without the month and year.

Returns

bool

PriceToFormat(IPriceFormatter, decimal?)

Formats a price value according to the security's price format. For US Bond futures, uses fractional notation (e.g., 123'120).

Added in ATAS 8.0.15.

public static string? PriceToFormat(this IPriceFormatter formatter, decimal? price)

Parameters

formatter IPriceFormatter

The price formatter of the security to format the price for.

price decimal?

The price value to format.

Returns

string

Formatted price string, or null if price is null.

PriceToFormat(decimal?, bool, string)

Formats a price with the invariant culture. For US Treasury futures the result is the integer part and the fractional part in 1/320 units, for example 123'120 for 123.375.

Added in ATAS 8.0.15.

public static string? PriceToFormat(this decimal? price, bool isUsBond, string priceFormat)

Parameters

price decimal?

The price to format.

isUsBond bool

true to use the US Treasury fractional notation.

priceFormat string

A composite format string such as the result of ToPriceFormat(int), or a plain numeric format.

Returns

string

The formatted price, or null when price is null.

ReadConfig(Assembly)

Reads and decrypts the application configuration file platform.wl located in the folder of the assembly.

public static byte[] ReadConfig(this Assembly assembly)

Parameters

assembly Assembly

The assembly whose folder contains the configuration.

Returns

byte[]

The decrypted file content.

Exceptions

ArgumentNullException

assembly is null.

FileNotFoundException

The configuration file does not exist.

RoundToTickSize(Security, decimal)

Aligns a price to the security's minimum price increment (nearest tick, midpoint rounded away from zero). Returns the price unchanged when the tick size is unknown.

Added in ATAS 8.0.15.

public static decimal RoundToTickSize(this Security security, decimal price)

Parameters

security Security
price decimal

Returns

decimal

Status(Order)

Derives the display status of the order from its State and filled volume.

public static OrderStatus Status(this Order order)

Parameters

order Order

The order.

Returns

OrderStatus

For an active order: Placed when nothing is filled, otherwise PartlyFilled. For a done order: Filled when fully filled, otherwise Canceled (also when partly filled). None for any other state.

ToDisplayFormat(int)

Builds a numeric display format with up to precision optional decimal digits and no thousands separator.

public static string ToDisplayFormat(this int precision)

Parameters

precision int

The maximum number of decimal digits; 0 or less gives F0.

Returns

string

ToEditFormat(int)

Builds a numeric edit format with no thousands separator, at least one decimal digit and up to precision decimal digits.

public static string ToEditFormat(this int precision)

Parameters

precision int

The maximum number of decimal digits; 0 or less gives an integer format.

Returns

string

ToExpiration(DateTime)

Builds the futures expiration code of the month: the month letter (F, G, H, J, K, M, N, Q, U, V, X, Z) followed by the last digit of the year. For example, March 2025 gives H5.

public static string ToExpiration(this DateTime time)

Parameters

time DateTime

A date in the expiration month.

Returns

string

ToMoney(decimal, string)

Wraps the amount into Money in the given currency, with 3 decimal digits.

public static Money ToMoney(this decimal value, string currency)

Parameters

value decimal

The amount.

currency string

The currency code.

Returns

Money

ToMoneyFormat(string?, string)

Converts a money format template into a composite format string with the amount as argument 0 and the currency as argument 1. In the template v stands for the amount (optionally followed by : and a numeric format), c for the currency, and </code> escapes the next character.

public static string ToMoneyFormat(this string? format, string valueFormat)

Parameters

format string

The template; null is treated as v.

valueFormat string

The numeric format applied to the amount when the template does not specify one.

Returns

string

ToMoscowTimeFromUtc(DateTime)

Converts a UTC time to Moscow time.

public static DateTime ToMoscowTimeFromUtc(this DateTime dateTime)

Parameters

dateTime DateTime

The UTC time.

Returns

DateTime

Exceptions

ArgumentException

dateTime has System.DateTimeKind.Local kind.

ToPriceFormat(int)

Builds a composite format string that shows exactly digits decimal digits, for example {0:0.00} for 2.

Added in ATAS 8.0.15.

public static string ToPriceFormat(this int digits)

Parameters

digits int

The number of decimal digits.

Returns

string

ToQuoteMoney(Security, decimal)

Wraps the amount into Money in the quote currency of the security.

public static Money ToQuoteMoney(this Security security, decimal value)

Parameters

security Security

The security.

value decimal

The amount, in the quote currency.

Returns

Money

The money; the currency code is ??? when the quote currency is unknown, and the precision is taken from QuoteCurrencyPrecision or is 2 decimal digits when it is not set.

ToSecurityCodeInfo(string)

Splits a futures ticker into its root code, month letter and year digits, for example NQH5 into NQ, H and 5, or FDAXM25 into FDAX, M and 25.

public static (string code, string monthCode, string yearCode) ToSecurityCodeInfo(this string ticker)

Parameters

ticker string

The ticker.

Returns

(string code, string monthCode, string yearCode)

The parts; the month and year codes are empty when the ticker has no trailing digits or is at most two characters long.