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
-
objectExtensions
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
tickerstringThe 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
connectorIDataFeedConnectorThe connector.
Returns
- bool
Exceptions
- ArgumentNullException
connectoris 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
timeDateTimeThe 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
codestringThe search code, already in lower case; null matches any value.
valuestringThe value to check; an empty value matches any code.
fullMatchbooltrue 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
executionTThe execution.
portfolioPortfolioThe portfolio of the trade.
securitySecurityThe security of the trade.
updateAction<MyTrade, T>Copies the execution data into the new trade.
Returns
- MyTrade
The new trade.
Type Parameters
TThe connector-specific execution type.
Exceptions
- ArgumentNullException
Any argument is null.
ConvertToMyTrdes<T>(IEnumerable<T>, Portfolio, Security, Action<MyTrade, T>)
Converts each execution with ConvertToMyTrade<T>(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
executionsIEnumerable<T>The executions.
portfolioPortfolioThe portfolio of the trades.
securitySecurityThe security of the trades.
updateAction<MyTrade, T>Copies the execution data into each new trade.
Returns
- IEnumerable<MyTrade>
A materialized array of the new trades.
Type Parameters
TThe 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
tradingOptionsISecurityTradingOptionsThe trading options of the security.
typeOrderTypesThe order type.
Returns
- OrderExtendedOptions
The options object, or null when the connector has no extended options for this order type.
Exceptions
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
connectorIDataFeedConnectorThe connector that provides the security's trading options.
positionPositionThe position to close.
volumedecimal?The signed volume to close, in lots, with the sign of the position (positive closes a long by selling); null closes the whole position.
allowReduceOnlyboolCurrently not used: reduce-only is set whenever the connector supports it.
Returns
- Order
The new order.
Exceptions
- ArgumentNullException
connectororpositionis null.
Filled(Order)
Returns the volume filled so far: QuantityToFill - Unfilled.
public static decimal Filled(this Order order)
Parameters
orderOrderThe 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
securitiesIEnumerable<Security>The securities to filter.
filterSecurityFilteruseExchangeboolfalse to ignore the exchange.
codeFullMatchbooltrue to require an exact code match; otherwise the security code must contain the filter code.
exchangeFullMatchbooltrue 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
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
valuedecimalThe 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
portfolioPortfolioThe portfolio to get extended info from.
Returns
- T
The existing or newly created extended info instance.
Type Parameters
TThe 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
securitySecurityThe 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
securitySecurityThe security.
Returns
- decimal
The multiplier, or 1 when the tick size is 0.
Exceptions
- ArgumentNullException
securityis 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
positionPositionThe 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
positionorposition.Security.Securityis null.- InvalidOperationException
Thrown when the security's TickCost is zero, making the calculation impossible.
GetSecurityCode(string)
public static string GetSecurityCode(this string ticker)
Parameters
tickerstring
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
portfolioPortfolioThe 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
portfoliois 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
subscriptionTypesSubscriptionTypeThe 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
tradeHistoryMyTradeThe 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
exchangeCodestringThe exchange (board) code.
Returns
- bool
Exceptions
- ArgumentNullException
exchangeCodeis 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
exchangeCodestringThe exchange (board) code.
Returns
- bool
Exceptions
- ArgumentNullException
exchangeCodeis 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
securitySecurityThe security.
Returns
- bool
Exceptions
- ArgumentNullException
securityis 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
exchangeCodestringThe exchange (board) code.
Returns
- bool
Exceptions
- ArgumentNullException
exchangeCodeis 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
exchangeCodestringThe exchange (board) code.
Returns
- bool
Exceptions
- ArgumentNullException
exchangeCodeis null.
IsReduceOnly(Order)
Checks whether the order's extended options request a reduce-only order.
public static bool IsReduceOnly(this Order order)
Parameters
orderOrderThe order.
Returns
- bool
false when the extended options do not implement IOrderOptionReduceOnly.
Exceptions
- ArgumentNullException
orderis 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
positionPositionThe position.
directionOrderDirectionsThe 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
matchHistoryMyTradeThe 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
tradeMyTradeThe 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
orderOrderThe 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
portfolioPortfolioThe 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
positionPositionThe position.
Returns
- bool
IsStopOrder(Order)
public static bool IsStopOrder(this Order order)
Parameters
orderOrderThe 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
formatterIPriceFormatterThe price formatter of the security; its code is reduced to the root code before the check.
Returns
- bool
Exceptions
- ArgumentNullException
formatteris 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
codestringThe 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
formatterIPriceFormatterThe price formatter of the security to format the price for.
pricedecimal?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
pricedecimal?The price to format.
isUsBondbooltrue to use the US Treasury fractional notation.
priceFormatstringA composite format string such as the result of ToPriceFormat(int), or a plain numeric format.
Returns
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
assemblyAssemblyThe assembly whose folder contains the configuration.
Returns
- byte[]
The decrypted file content.
Exceptions
- ArgumentNullException
assemblyis 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
securitySecuritypricedecimal
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
orderOrderThe 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
precisionintThe 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
precisionintThe 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
timeDateTimeA 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
valuedecimalThe amount.
currencystringThe currency code.
Returns
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
formatstringThe template; null is treated as
v.valueFormatstringThe 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
dateTimeDateTimeThe UTC time.
Returns
- DateTime
Exceptions
- ArgumentException
dateTimehas 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
digitsintThe 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
securitySecurityThe security.
valuedecimalThe 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
tickerstringThe 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.