TraderHelper
The auxiliary class for provision of various algorithmic functionalities.
Properties
public static DataType IndicatorValue { get; }
value = TraderHelper.IndicatorValue
Indicator value.
Methods
public static IMessageAdapter AddAdapter(Connector connector, Type adapterType, Action<IMessageAdapter> init)
result = TraderHelper.AddAdapter(connector, adapterType, init)
Create IMessageAdapter.
- connector
- The class to create connections to trading systems.
- adapterType
- Adapter type.
- init
- Initialize adapter.
Returns: The class to create connections to trading systems.
public static TAdapter AddAdapter<TAdapter>(Connector connector, Action<TAdapter> init)
result = TraderHelper.AddAdapter(connector, init)
Create IMessageAdapter.
- connector
- The class to create connections to trading systems.
- init
- Initialize adapter.
Returns: The class to create connections to trading systems.
public static void AddOrderErrorLog(ILogReceiver receiver, Order order, string operation, Func<string> getAdditionalInfo)
TraderHelper.AddOrderErrorLog(receiver, order, operation, getAdditionalInfo)
Write order error to the log.
- receiver
- Logs receiver.
- order
- Order.
- operation
- Order action name.
- getAdditionalInfo
- Extended order info.
public static void AddOrderInfoLog(ILogReceiver receiver, Order order, string operation, Func<string> getAdditionalInfo)
TraderHelper.AddOrderInfoLog(receiver, order, operation, getAdditionalInfo)
Write order info to the log.
- receiver
- Logs receiver.
- order
- Order.
- operation
- Order action name.
- getAdditionalInfo
- Extended order info.
public static decimal ApplyOffset(decimal price, Sides side, Unit offset, Security security)
result = TraderHelper.ApplyOffset(price, side, offset, security)
To use shifting for price, depending on direction .
- price
- Price.
- side
- The order direction, used as shift direction (for buy the shift is added, for sell - subtracted).
- offset
- Price shift.
- security
- Security.
Returns: New price.
public static void CancelOrders(IConnector connector, IEnumerable<Order> orders, bool? isStopOrder, Portfolio portfolio, Sides? side, ExchangeBoard board, Security security, SecurityTypes? securityType)
TraderHelper.CancelOrders(connector, orders, isStopOrder, portfolio, side, board, security, securityType)
Cancel orders by filter.
- connector
- The connection of interaction with trade systems.
- orders
- The group of orders, from which the required orders shall be found and cancelled.
- isStopOrder
- , if cancel only a stop orders, - if regular orders, - both.
- portfolio
- Portfolio. If the value is equal to , then the portfolio does not match the orders cancel filter.
- side
- Order side. If the value is , the direction does not use.
- board
- Trading board. If the value is equal to , then the board does not match the orders cancel filter.
- security
- Instrument. If the value is equal to , then the instrument does not match the orders cancel filter.
- securityType
- Security type. If the value is , the type does not use.
public static ExpressionFormula<decimal> Compile(string expression, IFileSystem fileSystem, AssemblyLoadContextTracker tracker)
result = TraderHelper.Compile(expression, fileSystem, tracker)
Compile mathematical formula.
- expression
- Text expression.
- fileSystem
- File system.
- tracker
- AssemblyLoadContextTracker
Returns: Compiled mathematical formula.
public static Task<ExpressionFormula<decimal>> CompileAsync(string expression, IFileSystem fileSystem, AssemblyLoadContextTracker tracker, CancellationToken cancellationToken)
result = TraderHelper.CompileAsync(expression, fileSystem, tracker, cancellationToken)
Compile mathematical formula.
- expression
- Text expression.
- fileSystem
- File system.
- tracker
- AssemblyLoadContextTracker
- cancellationToken
- CancellationToken
Returns: Compiled mathematical formula.
public static Task<ExpressionFormula<TResult>> CompileAsync<TResult>(string expression, IFileSystem fileSystem, AssemblyLoadContextTracker tracker, CancellationToken cancellationToken)
result = TraderHelper.CompileAsync(expression, fileSystem, tracker, cancellationToken)
Compile mathematical formula.
- expression
- Text expression.
- fileSystem
- File system.
- tracker
- AssemblyLoadContextTracker
- cancellationToken
- CancellationToken
Returns: Compiled mathematical formula.
public static ExpressionFormula<TResult> Compile<TResult>(string expression, IFileSystem fileSystem, AssemblyLoadContextTracker tracker)
result = TraderHelper.Compile(expression, fileSystem, tracker)
Compile mathematical formula.
- expression
- Text expression.
- fileSystem
- File system.
- tracker
- AssemblyLoadContextTracker
Returns: Compiled mathematical formula.
public static bool Contains(BasketSecurity basketSecurity, ISecurityProvider securityProvider, Security security)
result = TraderHelper.Contains(basketSecurity, securityProvider, security)
To check whether specified instrument is used now.
- basketSecurity
- Instruments basket.
- securityProvider
- The provider of information about instruments.
- security
- The instrument that should be checked.
Returns: , if specified instrument is used now, otherwise .
public static IBasketSecurityProcessor CreateProcessor(IBasketSecurityProcessorProvider processorProvider, Security security)
result = TraderHelper.CreateProcessor(processorProvider, security)
Create market data processor for basket securities.
- processorProvider
- Basket security processors provider.
- security
- Basket security.
Returns: Market data processor for basket securities.
public static ValueTask DeleteAllAsync(ISecurityStorage storage, CancellationToken cancellationToken)
result = TraderHelper.DeleteAllAsync(storage, cancellationToken)
To delete all instruments.
- storage
- Securities meta info storage.
- cancellationToken
- CancellationToken
public static IAsyncEnumerable<BoardMessage> ExtractBoardsAsync(byte[] archive)
result = TraderHelper.ExtractBoardsAsync(archive)
Extract boards from the archive.
- archive
- The archive.
Returns: Boards.
public static IAsyncEnumerable<SecurityMessage> ExtractSecuritiesAsync(byte[] archive)
result = TraderHelper.ExtractSecuritiesAsync(archive)
Extract securities from the archive.
- archive
- The archive.
Returns: Securities.
public static void FillFortsJumps(ExpirationContinuousSecurity continuousSecurity, ISecurityProvider provider, string baseCode, DateTime from, DateTime to)
TraderHelper.FillFortsJumps(continuousSecurity, provider, baseCode, from, to)
To fill transitions ExpirationJumps.
- continuousSecurity
- Continuous security.
- provider
- The provider of information about instruments.
- baseCode
- The base part of the instrument code.
- from
- The start of the expiration range.
- to
- The end of the expiration range.
public static IEnumerable<Order> Filter(IEnumerable<Order> orders, Security security)
result = TraderHelper.Filter(orders, security)
To filter orders for the given instrument.
- orders
- All orders, in which the required shall be searched for.
- security
- The instrument, for which the orders shall be filtered.
Returns: Filtered orders.
public static IEnumerable<Position> Filter(IEnumerable<Position> positions, Security security)
result = TraderHelper.Filter(positions, security)
To filter positions for the given instrument.
- positions
- All positions, in which the required shall be searched for.
- security
- The instrument, for which positions shall be filtered.
Returns: Filtered positions.
public static IEnumerable<MyTrade> Filter(IEnumerable<MyTrade> myTrades, Security security)
result = TraderHelper.Filter(myTrades, security)
To filter own trades for the given instrument.
- myTrades
- All own trades, in which the required shall be looked for.
- security
- The instrument, on which the trades shall be found.
Returns: Filtered trades.
public static string GenerateId(SecurityIdGenerator generator, string secCode, ExchangeBoard board)
result = TraderHelper.GenerateId(generator, secCode, board)
Generate SecurityId security.
- generator
- SecurityIdGenerator
- secCode
- Security code.
- board
- Security board.
Returns: Id security.
public static Security GetAllSecurity(ISecurityProvider provider)
result = TraderHelper.GetAllSecurity(provider)
Find AllSecurity instance in the specified provider.
- provider
- The provider of information about instruments.
Returns: Found instance.
public static decimal? GetCurrentPrice(Security security, IMarketDataProvider provider, Sides? direction)
result = TraderHelper.GetCurrentPrice(security, provider, direction)
To calculate the current price by the instrument depending on the order direction.
- security
- The instrument used for the current price calculation.
- provider
- The market data provider.
- direction
- Order side.
Returns: The current price. If information in order book is insufficient, then will be returned.
public static Sides? GetDirection(decimal position)
result = TraderHelper.GetDirection(position)
To get the order direction for the position.
- position
- The position value.
Returns: Order side.
public static Sides? GetDirection(Position position)
result = TraderHelper.GetDirection(position)
To get the order direction for the position.
- position
- The position value.
Returns: Order side.
public static IEnumerable<Security> GetFortsJumps(string baseCode, DateTime from, DateTime to, Func<string, Security> getSecurity, bool throwIfNotExists)
result = TraderHelper.GetFortsJumps(baseCode, from, to, getSecurity, throwIfNotExists)
To get real expiration instruments for base part of the code.
- baseCode
- The base part of the instrument code.
- from
- The start of the expiration range.
- to
- The end of the expiration range.
- getSecurity
- The function to get instrument by the code.
- throwIfNotExists
- To generate exception, if some of instruments are not available.
Returns: Expiration instruments.
public static IEnumerable<Security> GetFortsJumps(ExpirationContinuousSecurity continuousSecurity, ISecurityProvider provider, string baseCode, DateTime from, DateTime to, bool throwIfNotExists)
result = TraderHelper.GetFortsJumps(continuousSecurity, provider, baseCode, from, to, throwIfNotExists)
To get real expiration instruments for the continuous instrument.
- continuousSecurity
- Continuous security.
- provider
- The provider of information about instruments.
- baseCode
- The base part of the instrument code.
- from
- The start of the expiration range.
- to
- The end of the expiration range.
- throwIfNotExists
- To generate exception, if some of instruments for passed are not available.
Returns: Expiration instruments.
public static IEnumerable<Security> GetInnerSecurities(BasketSecurity security, ISecurityProvider securityProvider)
result = TraderHelper.GetInnerSecurities(security, securityProvider)
Find inner security instances.
- security
- Instruments basket.
- securityProvider
- The provider of information about instruments.
Returns: Instruments, from which this basket is created.
public static Security GetOrCreate(ISecurityStorage storage, SecurityId id, Func<string, Security> creator, bool isNew)
result = TraderHelper.GetOrCreate(storage, id, creator, isNew)
Get or create (if not exist).
- storage
- Securities meta info storage.
- id
- Security ID.
- creator
- Creator.
- isNew
- Is newly created.
Returns: Security.
public static ValueTask<ValueTuple<Security, bool>> GetOrCreateAsync(ISecurityStorage storage, SecurityId id, Func<string, Security> creator, CancellationToken cancellationToken)
result = TraderHelper.GetOrCreateAsync(storage, id, creator, cancellationToken)
Get or create (if not exist).
- storage
- Securities meta info storage.
- id
- Security ID.
- creator
- Creator.
- cancellationToken
- CancellationToken
Returns: Security and the flag whether it was newly created.
public static Portfolio GetOrCreatePortfolio(IPositionStorage storage, string portfolioName, Func<string, Portfolio> creator, bool isNew)
result = TraderHelper.GetOrCreatePortfolio(storage, portfolioName, creator, isNew)
Get or create (if not exist).
- storage
- Storage.
- portfolioName
- Portfolio code name.
- creator
- Creator.
- isNew
- Is newly created.
Returns: Portfolio.
public static Position GetOrCreatePosition(IPositionStorage storage, Portfolio portfolio, Security security, string strategyId, Sides? side, string clientCode, string depoName, TPlusLimits? limitType, Func<Portfolio, Security, string, Sides?, string, string, TPlusLimits?, Position> creator, bool isNew)
result = TraderHelper.GetOrCreatePosition(storage, portfolio, security, strategyId, side, clientCode, depoName, limitType, creator, isNew)
Get or create (if not exist).
- storage
- Storage.
- portfolio
- Portfolio.
- security
- Security.
- strategyId
- Strategy ID.
- side
- Side.
- clientCode
- Client code.
- depoName
- Depo name.
- limitType
- Limit type.
- creator
- Creator.
- isNew
- Is newly created.
Returns: Position.
public static decimal GetPnL(IPnLManager manager)
result = TraderHelper.GetPnL(manager)
Get the total profit and loss (PnL) value.
- manager
- IPnLManager
Returns: Total profit and loss (PnL) value, which is the sum of unrealized and realized PnL.
public static decimal? GetPnL(Portfolio portfolio)
result = TraderHelper.GetPnL(portfolio)
To calculate profit-loss based on the portfolio.
- portfolio
- The portfolio, for which the profit-loss shall be calculated.
Returns: Profit-loss.
public static decimal GetPosition(MyTrade trade)
result = TraderHelper.GetPosition(trade)
To get the position on own trade.
- trade
- Own trade, used for position calculation. At buy the trade volume Volume is taken with positive sign, at sell - with negative.
Returns: Position.
public static Security GetSecurityCriteria(Connector connector, SecurityLookupMessage criteria, IExchangeInfoProvider exchangeInfoProvider)
result = TraderHelper.GetSecurityCriteria(connector, criteria, exchangeInfoProvider)
To create the search criteria Security from SecurityLookupMessage.
- connector
- Connection to the trading system.
- criteria
- The criterion which fields will be used as a filter.
- exchangeInfoProvider
- Exchanges and trading boards provider.
Returns: Search criterion.
public static IDictionary<Level1Fields, object> GetSecurityValues(IMarketDataProvider provider, Security security)
result = TraderHelper.GetSecurityValues(provider, security)
To get all market data values for the instrument.
- provider
- The market data provider.
- security
- Security.
Returns: Filed values. If there is no data, is returned.
public static T GetSecurityValue<T>(IMarketDataProvider provider, Security security, Level1Fields field)
result = TraderHelper.GetSecurityValue(provider, security, field)
To get the value of market data for the instrument.
- provider
- The market data provider.
- security
- Security.
- field
- Market-data field.
Returns: The field value. If no data, the will be returned.
public static bool IsAssociated(SecurityId securityId, ExchangeBoard board)
result = TraderHelper.IsAssociated(securityId, board)
Is specified security id associated with the board.
- securityId
- Security ID.
- board
- Board info.
Returns: , if associated, otherwise, .
public static bool IsBasket(Security security)
result = TraderHelper.IsBasket(security)
Is specified security is basket.
- security
- Security.
Returns: Check result.
public static bool IsContinuous(Security security)
result = TraderHelper.IsContinuous(security)
Is specified security is continuous.
- security
- Security.
Returns: Check result.
public static bool IsContinuous(SecurityMessage security)
result = TraderHelper.IsContinuous(security)
Is specified security is continuous.
- security
- Security.
Returns: Check result.
public static bool IsIndex(Security security)
result = TraderHelper.IsIndex(security)
Is specified security is index.
- security
- Security.
Returns: Check result.
public static bool IsStockSharp(News news)
result = TraderHelper.IsStockSharp(news)
Determines whether the specified news related with StockSharp.
- news
- News.
Returns: Check result.
public static bool IsTradeTime(ExchangeBoard board, DateTime time, bool? isWorkingDay, WorkingTimePeriod period)
result = TraderHelper.IsTradeTime(board, time, isWorkingDay, period)
To check, whether the time is traded (has the session started, ended, is there a clearing).
- board
- Board info.
- time
- The passed time to be checked.
- isWorkingDay
- , if the date is traded, otherwise, is not traded.
- period
- Current working time period.
Returns: , if time is traded, otherwise, not traded.
public static bool IsTradeTime(ExchangeBoard board, DateTime time)
result = TraderHelper.IsTradeTime(board, time)
To check, whether the time is traded (has the session started, ended, is there a clearing).
- board
- Board info.
- time
- The passed time to be checked.
Returns: , if time is traded, otherwise, not traded.
public static IEnumerable<Security> Lookup(ISecurityProvider provider, Security criteria)
result = TraderHelper.Lookup(provider, criteria)
Lookup securities by criteria .
- provider
- The provider of information about instruments.
- criteria
- The instrument whose fields will be used as a filter.
Returns: Found instruments.
public static IEnumerable<Security> LookupAll(ISecurityProvider provider)
result = TraderHelper.LookupAll(provider)
Get all available instruments.
- provider
- The provider of information about instruments.
Returns: All available instruments.
public static void LookupAll(Connector connector)
TraderHelper.LookupAll(connector)
Lookup securities, portfolios and orders.
- connector
- The connection of interaction with trade systems.
public static IAsyncEnumerable<Security> LookupAllAsync(ISecurityProvider provider)
result = TraderHelper.LookupAllAsync(provider)
Get all available instruments.
- provider
- The provider of information about instruments.
Returns: All available instruments.
public static IEnumerable<Security> LookupByCode(ISecurityProvider provider, string code, SecurityTypes? type)
result = TraderHelper.LookupByCode(provider, code, type)
To get the instrument by the instrument code.
- provider
- The provider of information about instruments.
- code
- Security code.
- type
- Security type.
Returns: The got instrument. If there is no instrument by given criteria, is returned.
public static ValueTask<Security> LookupByNativeIdAsync(ISecurityProvider provider, INativeIdStorageProvider nativeIdStorageProvider, string storageName, object nativeId, CancellationToken cancellationToken)
result = TraderHelper.LookupByNativeIdAsync(provider, nativeIdStorageProvider, storageName, nativeId, cancellationToken)
To get the instrument by the system identifier.
- provider
- The provider of information about instruments.
- nativeIdStorageProvider
- Security native identifier storage provider.
- storageName
- Storage name.
- nativeId
- Native (internal) trading system security id.
- cancellationToken
- CancellationToken
Returns: The got instrument. If there is no instrument by given criteria, is returned.
public static void ShrinkPrice(Order order, ShrinkRules rule)
TraderHelper.ShrinkPrice(order, rule)
To cut the price for the order, to make it multiple of the minimal step, also to limit number of decimal places.
- order
- The order for which the price will be cut Price.
- rule
- The price rounding rule.
public static decimal ShrinkPrice(Security security, decimal price, ShrinkRules rule)
result = TraderHelper.ShrinkPrice(security, price, rule)
To cut the price, to make it multiple of minimal step, also to limit number of signs after the comma.
- security
- The instrument from which the PriceStep and Decimals values are taken.
- price
- The price to be made multiple.
- rule
- The price rounding rule.
Returns: The multiple price.
public static BasketSecurity ToBasket(Security security, IBasketSecurityProcessorProvider processorProvider)
result = TraderHelper.ToBasket(security, processorProvider)
Convert Security to BasketSecurity value.
- security
- Security.
- processorProvider
- Basket security processors provider.
Returns: Instruments basket.
public static IAsyncEnumerable<TMessage> ToBasket<TMessage>(IAsyncEnumerable<TMessage> innerSecMessages, Security security, IBasketSecurityProcessorProvider processorProvider)
result = TraderHelper.ToBasket(innerSecMessages, security, processorProvider)
Convert inner securities messages to basket.
- innerSecMessages
- Inner securities messages.
- security
- Basket security.
- processorProvider
- Basket security processors provider.
Returns: Messages of basket securities.
public static IEnumerable<TMessage> ToBasket<TMessage>(IEnumerable<TMessage> innerSecMessages, Security security, IBasketSecurityProcessorProvider processorProvider)
result = TraderHelper.ToBasket(innerSecMessages, security, processorProvider)
Convert inner securities messages to basket.
- innerSecMessages
- Inner securities messages.
- security
- Basket security.
- processorProvider
- Basket security processors provider.
Returns: Messages of basket securities.
public static TBasketSecurity ToBasket<TBasketSecurity>(Security security)
result = TraderHelper.ToBasket(security)
Convert Security to BasketSecurity value.
- security
- Security.
Returns: Instruments basket.
public static ChannelStates ToChannelState(ProcessStates state)
result = TraderHelper.ToChannelState(state)
Convert ProcessStates value to ChannelStates.
- state
- ProcessStates value.
Returns: ChannelStates value.
public static ProcessStates ToProcessState(ChannelStates state)
result = TraderHelper.ToProcessState(state)
Convert ChannelStates value to ProcessStates.
- state
- ChannelStates value.
Returns: ProcessStates value.
public static IEnumerable<TimeQuoteChange> ToTimeQuotes(QuoteChangeMessage message)
result = TraderHelper.ToTimeQuotes(message)
Convert depth to quotes.
- message
- Depth.
Returns: Quotes.
public static IEnumerable<TimeQuoteChange> ToTimeQuotes(IEnumerable<QuoteChangeMessage> messages)
result = TraderHelper.ToTimeQuotes(messages)
Convert depths to quotes.
- messages
- Depths.
Returns: Quotes.
public static IMessageAdapter TryGetAdapter(IPortfolioMessageAdapterProvider portfolioProvider, IEnumerable<IMessageAdapter> adapters, Portfolio portfolio)
result = TraderHelper.TryGetAdapter(portfolioProvider, adapters, portfolio)
Get adapter by portfolio.
- portfolioProvider
- The portfolio based message adapter's provider.
- adapters
- All available adapters.
- portfolio
- Portfolio.
Returns: Found adapter or .
public static IMessageAdapter TryGetAdapter(IPortfolioMessageAdapterProvider portfolioProvider, IMessageAdapterProvider adapterProvider, Portfolio portfolio)
result = TraderHelper.TryGetAdapter(portfolioProvider, adapterProvider, portfolio)
Get adapter by portfolio.
- portfolioProvider
- The portfolio based message adapter's provider.
- adapterProvider
- The message adapter's provider.
- portfolio
- Portfolio.
Returns: Found adapter or .
public static string ValidateId(string id)
result = TraderHelper.ValidateId(id)
To check the correctness of the entered identifier.
- id
- Security ID.
Returns: An error message text, or if no error.