예제 #1
0
        public StopStrategyCommand(StrategyContainer strategy)
		{
			if (strategy == null)
				throw new ArgumentNullException("strategy");

			Strategy = strategy;
		}
예제 #2
0
        public static void SetStrategy(this StrategyContent control, StrategyContainer strategy)
        {
            strategy.BindStrategyToScope(control);

            control.Strategy = strategy;

            if (strategy.SessionType == SessionType.Emulation)
            {
                control.EmulationService = new EmulationService(strategy);
            }

            control.ChildsLoaded += () =>
            {
                //после загрузки всех дочерних контролов можно запустить инициализацию по истории
                if (strategy.Security == null || strategy.Portfolio == null)
                {
                    return;
                }

                new ResetStrategyCommand(strategy).Process(control);

                if (strategy.SessionType == SessionType.Battle && strategy.GetIsAutoStart())
                {
                    new StartStrategyCommand(strategy).Process(strategy);
                }
            };
        }
예제 #3
0
        private void Start(StrategyContainer strategy, DateTime?startDate, DateTime?stopDate, TimeSpan?candlesTimeFrame, bool onlyInitialize)
        {
            if (Connector == null)
            {
                throw new InvalidOperationException("Connector=null");
            }

            strategy.CheckCanStart();

            var from = startDate ?? DateTime.Today.AddDays(-strategy.HistoryDaysCount);
            var to   = stopDate ?? DateTime.Now;

            var strategyConnector = new StrategyConnector(strategy, from, to, candlesTimeFrame ?? TimeSpan.FromMinutes(5), onlyInitialize);

            ConfigManager.GetService <LogManager>().Sources.Add(strategyConnector);

            strategy.Connector = strategyConnector;
            strategy.SetCandleManager(CreateCandleManager(strategyConnector, TimeSpan.FromDays((strategy.HistoryDaysCount + 1) * 2)));
            strategy.SetIsEmulation(false);

            strategyConnector.Connected += strategyConnector.StartExport;

            strategy.Start();
            strategyConnector.Connect();
        }
예제 #4
0
        public EmulationService(StrategyContainer strategy)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException(nameof(strategy));
            }

            Strategy   = strategy;
            Strategies = new[] { strategy }.ToEx(1);

            var storageRegistry = new StudioStorageRegistry {
                MarketDataSettings = Strategy.MarketDataSettings
            };

            _basketEmulation = new BatchEmulation(new StudioSecurityProvider(), new Portfolio[0], storageRegistry);

            _basketEmulation.StateChanged    += BasketEmulationOnStateChanged;
            _basketEmulation.ProgressChanged += (curr, total) =>
            {
                Progress = total;

                _basketEmulation
                .BatchStrategies
                .OfType <StrategyContainer>()
                .ForEach(s => ProgressChanged.SafeInvoke((StrategyContainer)s.Strategy, curr));
            };

            ConfigManager.GetService <LogManager>().Sources.Add(EmulationConnector);

            EmulationConnector.HistoryMessageAdapter.StorageRegistry = storageRegistry;

            CanStart = true;
        }
예제 #5
0
        private void defineSupportedMessage()
        {
            this.strategyContainer = new StrategyContainer();
            this.strategyContainer.AddStrategy(typeof(SolicitateBallotRequest),
                                               new SendSolicitateBallotRequestToAcceptors(this.MessageBroker));

            ReceiveUpdatedBallotNumberFromAcceptors receiveUpdatedBallot = new ReceiveUpdatedBallotNumberFromAcceptors();

            receiveUpdatedBallot.BallotRejected += onBallotRejected;
            receiveUpdatedBallot.BallotApproved += onBallotApproved;
            this.strategyContainer.AddStrategy(typeof(SolicitateBallotResponse), receiveUpdatedBallot);

            this.strategyContainer.AddStrategy(typeof(VoteRequest),
                                               new SendVoteRequestToAcceptors(this.MessageBroker));

            ReceiveVoteResponseFromAcceptors receiveVote = new ReceiveVoteResponseFromAcceptors();

            receiveVote.OnApprovalPreempted += onBallotRejected;
            receiveVote.OnApprovalElected   += onProposalElected;
            this.strategyContainer.AddStrategy(typeof(VoteResponse), receiveVote);

            ReceiveProposalRequestFromReplica requestFromReplica = new ReceiveProposalRequestFromReplica();

            requestFromReplica.OnProposalReceived += onProposalFromReplicaReceived;
            this.strategyContainer.AddStrategy(typeof(ProposalRequest), requestFromReplica);
        }
        public DebugDiagramStrategyCommand(StrategyContainer strategy)
		{
			if (strategy == null) 
				throw new ArgumentNullException(nameof(strategy));

			Strategy = strategy;
		}
예제 #7
0
        public static string CheckCanStart(this StrategyContainer strategy, bool throwError = true)
        {
            string error = null;

            if (strategy.Security == null)
            {
                error = LocalizedStrings.Str3613Params.Put(strategy.Name);
            }

            if (strategy.Portfolio == null)
            {
                error = LocalizedStrings.Str3614Params.Put(strategy.Name);
            }

            var diagramStrategy = strategy.Strategy as DiagramStrategy;

            if (diagramStrategy != null)
            {
                if (diagramStrategy.Composition == null)
                {
                    error = LocalizedStrings.Str3615Params.Put(strategy.Name);
                }
                else if (diagramStrategy.Composition.HasErrors)
                {
                    error = LocalizedStrings.Str3616Params.Put(strategy.Name);
                }
            }

            if (throwError && error != null)
            {
                throw new InvalidOperationException(error);
            }

            return(error);
        }
예제 #8
0
        public CandleChartPanel()
        {
            InitializeComponent();

            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            cmdSvc.Register <ChartDrawCommand>(this, false, cmd => _bufferedChart.Draw(cmd.Values));
            cmdSvc.Register <ChartAddAreaCommand>(this, false, cmd => _bufferedChart.AddArea(cmd.Area));
            cmdSvc.Register <ChartRemoveAreaCommand>(this, false, cmd => _bufferedChart.RemoveArea(cmd.Area));
            cmdSvc.Register <ChartAddElementCommand>(this, false, cmd => _bufferedChart.AddElement(cmd.Area, cmd.Element));
            cmdSvc.Register <ChartRemoveElementCommand>(this, false, cmd => _bufferedChart.RemoveElement(cmd.Area, cmd.Element));
            cmdSvc.Register <ChartClearAreasCommand>(this, false, cmd => _bufferedChart.ClearAreas());
            cmdSvc.Register <ChartResetElementsCommand>(this, false, cmd => _bufferedChart.Reset(cmd.Elements));
            cmdSvc.Register <ChartAutoRangeCommand>(this, false, cmd => _bufferedChart.IsAutoRange = cmd.AutoRange);
            cmdSvc.Register <ResetedCommand>(this, true, cmd => OnReseted());
            cmdSvc.Register <BindStrategyCommand>(this, true, cmd =>
            {
                if (!cmd.CheckControl(this))
                {
                    return;
                }

                if (_strategy == cmd.Source)
                {
                    return;
                }

                _strategy = cmd.Source;

                SetChart(true);

                ChartPanel.IsInteracted = _strategy != null && _strategy.GetIsInteracted();

                if (_settingsStorage != null)
                {
                    ChartPanel.Load(_settingsStorage);
                }

                TryCreateDefaultSeries();
            });

            ChartPanel.SettingsChanged           += () => new ControlChangedCommand(this).Process(this);
            ChartPanel.RegisterOrder             += order => new RegisterOrderCommand(order).Process(this);
            ChartPanel.SubscribeCandleElement    += OnChartPanelSubscribeCandleElement;
            ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement;
            ChartPanel.SubscribeOrderElement     += OnChartPanelSubscribeOrderElement;
            ChartPanel.SubscribeTradeElement     += OnChartPanelSubscribeTradeElement;
            ChartPanel.UnSubscribeElement        += OnChartPanelUnSubscribeElement;

            var indicatorTypes = ConfigManager
                                 .GetService <IAlgoService>()
                                 .IndicatorTypes;

            ChartPanel.MinimumRange = 200;
            ChartPanel.IndicatorTypes.AddRange(indicatorTypes);

            _bufferedChart = new BufferedChart(ChartPanel);

            WhenLoaded(() => new RequestBindSource(this).SyncProcess(this));
        }
예제 #9
0
            public StrategyConnector(StrategyContainer strategy, DateTimeOffset startDate, DateTimeOffset stopDate, TimeSpan useCandlesTimeFrame, bool onlyInitialize)
            {
                if (strategy == null)
                {
                    throw new ArgumentNullException("strategy");
                }

                UpdateSecurityLastQuotes = false;
                UpdateSecurityByLevel1   = false;

                var entityRegistry = ConfigManager.GetService <IStudioEntityRegistry>();

                _strategy            = strategy;
                _useCandlesTimeFrame = useCandlesTimeFrame;
                _onlyInitialize      = onlyInitialize;
                _sessionStrategy     = entityRegistry.ReadSessionStrategyById(strategy.Strategy.Id);

                if (_sessionStrategy == null)
                {
                    throw new InvalidOperationException("sessionStrategy = null");
                }

                Id   = strategy.Id;
                Name = strategy.Name + " Connector";

                _realConnector             = (StudioConnector)ConfigManager.GetService <IStudioConnector>();
                _realConnector.NewMessage += RealConnectorNewMessage;

                EntityFactory = new StudioConnectorEntityFactory();

                _securityProvider = new StudioSecurityProvider();

                var storageRegistry = new StudioStorageRegistry {
                    MarketDataSettings = strategy.MarketDataSettings
                };

                Adapter.InnerAdapters.Add(_historyMessageAdapter = new HistoryMessageAdapter(TransactionIdGenerator, _securityProvider)
                {
                    StartDate       = startDate,
                    StopDate        = stopDate,
                    StorageRegistry = storageRegistry
                });
                //_historyMessageAdapter.UpdateCurrentTime(startDate);
                var transactionAdapter = new PassThroughMessageAdapter(TransactionIdGenerator);

                transactionAdapter.AddTransactionalSupport();
                Adapter.InnerAdapters.Add(transactionAdapter);

                _historyMessageAdapter.MarketTimeChangedInterval = useCandlesTimeFrame;

                // при инициализации по свечкам, время меняется быстрее и таймаут должен быть больше 30с.
                ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue;

                _historyMessageAdapter.BasketStorage.InnerStorages.AddRange(GetExecutionStorages());

                this.LookupById(strategy.Security.Id);

                new ChartAutoRangeCommand(true).Process(_strategy);
            }
예제 #10
0
 public ResetStrategyCommand(StrategyContainer strategy)
 {
     if (strategy == null)
     {
         throw new ArgumentNullException(nameof(strategy));
     }
     Strategy = strategy;
 }
예제 #11
0
        public StartStrategyCommand(StrategyContainer strategy, bool step = false)
		{
			if (strategy == null)
				throw new ArgumentNullException("strategy");

			Strategy = strategy;
			Step = step;
		}
예제 #12
0
		public OpenStrategyCommand(StrategyContainer strategy, string contentTemplate = null)
		{
			if (strategy == null)
				throw new ArgumentNullException(nameof(strategy));

			Strategy = strategy;
			ContentTemplate = contentTemplate;
		}
예제 #13
0
        public StopStrategyCommand(StrategyContainer strategy)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            Strategy = strategy;
        }
예제 #14
0
        private void defineSupportedMessage()
        {
            this.strategyContainer = new StrategyContainer();
            this.strategyContainer.AddStrategy(typeof(SolicitateBallotRequest),
                                               new SendUpdatedBallotNumberToLeader(this.MessageBroker));

            this.strategyContainer.AddStrategy(typeof(VoteRequest),
                                               new SendVoteResponseToLeader(this.MessageBroker));
        }
예제 #15
0
        public BasicContactFinder()
        {
            IntersectStrats = new StrategyContainer <IEdgeIntersector, Transformation, IEnumerable <Intersection> >();
            OverlapStrats   = new StrategyContainer <IOverlapable, Transformation, bool>();

            // add some default strategies
            IntersectStrats.AddStrategy(new SphereSphereStrategy());
            IntersectStrats.AddStrategy(new SphereCompositeStrategy());
            OverlapStrats.AddStrategy(new SphereSphereOverlap());
        }
예제 #16
0
        public StartStrategyCommand(StrategyContainer strategy, bool step = false)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            Strategy = strategy;
            Step     = step;
        }
예제 #17
0
        public OpenStrategyCommand(StrategyContainer strategy, string contentTemplate = null)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            Strategy        = strategy;
            ContentTemplate = contentTemplate;
        }
예제 #18
0
        private void defineSupportedMessage()
        {
            this.strategyContainer = new StrategyContainer();
            this.strategyContainer.AddStrategy(typeof(ClientRequest),
                                               new SendProposalRequestToLeaders(this.MessageBroker));
            ReceiveProposalDecisionFromLeader receiveProposalDecision = new ReceiveProposalDecisionFromLeader();

            receiveProposalDecision.OnDecisionApproved += onDecisionApproved;
            receiveProposalDecision.OnDecisionRejected += onDecisionRejected;
            this.strategyContainer.AddStrategy(typeof(ProposalDecision), receiveProposalDecision);
        }
예제 #19
0
        public BasicContactFinder()
        {
            IntersectStrats = new StrategyContainer<IEdgeIntersector, Transformation, IEnumerable<Intersection>>();
            OverlapStrats = new StrategyContainer<IOverlapable, Transformation, bool>();

            // add some default strategies
            IntersectStrats.AddStrategy(new SphereSphereStrategy());
            IntersectStrats.AddStrategy(new SphereCompositeStrategy());            
            OverlapStrats.AddStrategy(new SphereSphereOverlap());

        }
예제 #20
0
		public StartStrategyCommand(StrategyContainer strategy, DateTime startDate, DateTime stopDate, TimeSpan? candlesTimeFrame, bool onlyInitialize)
		{
			if (strategy == null)
				throw new ArgumentNullException("strategy");

			Strategy = strategy;
			StartDate = startDate;
			StopDate = stopDate;
			CandlesTimeFrame = candlesTimeFrame;
			OnlyInitialize = onlyInitialize;
		}
 private IStudioControl OpenOprimizationControl(StrategyContainer strategy)
 {
     return(OpenControl(strategy.Strategy.Id.To <string>(), typeof(OptimizatorContent), strategy, () =>
     {
         var c = new OptimizatorContent {
             Strategy = strategy
         };
         c.SetStrategy(strategy);
         return c;
     }));
 }
예제 #22
0
		public AddStrategyCommand(StrategyInfo info, StrategyContainer strategy, SessionType sessionType)
		{
			if (info == null)
				throw new ArgumentNullException(nameof(info));

			if (strategy == null)
				throw new ArgumentNullException(nameof(strategy));

			Info = info;
			Strategy = strategy;
			SessionType = sessionType;
		}
예제 #23
0
        private static void BindStrategyToScope(this StrategyContainer strategy, IStudioCommandScope control)
        {
            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            strategy.StrategyRemoved  += cmdSvc.UnBind;
            strategy.StrategyAssigned += newStrategy => cmdSvc.Bind(newStrategy, control);

            if (strategy.Strategy != null)
            {
                cmdSvc.Bind(strategy.Strategy, control);
            }
        }
        private IStudioControl OpenStrategyControl(StrategyContainer strategy, string contentTemplate)
        {
            return(OpenControl(strategy.Strategy.Id.To <string>(), typeof(StrategyContent), strategy, () =>
            {
                var ctrl = new StrategyContent();

                ctrl.SetStrategy(strategy);
                ctrl.LoadTemplate(contentTemplate ?? GetDefaultContentTemplate(strategy.StrategyInfo.Type, strategy.SessionType), false);

                return ctrl;
            }));
        }
예제 #25
0
        public StartStrategyCommand(StrategyContainer strategy, DateTime startDate, DateTime stopDate, TimeSpan?candlesTimeFrame, bool onlyInitialize)
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            Strategy         = strategy;
            StartDate        = startDate;
            StopDate         = stopDate;
            CandlesTimeFrame = candlesTimeFrame;
            OnlyInitialize   = onlyInitialize;
        }
예제 #26
0
            public StrategyCommandAdapter(StrategyContainer strategy)
            {
                if (strategy == null)
                {
                    throw new ArgumentNullException(nameof(strategy));
                }

                var strategyContainer = strategy;

                Subscribe(strategyContainer.Strategy);

                strategyContainer.StrategyAssigned += Subscribe;
                strategyContainer.StrategyRemoved  += UnSubscribe;
            }
        private IStudioControl OpenControl(StrategyContainer strategy, string contentTemplate = null)
        {
            switch (strategy.SessionType)
            {
            case SessionType.Battle:
            case SessionType.Emulation:
                return(OpenStrategyControl(strategy, contentTemplate));

            case SessionType.Optimization:
                return(OpenOprimizationControl(strategy));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #28
0
        private void OpenStrategy(StrategyContainer selectedStrategy)
        {
            var strategy = (StrategyContainer)selectedStrategy.Clone();

            strategy.Strategy.Id = selectedStrategy.Strategy.Id;
            strategy.Portfolio   = Strategy.Portfolio;
            strategy.SessionType = SessionType.Battle;

            strategy.Reseted += () =>
            {
                var settings = EmulationService.EmulationSettings;
                new StartStrategyCommand(strategy, settings.StartTime, settings.StopTime, null, true).Process(this);
            };

            new OpenStrategyCommand(strategy, Properties.Resources.EmulationStrategyContent).Process(strategy.StrategyInfo);
        }
예제 #29
0
        public AddStrategyCommand(StrategyInfo info, StrategyContainer strategy, SessionType sessionType)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            Info        = info;
            Strategy    = strategy;
            SessionType = sessionType;
        }
예제 #30
0
        public static void UpdateName(this StrategyContainer strategy)
        {
            var info  = strategy.StrategyInfo;
            var index = info.Strategies.Count(s => s.SessionType == strategy.SessionType) + 1;

            string name;

            switch (strategy.SessionType)
            {
            case SessionType.Battle:
                switch (info.Type)
                {
                case StrategyInfoTypes.SourceCode:
                case StrategyInfoTypes.Diagram:
                case StrategyInfoTypes.Assembly:
                    name = LocalizedStrings.Str3599;
                    break;

                case StrategyInfoTypes.Analytics:
                    name = LocalizedStrings.Str3604;
                    break;

                case StrategyInfoTypes.Terminal:
                    name = LocalizedStrings.Str3605;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case SessionType.Emulation:
                name = LocalizedStrings.Str3606;
                break;

            case SessionType.Optimization:
                name = LocalizedStrings.Str3177;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            strategy.Name = name + " " + index;
        }
예제 #31
0
        private void OnStrategyChanged(StrategyContainer oldStrategy, StrategyContainer newStrategy)
        {
            if (oldStrategy != null)
            {
                _commandAdapter.UnSubscribe();
                _logManager.Sources.Remove(oldStrategy);
            }

            if (newStrategy == null)
            {
                return;
            }

            _commandAdapter = new StrategyCommandAdapter(newStrategy);
            _logManager.Sources.Add(newStrategy);

            RaiseBindStrategy();
            //RaiseSelectStrategy();
        }
예제 #32
0
                public StrategyEvents(SessionStrategy sessionStrategy, Action startTimer)
                {
                    if (sessionStrategy == null)
                    {
                        throw new ArgumentNullException(nameof(sessionStrategy));
                    }

                    if (startTimer == null)
                    {
                        throw new ArgumentNullException(nameof(startTimer));
                    }

                    _strategy        = sessionStrategy.Strategy;
                    _sessionStrategy = sessionStrategy;
                    _startTimer      = startTimer;

                    _executionRegistry = _sessionStrategy.GetExecutionStorage();

                    SubscribeEvents();
                }
예제 #33
0
        private IEnumerable <Strategy> GetStrategies()
        {
            EmulationConnector.AddInfoLog(LocalizedStrings.Str3592);

            var enumerator = Strategies.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var strategy = (StrategyContainer)enumerator.Current;

                strategy.CheckCanStart();

                var container = new StrategyContainer
                {
                    Id                 = strategy.Id,
                    StrategyInfo       = _infoClone,
                    MarketDataSettings = strategy.MarketDataSettings,
                    Connector          = EmulationConnector,
                    //SessionType = SessionType.Optimization,
                };

                container.Environment.AddRange(strategy.Environment);

                container.SetCandleManager(CreateCandleManager());
                container.SetIsEmulation(true);
                container.SetIsInitialization(false);

                container.NameGenerator.Pattern = strategy.NameGenerator.Pattern;
                container.Portfolio             = strategy.Portfolio;
                container.Security = strategy.Security;
                container.Strategy = strategy;

                container.UnrealizedPnLInterval = EmulationSettings.UnrealizedPnLInterval ?? ((EmulationSettings.StopTime - EmulationSettings.StartTime).Ticks / 1000).To <TimeSpan>();

                _infoClone.Strategies.Add(container);

                yield return(container);
            }

            EmulationConnector.AddInfoLog(LocalizedStrings.Str3593);
        }
예제 #34
0
        private void Stop(StrategyContainer strategy)
        {
            strategy
            .WhenStopped()
            .Do(() =>
            {
                var candleManager = strategy.GetCandleManager();

                if (candleManager != null)
                {
                    candleManager.Dispose();
                }

                strategy.SafeGetConnector().Dispose();
                strategy.Connector = ConfigManager.GetService <IConnector>();
            })
            .Once()
            .Apply();

            strategy.Stop();
        }
예제 #35
0
        public static StrategyContainer CreateStrategy(this StrategyInfo info, SessionType sessionType)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            var registry = ConfigManager.GetService <IStudioEntityRegistry>();
            var security = "RI".GetFortsJumps(DateTime.Today, DateTime.Today.AddMonths(3), code => registry.Securities.LookupById(code + "@" + ExchangeBoard.Forts.Code)).Last();

            var container = new StrategyContainer
            {
                StrategyInfo       = info,
                Portfolio          = GetDefaultPortfolio(sessionType),
                Security           = security,
                MarketDataSettings = ConfigManager.GetService <MarketDataSettingsCache>().Settings.First(s => s.Id != Guid.Empty),
                SessionType        = sessionType
            };

            container.InitStrategy();

            return(container);
        }
예제 #36
0
        public UniversalGridPanel()
        {
            InitializeComponent();

            ConfigManager
            .GetService <IStudioCommandService>()
            .Register <BindStrategyCommand>(this, true, cmd =>
            {
                if (!cmd.CheckControl(this))
                {
                    return;
                }

                if (_strategy == cmd.Source)
                {
                    return;
                }

                _strategy = cmd.Source;
                SetGrid(Grid);
            });

            WhenLoaded(() => new RequestBindSource(this).SyncProcess(this));
        }
예제 #37
0
		public RemoveStrategyCommand(StrategyContainer strategy)
		{
			Strategy = strategy;
		}
예제 #38
0
		public CloneStrategyCommand(StrategyContainer strategy)
		{
			Strategy = strategy;
		}
        public ScalpingMarketDepthControl()
        {
            InitializeComponent();

            Settings.SecurityChanged += (arg1, arg2) =>
            {
                if (!_isLoaded)
                {
                    _needRequestData = true;
                }

                new RefuseMarketDataCommand(arg1, MarketDataTypes.MarketDepth).Process(this);
                new ClearMarketDepthCommand(arg2).Process(this);
                new RequestMarketDataCommand(arg2, MarketDataTypes.MarketDepth).Process(this);

                UpdateTitle();
            };

            //MdControl.Changed += () => new ControlChangedCommand(this).Process();
            MdControl.CanDrag  += OnQuotesCanDrag;
            MdControl.Dropping += OnQuotesDropping;

            //Quotes.ColumnsMoved += OnColumnsMoved;
            MdControl.CellMouseLeftButtonUp  += OnQuotesCellMouseLeftButtonUp;
            MdControl.CellMouseRightButtonUp += OnQuotesCellMouseRightButtonUp;

            //TODO добавить редактирование дейтсвией в пропгриде
            _actions = new MarketDepthControlActionList(MdControl)
            {
                new MarketDepthControlAction(MouseAction.LeftClick, ModifierKeys.None, (c, q) =>
                {
                    switch (c)
                    {
                    case MarketDepthColumns.Buy:
                    case MarketDepthColumns.Sell:
                        new RegisterOrderCommand(CreateOrder(c, q)).Process(this);
                        break;

                    case MarketDepthColumns.OwnBuy:
                    case MarketDepthColumns.OwnSell:
                        new CancelOrderCommand(CreateOrder(c, q)).Process(this);
                        break;
                    }
                }),
                new MarketDepthControlAction(Key.Escape, ModifierKeys.None, (c, q) => new CancelAllOrdersCommand().Process(this)),
            };

            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            //cmdSvc.Register<SubscribeMarketDepthKeyActionCommand>(this, cmd => _actions.Add(new MarketDepthControlAction(cmd.Key, cmd.ModifierKey)));
            //cmdSvc.Register<SubscribeMarketDepthMouseActionCommand>(this, cmd => _actions.Add(new MarketDepthControlAction(cmd.MouseAction, cmd.ModifierKey)));
            //cmdSvc.Register<UnSubscribeMarketDepthKeyActionCommand>(this, cmd => _actions.Remove(new MarketDepthControlAction(cmd.Key, cmd.ModifierKey)));
            //cmdSvc.Register<UnSubscribeMarketDepthMouseActionCommand>(this, cmd => _actions.Remove(new MarketDepthControlAction(cmd.MouseAction, cmd.ModifierKey)));

            cmdSvc.Register <UpdateMarketDepthCommand>(this, false, cmd =>
            {
                if (Settings.Security == null || cmd.Depth.Security == Settings.Security)
                {
                    MdControl.UpdateDepth(cmd.Depth);
                }
            });
            cmdSvc.Register <ClearMarketDepthCommand>(this, false, cmd =>
            {
                if (Settings.Security == null || cmd.Security == Settings.Security)
                {
                    MdControl.Clear();
                }
            });
            cmdSvc.Register <OrderCommand>(this, false, cmd =>
            {
                if (Settings.Security != null && cmd.Order.Security != Settings.Security)
                {
                    return;
                }

                switch (cmd.Action)
                {
                case OrderActions.Registered:
                    MdControl.ProcessNewOrder(cmd.Order);
                    break;

                case OrderActions.Changed:
                    MdControl.ProcessChangedOrder(cmd.Order);
                    break;
                }
            });
            cmdSvc.Register <ResetedCommand>(this, false, cmd => new RequestMarketDataCommand(Settings.Security, MarketDataTypes.MarketDepth).Process(this));
            cmdSvc.Register <BindStrategyCommand>(this, false, cmd =>
            {
                _strategy = cmd.Source;
                UpdateTitle();
            });

            WhenLoaded(() =>
            {
                _isLoaded = true;

                new RequestBindSource(this).SyncProcess(this);

                if (_needRequestData)
                {
                    new RequestMarketDataCommand(Settings.Security, MarketDataTypes.MarketDepth).Process(this);
                }
            });
        }