예제 #1
0
        public override void Load(SettingsStorage storage)
        {
            base.Load(storage);

            var compositionId = storage.GetValue <Guid>("CompositionId");

            var registry    = ConfigManager.GetService <StrategiesRegistry>();
            var composition = (CompositionDiagramElement)registry.Strategies.FirstOrDefault(c => c.TypeId == compositionId);

            Strategy = new EmulationDiagramStrategy
            {
                Id               = storage.GetValue <Guid>("StrategyId"),
                DataPath         = storage.GetValue <string>("DataPath"),
                StartDate        = storage.GetValue <DateTime>("StartDate"),
                StopDate         = storage.GetValue <DateTime>("StopDate"),
                SecurityId       = storage.GetValue <string>("SecurityId"),
                MarketDataSource = storage.GetValue <MarketDataSource>("MarketDataSource"),
                CandlesTimeFrame = storage.GetValue <TimeSpan>("CandlesTimeFrame"),
                Composition      = registry.Clone(composition)
            };

            DiagramDebuggerControl.Debugger.Load(storage.GetValue <SettingsStorage>("Debugger"));

            _layoutManager.LoadLayout(storage.GetValue <string>("Layout"));
        }
예제 #2
0
        private void OnStrategyPropertyChanged(EmulationDiagramStrategy strategy)
        {
            if (strategy != null)
            {
                strategy.PropertyChanged += OnStrategyPropertyChanged;

                var composition = strategy.Composition;

                Debugger = new DiagramDebugger(composition)
                {
                    IsEnabled = true
                };
                Debugger.Break += OnDebuggerBreak;
                Debugger.CompositionChanged += OnDebuggerCompositionChanged;

                NoStrategyLabel.Visibility = Visibility.Hidden;
                DiagramEditor.Composition  = composition;

                ShowElementProperties(null);
            }
            else
            {
                Debugger = null;

                NoStrategyLabel.Visibility = Visibility.Visible;
                DiagramEditor.Composition  = new CompositionDiagramElement {
                    Name = string.Empty
                };
            }

            DiagramEditor.Composition.IsModifiable = false;
        }
예제 #3
0
        private void OpenEmulation(CompositionItem item)
        {
            var strategy = new EmulationDiagramStrategy
            {
                Composition = _strategiesRegistry.Clone(item.Element)
            };

            var content = new EmulationControl
            {
                Strategy = strategy
            };

            _layoutManager.OpenDocumentWindow(content);
        }
예제 #4
0
        private void OnStrategyChanged(EmulationDiagramStrategy oldStrategy, EmulationDiagramStrategy newStrategy)
        {
            if (oldStrategy != null)
            {
                ConfigManager
                .GetService <LogManager>()
                .Sources
                .Remove(oldStrategy);

                oldStrategy.OrderRegistering    += OnStrategyOrderRegistering;
                oldStrategy.OrderReRegistering  += OnStrategyOrderReRegistering;
                oldStrategy.OrderRegisterFailed += OnStrategyOrderRegisterFailed;

                oldStrategy.StopOrderRegistering    += OnStrategyOrderRegistering;
                oldStrategy.StopOrderReRegistering  += OnStrategyOrderReRegistering;
                oldStrategy.StopOrderRegisterFailed += OnStrategyOrderRegisterFailed;

                oldStrategy.NewMyTrades += OnStrategyNewMyTrade;
            }

            DiagramDebuggerControl.Strategy = newStrategy;

            if (newStrategy == null)
            {
                return;
            }

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

            newStrategy.OrderRegistering    += OnStrategyOrderRegistering;
            newStrategy.OrderReRegistering  += OnStrategyOrderReRegistering;
            newStrategy.OrderRegisterFailed += OnStrategyOrderRegisterFailed;

            newStrategy.StopOrderRegistering    += OnStrategyOrderRegistering;
            newStrategy.StopOrderReRegistering  += OnStrategyOrderReRegistering;
            newStrategy.StopOrderRegisterFailed += OnStrategyOrderRegisterFailed;

            newStrategy.NewMyTrades += OnStrategyNewMyTrade;

            newStrategy.PnLChanged += () =>
            {
                var pnl = new EquityData
                {
                    Time  = newStrategy.CurrentTime,
                    Value = newStrategy.PnL - newStrategy.Commission ?? 0
                };

                var unrealizedPnL = new EquityData
                {
                    Time  = newStrategy.CurrentTime,
                    Value = newStrategy.PnLManager.UnrealizedPnL
                };

                var commission = new EquityData
                {
                    Time  = newStrategy.CurrentTime,
                    Value = newStrategy.Commission ?? 0
                };

                _pnlCurve.Add(pnl);
                _unrealizedPnLCurve.Add(unrealizedPnL);
                _commissionCurve.Add(commission);
            };

            newStrategy.PositionChanged += () => _posItems.Add(new EquityData
            {
                Time  = newStrategy.CurrentTime,
                Value = newStrategy.Position
            });
        }