Strategy
The base class for all trade strategies.
Inherits: BaseLogReceiver
Implements: INotifyPropertyChangedEx, INotifyPropertyChanged, IMarketRuleContainer, ILogReceiver, ILogSource, IDisposable, ICloneable<Strategy>, ICloneable, IMarketDataProvider, ISubscriptionProvider, ISecurityProvider, ISecurityMessageProvider, ITransactionProvider, IScheduledTask, ICustomTypeDescriptor, ITimeProvider, IPortfolioProvider, IPositionProvider, IReportSource
Constructors
Properties
public TimeSpan AggregationInterval { get; set; }
value = strategy.AggregationInterval
strategy.AggregationInterval = value
Time interval for aggregation. Orders/trades within the same interval are grouped together. Default is 1 hour. Set to Zero to disable time-based grouping.
public bool CancelOrdersWhenStopping { get; set; }
value = strategy.CancelOrdersWhenStopping
strategy.CancelOrdersWhenStopping = value
To cancel active orders at stop. Is On by default.
public INotifyList<Strategy> ChildStrategies { get; }
value = strategy.ChildStrategies
Subsidiary trade strategies.
public StrategyCommentModes CommentMode { get; set; }
value = strategy.CommentMode
strategy.CommentMode = value
Set Comment by Name or Id.
public decimal? Commission { get; private set; }
value = strategy.Commission
strategy.Commission = value
Total commission.
public virtual Connector Connector { get; set; }
value = strategy.Connector
strategy.Connector = value
Connection to the trading system.
public override DateTime CurrentTime { get; }
value = strategy.CurrentTime
Current time.
public bool DisposeOnStop { get; set; }
value = strategy.DisposeOnStop
strategy.DisposeOnStop = value
Automatically to clear resources, used by the strategy, when it stops (state ProcessState becomes equal to Stopped).
public SettingsStorage Environment { get; }
value = strategy.Environment
Strategy environment parameters.
public LogLevels ErrorState { get; private set; }
value = strategy.ErrorState
strategy.ErrorState = value
The state of an error.
public static bool HideSecurityAndPortfolioParameters { get; set; }
value = Strategy.HideSecurityAndPortfolioParameters
Strategy.HideSecurityAndPortfolioParameters = value
Make Security and Portfolio as non-browsable.
protected virtual TimeSpan? HistoryCalculated { get; }
value = strategy.HistoryCalculated
Calculated from code version of HistorySize.
public TimeSpan? HistorySize { get; set; }
value = strategy.HistorySize
strategy.HistorySize = value
History to initialize the strategy on Live trading.
public INotifyList<IIndicator> Indicators { get; }
value = strategy.Indicators
All indicators used in strategy. Uses in default implementation of IsFormed.
public Level1Fields? IndicatorSource { get; set; }
value = strategy.IndicatorSource
strategy.IndicatorSource = value
Default source for indicators when Source is not set.
public bool IsBacktesting { get; }
value = strategy.IsBacktesting
Determines Connector is HistoryEmulationConnector.
public bool IsOnline { get; private set; }
value = strategy.IsOnline
strategy.IsOnline = value
True means that strategy is started and all of its subscriptions are in online state.
public bool IsRulesSuspended { get; }
value = strategy.IsRulesSuspended
Is rules execution suspended.
public bool KeepStatistics { get; set; }
value = strategy.KeepStatistics
strategy.KeepStatistics = value
Keep trading statistics (orders, trades, profit etc.) after restart.
public Exception LastError { get; private set; }
value = strategy.LastError
strategy.LastError = value
The last error that caused the strategy to stop.
public TimeSpan? Latency { get; private set; }
value = strategy.Latency
strategy.Latency = value
Total latency.
public override LogLevels LogLevel { get; set; }
value = strategy.LogLevel
strategy.LogLevel = value
The level to perform this rule logging.
public int MaxOrdersBeforeAggregation { get; set; }
value = strategy.MaxOrdersBeforeAggregation
strategy.MaxOrdersBeforeAggregation = value
Maximum number of orders before automatic aggregation is triggered. Default is 10000. Set to 0 to disable automatic aggregation.
public int MaxTradesBeforeAggregation { get; set; }
value = strategy.MaxTradesBeforeAggregation
strategy.MaxTradesBeforeAggregation = value
Maximum number of trades before automatic aggregation is triggered. Default is 10000. Set to 0 to disable automatic aggregation.
public IEnumerable<MyTrade> MyTrades { get; }
value = strategy.MyTrades
Trades, matched during the strategy operation.
public override string Name { get; set; }
value = strategy.Name
strategy.Name = value
Strategy name.
public StrategyNameGenerator NameGenerator { get; }
value = strategy.NameGenerator
The generator of strategy name.
public virtual IEnumerable<IOrderBookSource> OrderBookSources { get; }
value = strategy.OrderBookSources
All possible IOrderBookMessage sources that can be received via OrderBookDrawing.
public Subscription OrderLookup { get; }
value = strategy.OrderLookup
Get global subscription on Order lookup. Can be .
public IEnumerable<Order> Orders { get; }
value = strategy.Orders
Orders, registered within the strategy framework.
public TimeSpan OrdersKeepTime { get; set; }
value = strategy.OrdersKeepTime
strategy.OrdersKeepTime = value
The time for storing Orders in memory. By default it equals to 2 days. If value is set in Zero, orders will not be deleted.
public StrategyParameterDictionary Parameters { get; }
value = strategy.Parameters
Strategy parameters.
public decimal PnL { get; }
value = strategy.PnL
The aggregate value of profit-loss without accounting commission Commission.
public IPnLManager PnLManager { get; set; }
value = strategy.PnLManager
strategy.PnLManager = value
The profit-loss manager.
public Portfolio Portfolio { get; set; }
value = strategy.Portfolio
strategy.Portfolio = value
Portfolio.
public Subscription PortfolioLookup { get; }
value = strategy.PortfolioLookup
Get global subscription on Portfolio lookup. Can be .
public IPortfolioProvider PortfolioProvider { get; set; }
value = strategy.PortfolioProvider
strategy.PortfolioProvider = value
IPortfolioProvider
public decimal Position { get; set; }
value = strategy.Position
strategy.Position = value
The position aggregate value.
public IEnumerable<Position> Positions { get; }
value = strategy.Positions
Get all positions.
public virtual ProcessStates ProcessState { get; private set; }
value = strategy.ProcessState
strategy.ProcessState = value
The operation state.
public ReportSource ReportSource { get; }
value = strategy.ReportSource
Report data source with aggregation support.
public decimal RiskFreeRate { get; set; }
value = strategy.RiskFreeRate
strategy.RiskFreeRate = value
Annual risk-free rate (e.g., 0.03 = 3%).
public IRiskManager RiskManager { get; set; }
value = strategy.RiskManager
strategy.RiskManager = value
The risks control manager.
public IEnumerable<IRiskRule> RiskRules { get; set; }
value = strategy.RiskRules
strategy.RiskRules = value
The risk rules.
public Security Security { get; set; }
value = strategy.Security
strategy.Security = value
Security.
public decimal? Slippage { get; private set; }
value = strategy.Slippage
strategy.Slippage = value
Total slippage.
public DateTime StartedTime { get; private set; }
value = strategy.StartedTime
strategy.StartedTime = value
Strategy start time.
public IStatisticManager StatisticManager { get; protected set; }
value = strategy.StatisticManager
strategy.StatisticManager = value
The statistics manager.
public Func<Sides, decimal, IPositionModifyAlgo> TargetAlgoFactory { get; set; }
value = strategy.TargetAlgoFactory
strategy.TargetAlgoFactory = value
Factory to create position modify algorithms for TargetPositionManager. Default creates MarketOrderAlgo.
public PositionTargetManager TargetPositionManager { get; }
value = strategy.TargetPositionManager
Target position manager.
public TimeSpan TotalWorkingTime { get; private set; }
value = strategy.TotalWorkingTime
strategy.TotalWorkingTime = value
The total time of strategy operation less time periods, when strategy was stopped.
public StrategyTradingModes TradingMode { get; set; }
value = strategy.TradingMode
strategy.TradingMode = value
Allow trading.
public TimeSpan UnrealizedPnLInterval { get; set; }
value = strategy.UnrealizedPnLInterval
strategy.UnrealizedPnLInterval = value
The interval for unrealized profit recalculation. The default value is 1 minute.
public bool UnsubscribeOnStop { get; set; }
value = strategy.UnsubscribeOnStop
strategy.UnsubscribeOnStop = value
Unsubscribe all active subscription while strategy become stopping.
public virtual decimal Volume { get; set; }
value = strategy.Volume
strategy.Volume = value
Operational volume.
public bool WaitAllTrades { get; set; }
value = strategy.WaitAllTrades
strategy.WaitAllTrades = value
Stop strategy only after getting all trades by registered orders.
public bool WaitRulesOnStop { get; set; }
value = strategy.WaitRulesOnStop
strategy.WaitRulesOnStop = value
Wait Rules to finish before strategy become into Stopped state.
public WorkingTime WorkingTime { get; set; }
value = strategy.WorkingTime
strategy.WorkingTime = value
The time boundary, within which candles for give series shall be translated.
Methods
protected void Alert(AlertNotifications type, string message)
strategy.Alert(type, message)
Send alert notification with strategy name as caption.
- type
- Alert type.
- message
- Alert text.
protected void Alert(AlertNotifications type, string caption, string message)
strategy.Alert(type, caption, message)
Send alert notification.
- type
- Alert type.
- caption
- Signal header.
- message
- Alert text.
protected void AlertLog(string message)
strategy.AlertLog(message)
Send log alert notification.
- message
- Alert text.
protected void AlertPopup(string message)
strategy.AlertPopup(message)
Send popup alert notification.
- message
- Alert text.
protected void AlertSound(string message)
strategy.AlertSound(message)
Send sound alert notification.
- message
- Alert text.
public virtual void ApplyCommand(CommandMessage cmdMsg)
strategy.ApplyCommand(cmdMsg)
Apply incoming command.
- cmdMsg
- The message contains information about command to change state.
public Order BuyLimit(decimal price, decimal? volume, Security security)
result = strategy.BuyLimit(price, volume, security)
To create the initialized order object for buy.
- price
- Price.
- volume
- The volume. If value is passed, then Volume value is used.
- security
- The security. If value is passed, then Security value is used.
Returns: The initialized order object.
public Order BuyMarket(decimal? volume, Security security)
result = strategy.BuyMarket(volume, security)
To create initialized object of buy order at market price.
- volume
- The volume. If value is passed, then Volume value is used.
- security
- The security. If value is passed, then Security value is used.
Returns: The initialized order object.
protected virtual bool CanAttach(Order order)
result = strategy.CanAttach(order)
Determines the specified order can be owned by the strategy.
- order
- Order.
Returns: Check result.
public void CancelActiveOrders(bool? isStopOrder, Portfolio portfolio, Sides? direction, ExchangeBoard board, Security security, SecurityTypes? securityType, long? transactionId)
strategy.CancelActiveOrders(isStopOrder, portfolio, direction, board, security, securityType, transactionId)
To cancel all active orders (to stop and regular).
- 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.
- direction
- 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.
- transactionId
- Order cancellation transaction id.
public void CancelOrder(Order order)
strategy.CancelOrder(order)
Cancel the order.
- order
- The order which should be canceled.
public void CancelTargetPosition(Security security, Portfolio portfolio)
strategy.CancelTargetPosition(security, portfolio)
Cancel target position for specified security and portfolio.
- security
- Security.
- portfolio
- Portfolio.
public void CancelTargetPosition()
strategy.CancelTargetPosition()
Cancel target position for the strategy's Security and Portfolio.
protected virtual bool CanTrade(Security security, Portfolio portfolio, Sides side, decimal volume, string noTradeReason)
result = strategy.CanTrade(security, portfolio, side, volume, noTradeReason)
Check if can trade with order information.
- security
- Security to trade.
- portfolio
- Portfolio to trade.
- side
- Order side.
- volume
- Order volume.
- noTradeReason
- Reason why trading is not allowed.
Returns: True if trading is allowed.
public Order ClosePosition(Security security, Portfolio portfolio)
result = strategy.ClosePosition(security, portfolio)
To close open position by market (to register the order of the type Market).
- security
- Security. If not passed the value from Security will be obtain.
- portfolio
- Portfolio. If not passed the value from Portfolio will be obtain.
Returns: The initialized order object.
protected virtual void CopyTo(Strategy copy)
strategy.CopyTo(copy)
Copy settings into .
- copy
- Strategy
protected IChartArea CreateChartArea()
result = strategy.CreateChartArea()
Create chart area.
Returns: IChartArea
protected virtual Strategy CreateClone()
result = strategy.CreateClone()
Create clone object (non-initialized).
Returns: Strategy
public Order CreateOrder(Sides side, decimal price, decimal? volume)
result = strategy.CreateOrder(side, price, volume)
To create the initialized order object.
- side
- Order side.
- price
- The price. If value is passed, the order is registered at market price.
- volume
- The volume. If value is passed, then Volume value is used.
Returns: The initialized order object.
protected ITimerHandler CreateTimer(TimeSpan interval, Action callback)
result = strategy.CreateTimer(interval, callback)
Create a timer that executes callback at specified intervals.
- interval
- Timer interval.
- callback
- Callback to execute.
Returns: ITimerHandler
protected override void DisposeManaged()
strategy.DisposeManaged()
Release resources.
protected IChartCandleElement DrawCandles(IChartArea area, Subscription subscription)
result = strategy.DrawCandles(area, subscription)
Draw candles on chart.
- area
- IChartArea
- subscription
- Subscription
Returns: IChartCandleElement
protected IChartCandleElement DrawCandles<T>(IChartArea area, ISubscriptionHandler<T> subscription)
result = strategy.DrawCandles(area, subscription)
Draw candles on chart.
- area
- IChartArea
- subscription
- SubscriptionHandler
Returns: IChartCandleElement
protected IChartIndicatorElement DrawIndicator(IChartArea area, IIndicator indicator, Color? color, Color? additionalColor)
result = strategy.DrawIndicator(area, indicator, color, additionalColor)
Draw indicator on chart.
- area
- IChartArea
- indicator
- IIndicator
- color
- Color
- additionalColor
- AdditionalColor
Returns: IChartIndicatorElement
public void DrawOrderBook(Subscription subscription, IOrderBookSource source, IOrderBookMessage book)
strategy.DrawOrderBook(subscription, source, book)
Draw IOrderBookMessage.
- subscription
- Subscription
- source
- IOrderBookSource
- book
- IOrderBookMessage
public void DrawOrderBookOrder(Subscription subscription, IOrderBookSource source, Order order)
strategy.DrawOrderBookOrder(subscription, source, order)
Draw order book order.
- subscription
- Subscription
- source
- IOrderBookSource
- order
- Order.
public void DrawOrderBookOrderFail(Subscription subscription, IOrderBookSource source, OrderFail fail)
strategy.DrawOrderBookOrderFail(subscription, source, fail)
Draw order book order fail.
- subscription
- Subscription
- source
- IOrderBookSource
- fail
- Order fail.
protected IChartOrderElement DrawOrders(IChartArea area)
result = strategy.DrawOrders(area)
Draw orders on chart.
- area
- IChartArea
Returns: IChartOrderElement
protected IChartTradeElement DrawOwnTrades(IChartArea area)
result = strategy.DrawOwnTrades(area)
Draw trades on chart.
- area
- IChartArea
Returns: IChartTradeElement
public void EditOrder(Order order, Order changes)
strategy.EditOrder(order, changes)
Edit the order.
- order
- Order.
- changes
- Order changes.
private void EnsureOrderMetadata(Order order, DateTime fallbackTime)
strategy.EnsureOrderMetadata(order, fallbackTime)
Ensures the order has metadata required by strategy surfaces.
- order
- Order.
- fallbackTime
- Fallback time.
public IAlertNotificationService GetAlertService()
result = strategy.GetAlertService()
To get the IAlertNotificationService associated with the passed strategy.
Returns: Alert notification service.
public IChart GetChart()
result = strategy.GetChart()
To get the IChart associated with the passed strategy.
Returns: Chart.
public IOptionDesk GetOptionDesk()
result = strategy.GetOptionDesk()
To get the IOptionDesk.
Returns: IOptionDesk.
public IOptionPositionChart GetOptionPositionChart()
result = strategy.GetOptionPositionChart()
To get the IOptionPositionChart associated with the passed strategy.
Returns: Chart.
public virtual IStrategyParam[] GetParameters()
result = strategy.GetParameters()
Get parameters.
Returns: Parameters.
public Portfolio GetPortfolio()
result = strategy.GetPortfolio()
Get Portfolio or throw InvalidOperationException if not present.
Returns: Portfolio
public decimal? GetPositionValue(Security security, Portfolio portfolio)
result = strategy.GetPositionValue(security, portfolio)
Get position.
- security
- Security.
- portfolio
- Portfolio.
Returns: Position.
public Security GetSecurity()
result = strategy.GetSecurity()
Get Security or throw InvalidOperationException if not present.
Returns: Security
public T GetSecurityValue<T>(Level1Fields field)
result = strategy.GetSecurityValue(field)
To get market data value for the strategy instrument.
- field
- Market-data field.
Returns: The field value. If no data, the will be returned.
protected TValue GetStatValue<TParam, TValue>(TValue fallback)
result = strategy.GetStatValue(fallback)
Get the value of a statistic parameter by its type.
- fallback
- Fallback value if the parameter is not found.
Returns: The parameter value or .
public decimal? GetTargetPosition(Security security, Portfolio portfolio)
result = strategy.GetTargetPosition(security, portfolio)
Get target position for specified security and portfolio.
- security
- Security.
- portfolio
- Portfolio.
Returns: Target position, or null if not set.
public decimal? GetTargetPosition()
result = strategy.GetTargetPosition()
Get target position for the strategy's Security and Portfolio.
Returns: Target position, or null if not set.
public virtual IEnumerable<Portfolio> GetWorkingPortfolios()
result = strategy.GetWorkingPortfolios()
Get all portfolios required for strategy.
Returns: Portfolios.
public virtual IEnumerable<ValueTuple<Security, DataType>> GetWorkingSecurities()
result = strategy.GetWorkingSecurities()
Get all securities required for strategy.
Returns: Securities.
public bool IsFormedAndOnline()
result = strategy.IsFormedAndOnline()
IsFormed and IsOnline.
Returns: Check result.
public bool IsFormedAndOnlineAndAllowTrading(StrategyTradingModes required)
result = strategy.IsFormedAndOnlineAndAllowTrading(required)
IsFormedAndOnline and TradingMode.
- required
- Required action.
Returns: Check result.
public bool? IsOrderEditable(Order order)
result = strategy.IsOrderEditable(order)
Determines the specified order can be edited by Order).
- order
- Order.
Returns: if the order is editable, order cannot be changed, means no information.
public bool? IsOrderReplaceable(Order order)
result = strategy.IsOrderReplaceable(order)
Determines the specified order can be replaced by Order).
- order
- Order.
Returns: if the order is replaceable, order cannot be replaced, means no information.
public override void Load(SettingsStorage storage)
strategy.Load(storage)
Load settings.
- storage
- Settings storage.
public ValueTask<Security> LookupByIdAsync(SecurityId id, CancellationToken cancellationToken)
result = strategy.LookupByIdAsync(id, cancellationToken)
To get the instrument by the identifier.
- id
- Security ID.
- cancellationToken
- CancellationToken
Returns: The got instrument. If there is no instrument by given criteria, is returned.
protected virtual void OnError(Strategy strategy, Exception error)
strategy.OnError(strategy, error)
Processing of error, occurred as result of strategy operation.
- strategy
- Strategy.
- error
- Error.
protected virtual void OnOrderReceived(Order order)
strategy.OnOrderReceived(order)
Order received.
- order
- Order
protected virtual void OnOrderRegistered(Order order)
strategy.OnOrderRegistered(order)
To call the event OrderRegistered.
- order
- Order.
protected virtual void OnOrderRegisterFailed(OrderFail fail, bool calcRisk)
strategy.OnOrderRegisterFailed(fail, calcRisk)
The method, called at strategy order registration error.
- fail
- Error registering order.
- calcRisk
- Invoke risk manager.
protected virtual void OnOrderRegistering(Order order)
strategy.OnOrderRegistering(order)
To call the event OrderRegistering.
- order
- Order.
protected virtual void OnOrderReRegistering(Order oldOrder, Order newOrder)
strategy.OnOrderReRegistering(oldOrder, newOrder)
To call the event OrderReRegistering.
- oldOrder
- Cancelling order.
- newOrder
- New order to register.
protected virtual void OnOwnTradeReceived(MyTrade trade)
strategy.OnOwnTradeReceived(trade)
Own trade received.
- trade
- MyTrade
protected virtual void OnPositionReceived(Position position)
strategy.OnPositionReceived(position)
Position received.
- position
- Position
protected virtual void OnReseted()
strategy.OnReseted()
It is called from the Reset method.
protected virtual void OnStarted(DateTimeOffset time)
strategy.OnStarted(time)
The method is called when the Start method has been called and the ProcessState state has been taken the Started value.
protected virtual void OnStarted()
strategy.OnStarted()
The method is called when the Start method has been called and the ProcessState state has been taken the Started value.
protected virtual void OnStarted2(DateTime time)
strategy.OnStarted2(time)
The method is called when the Start method has been called and the ProcessState state has been taken the Started value.
protected virtual void OnStopped()
strategy.OnStopped()
The method is called when the ProcessState process state has been taken the Stopped value.
protected virtual void OnStopping()
strategy.OnStopping()
The method is called when the ProcessState process state has been taken the Stopping value.
public StrategyParam<T> Param<T>(string id, T initialValue)
result = strategy.Param(id, initialValue)
Initializes a new instance of the StrategyParam.
- id
- Parameter identifier.
- initialValue
- The initial value.
Returns: The strategy parameter.
public void Prepare()
strategy.Prepare()
Prepare data for report generation. Call this before accessing any data to ensure all values are up-to-date.
private void ProcessOrder(Order order, bool isChanging)
strategy.ProcessOrder(order, isChanging)
To add the order to the strategy.
- order
- Order.
- isChanging
- The order came from the change event.
public void RaiseParametersChanged(string name)
strategy.RaiseParametersChanged(name)
To call events ParametersChanged and PropertyChanged.
- name
- Parameter name.
protected void RaiseProcessStateChanged(Strategy strategy)
strategy.RaiseProcessStateChanged(strategy)
To call the event ProcessStateChanged.
- strategy
- Strategy.
public void RegisterOrder(Order order)
strategy.RegisterOrder(order)
Register new order.
- order
- Registration details.
public void ReRegisterOrder(Order oldOrder, Order newOrder)
strategy.ReRegisterOrder(oldOrder, newOrder)
Reregister the order.
- oldOrder
- Cancelling order.
- newOrder
- New order to register.
public void Reset()
strategy.Reset()
To re-initialize the trade algorithm. It is called after initialization of the strategy object and loading stored parameters.
public IConnector SafeGetConnector()
result = strategy.SafeGetConnector()
To get the strategy getting Connector. If it is not initialized, the exception will be discarded.
Returns: Connector.
public void Save(SettingsStorage storage, bool saveStatistics, bool saveSystemParameters)
strategy.Save(storage, saveStatistics, saveSystemParameters)
Save settings.
- storage
- SettingsStorage
- saveStatistics
- KeepStatistics
- saveSystemParameters
- Save system parameters.
public override void Save(SettingsStorage storage)
strategy.Save(storage)
Save settings.
- storage
- Settings storage.
public Order SellLimit(decimal price, decimal? volume, Security security)
result = strategy.SellLimit(price, volume, security)
To create the initialized order object for sell.
- price
- Price.
- volume
- The volume. If value is passed, then Volume value is used.
- security
- The security. If value is passed, then Security value is used.
Returns: The initialized order object.
public Order SellMarket(decimal? volume, Security security)
result = strategy.SellMarket(volume, security)
To create the initialized order object of sell order at market price.
- volume
- The volume. If value is passed, then Volume value is used.
- security
- The security. If value is passed, then Security value is used.
Returns: The initialized order object.
public void SetAlertService(IAlertNotificationService service)
strategy.SetAlertService(service)
To set a IAlertNotificationService for the strategy.
- service
- Alert notification service.
public void SetChart(IChart chart)
strategy.SetChart(chart)
To set a IChart for the strategy.
- chart
- Chart.
public void SetOptionDesk(IOptionDesk desk)
strategy.SetOptionDesk(desk)
To set the IOptionDesk.
- desk
- IOptionDesk.
public void SetOptionPositionChart(IOptionPositionChart chart)
strategy.SetOptionPositionChart(chart)
To set a IChart for the strategy.
- chart
- Chart.
public void SetPositionValue(Security security, Portfolio portfolio, decimal value, DateTime time)
strategy.SetPositionValue(security, portfolio, value, time)
Set position.
- security
- Security.
- portfolio
- Portfolio.
- value
- Position.
- time
- Timestamp to assign into LocalTime and ServerTime if position is created anew.
public void SetTargetPosition(decimal target)
strategy.SetTargetPosition(target)
Set target position for the strategy's Security and Portfolio.
- target
- Target position value.
public void SetTargetPosition(Security security, Portfolio portfolio, decimal target)
strategy.SetTargetPosition(security, portfolio, target)
Set target position for specified security and portfolio.
- security
- Security.
- portfolio
- Portfolio.
- target
- Target position value.
protected void StartProtection(Unit takeProfit, Unit stopLoss, bool isStopTrailing, TimeSpan? takeTimeout, TimeSpan? stopTimeout, bool useMarketOrders, bool isLocalStop)
strategy.StartProtection(takeProfit, stopLoss, isStopTrailing, takeTimeout, stopTimeout, useMarketOrders, isLocalStop)
Start position protection.
- takeProfit
- Take offset.
- stopLoss
- Stop offset.
- isStopTrailing
- Whether to use a trailing technique.
- takeTimeout
- Time limit. If protection has not worked by this time, the position will be closed on the market.
- stopTimeout
- Time limit. If protection has not worked by this time, the position will be closed on the market.
- useMarketOrders
- Whether to use market orders.
- isLocalStop
- Force local stop processing regardless of adapter capabilities.
protected ITimerHandler StartTimer(TimeSpan interval, Action callback)
result = strategy.StartTimer(interval, callback)
Create a timer that executes callback at specified intervals and starts it immediately.
- interval
- Timer interval.
- callback
- Callback to execute.
Returns: ITimerHandler
public void Stop(Exception error)
strategy.Stop(error)
To stop the trade algorithm by error reason.
- error
- Error.
public void Subscribe(Subscription subscription)
strategy.Subscribe(subscription)
Subscribe.
- subscription
- Subscription.
protected ISubscriptionHandler<ICandleMessage> SubscribeCandles(Subscription subscription)
result = strategy.SubscribeCandles(subscription)
Subscribe to candles.
- subscription
- Subscription
Returns: SubscriptionHandler
protected ISubscriptionHandler<ICandleMessage> SubscribeCandles(DataType dt, bool isFinishedOnly, Security security)
result = strategy.SubscribeCandles(dt, isFinishedOnly, security)
Subscribe to candles.
- dt
- DataType
- isFinishedOnly
- IsFinishedOnly
- security
- Security. If security is not passed, then Security value is used.
Returns: SubscriptionHandler
protected ISubscriptionHandler<ICandleMessage> SubscribeCandles(TimeSpan tf, bool isFinishedOnly, Security security)
result = strategy.SubscribeCandles(tf, isFinishedOnly, security)
Subscribe to candles.
- tf
- Time-frame.
- isFinishedOnly
- IsFinishedOnly
- security
- Security. If security is not passed, then Security value is used.
Returns: SubscriptionHandler
protected ISubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Subscription subscription)
result = strategy.SubscribeLevel1(subscription)
Subscribe to Level1.
- subscription
- Subscription
Returns: SubscriptionHandler
protected ISubscriptionHandler<Level1ChangeMessage> SubscribeLevel1(Security security)
result = strategy.SubscribeLevel1(security)
Subscribe to Level1.
- security
- Security. If security is not passed, then Security value is used.
Returns: SubscriptionHandler
protected ISubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Subscription subscription)
result = strategy.SubscribeOrderBook(subscription)
Subscribe to MarketDepth.
- subscription
- Subscription
Returns: SubscriptionHandler
protected ISubscriptionHandler<IOrderBookMessage> SubscribeOrderBook(Security security)
result = strategy.SubscribeOrderBook(security)
Subscribe to MarketDepth.
- security
- Security. If security is not passed, then Security value is used.
Returns: SubscriptionHandler
protected ISubscriptionHandler<ITickTradeMessage> SubscribeTicks(Subscription subscription)
result = strategy.SubscribeTicks(subscription)
Subscribe to Ticks.
- subscription
- Subscription
Returns: SubscriptionHandler
protected ISubscriptionHandler<ITickTradeMessage> SubscribeTicks(Security security)
result = strategy.SubscribeTicks(security)
Subscribe to Ticks.
- security
- Security. If security is not passed, then Security value is used.
Returns: SubscriptionHandler
protected virtual object ToReportValue(object value)
result = strategy.ToReportValue(value)
To convert parameter value to report value.
- value
- The parameter value.
Returns: The report value.
public bool TryAddMyTrade(MyTrade trade)
result = strategy.TryAddMyTrade(trade)
Try add own trade.
- trade
- MyTrade
Returns: Operation result.
public void UnSubscribe(Subscription subscription)
strategy.UnSubscribe(subscription)
Unsubscribe.
- subscription
- Subscription.
Events
public event Action<Subscription, ExchangeBoard> BoardReceived
strategy.BoardReceived += handler
ExchangeBoard received.
public event Action<Subscription, ICandleMessage> CandleReceived
strategy.CandleReceived += handler
ICandleMessage received.
public event Action CommissionChanged
strategy.CommissionChanged += handler
Commission change event.
public event Action ConnectorChanged
strategy.ConnectorChanged += handler
The event of strategy connection change.
public event Action<TimeSpan> CurrentTimeChanged
strategy.CurrentTimeChanged += handler
Server time changed CurrentTime. It passed the time difference since the last call of the event. The first time the event passes the value Zero.
public event Action<Subscription, DataType> DataTypeReceived
strategy.DataTypeReceived += handler
DataType received.
public event Action<Strategy, Exception> Error
strategy.Error += handler
The event of error occurrence in the strategy.
public event Action<Strategy> IsOnlineChanged
strategy.IsOnlineChanged += handler
The event of strategy online state change.
public event Action LatencyChanged
strategy.LatencyChanged += handler
Latency change event.
public event Action<Subscription, Level1ChangeMessage> Level1Received
strategy.Level1Received += handler
Level1ChangeMessage received.
public event Action<MyTrade> NewMyTrade
strategy.NewMyTrade += handler
Own trade received.
public event Action<Subscription, News> NewsReceived
strategy.NewsReceived += handler
News received.
public event Action<Subscription, IOrderBookSource, IOrderBookMessage> OrderBookDrawing
strategy.OrderBookDrawing += handler
IOrderBookMessage).
public event Action<Subscription, IOrderBookSource, Order> OrderBookDrawingOrder
strategy.OrderBookDrawingOrder += handler
Order).
public event Action<Subscription, IOrderBookSource, OrderFail> OrderBookDrawingOrderFail
strategy.OrderBookDrawingOrderFail += handler
OrderFail).
public event Action<Subscription, IOrderBookMessage> OrderBookReceived
strategy.OrderBookReceived += handler
IOrderBookMessage received.
public event Action<OrderFail> OrderCancelFailed
strategy.OrderCancelFailed += handler
Order cancellation error event.
public event Action<Subscription, OrderFail> OrderCancelFailReceived
strategy.OrderCancelFailReceived += handler
OrderFail cancellation event.
public event Action<Order> OrderCanceling
strategy.OrderCanceling += handler
The event of sending order for cancelling.
public event Action<Order> OrderChanged
strategy.OrderChanged += handler
Order changed (cancelled, matched).
public event Action<long, Order> OrderEdited
strategy.OrderEdited += handler
Order) success result event.
public event Action<long, OrderFail> OrderEditFailed
strategy.OrderEditFailed += handler
Order) error result event.
public event Action<Subscription, OrderFail> OrderEditFailReceived
strategy.OrderEditFailReceived += handler
OrderFail edition event.
public event Action<Subscription, IOrderLogMessage> OrderLogReceived
strategy.OrderLogReceived += handler
IOrderLogMessage received.
public event Action<Subscription, Order> OrderReceived
strategy.OrderReceived += handler
Order received.
public event Action<Order> OrderRegistered
strategy.OrderRegistered += handler
The event of order successful registration.
public event Action<OrderFail> OrderRegisterFailed
strategy.OrderRegisterFailed += handler
Order registration error event.
public event Action<Subscription, OrderFail> OrderRegisterFailReceived
strategy.OrderRegisterFailReceived += handler
OrderFail registration event.
public event Action<Order> OrderRegistering
strategy.OrderRegistering += handler
The event of sending order for registration.
public event Action<Order, Order> OrderReRegistering
strategy.OrderReRegistering += handler
The event of sending order for re-registration.
public event Action<Subscription, MyTrade> OwnTradeReceived
strategy.OwnTradeReceived += handler
MyTrade received.
public event Action ParametersChanged
strategy.ParametersChanged += handler
Parameters change event.
public event Action<Subscription> PnLReceived
strategy.PnLReceived += handler
PnL change event.
public event Action<Subscription, Portfolio, DateTime, decimal, decimal?, decimal?> PnLReceived2
strategy.PnLReceived2 += handler
PnL change event.
public event Action<Subscription, Portfolio> PortfolioReceived
strategy.PortfolioReceived += handler
Portfolio received.
public event Action PositionChanged
strategy.PositionChanged += handler
Position change event.
public event Action<Subscription, Position> PositionReceived
strategy.PositionReceived += handler
Position received.
public event Action<Strategy> ProcessStateChanged
strategy.ProcessStateChanged += handler
ProcessState change event.
public event PropertyChangedEventHandler PropertyChanged
strategy.PropertyChanged += handler
The diagram element properties value change event.
public event Action Reseted
strategy.Reseted += handler
The event of the strategy re-initialization.
public event Action<Subscription, Security> SecurityReceived
strategy.SecurityReceived += handler
Security received.
public event Action SlippageChanged
strategy.SlippageChanged += handler
Slippage change event.
public event Action<Subscription, Exception, bool> SubscriptionFailed
strategy.SubscriptionFailed += handler
Subscription is failed.
public event Action<Subscription> SubscriptionOnline
strategy.SubscriptionOnline += handler
Subscription is online.
public event Action<Subscription, object> SubscriptionReceived
strategy.SubscriptionReceived += handler
Value received.
public event Action<Subscription> SubscriptionStarted
strategy.SubscriptionStarted += handler
Subscription is started.
public event Action<Subscription, Exception> SubscriptionStopped
strategy.SubscriptionStopped += handler
Subscription is stopped.
public event Action<Subscription, ITickTradeMessage> TickTradeReceived
strategy.TickTradeReceived += handler
ITickTradeMessage received.