예제 #1
0
        public StudioRegistryConnector(IConnector studioConnector)
        {
            EntityFactory = new StudioConnectorEntityFactory();

            MarketDataAdapter  = _adapter = new PassThroughMessageAdapter(new PassThroughSessionHolder(TransactionIdGenerator));
            TransactionAdapter = new PassThroughMessageAdapter(new PassThroughSessionHolder(TransactionIdGenerator));

            ApplyMessageProcessor(MessageDirections.In, true, true);
            ApplyMessageProcessor(MessageDirections.Out, true, true);

            _entityRegistry = ConfigManager.GetService <IStudioEntityRegistry>();
            _entityRegistry.Securities.Added += s => _adapter.SendOutMessage(s.ToMessage(GetSecurityId(s)));
            _entityRegistry.Portfolios.Added += p => _adapter.SendOutMessage(p.ToMessage());

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

            //cmdSvc.Register<LookupSecuritiesCommand>(this, cmd => LookupSecurities(cmd.Criteria));
            cmdSvc.Register <RequestPortfoliosCommand>(this, false, cmd => Portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this)));

            NewPortfolios += portfolios => portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this));
            //NewPositions += positions => positions.ForEach(pos => new PositionCommand(pos, true).Process(this));

            // для корректной работы правил коннектор всегда должен быть реальным
            //NewSecurities += securities => securities.ForEach(s => s.Connector = studioConnector);
            NewPortfolios += portfolios => portfolios.ForEach(p => p.Connector = studioConnector);
        }
예제 #2
0
        public MainWindow()
        {
            InitializeComponent();

            Title = Title.Put("TWIME");

            _ordersWindow.MakeHideable();
            _myTradesWindow.MakeHideable();
            _tradesWindow.MakeHideable();
            _securitiesWindow.MakeHideable();
            _portfoliosWindow.MakeHideable();

            var mdAdapter = new PassThroughMessageAdapter(Trader.TransactionIdGenerator);

            mdAdapter.AddMarketDataSupport();
            Trader.Adapter.InnerAdapters.Add(mdAdapter);

            Instance = this;

            Trader.LogLevel = LogLevels.Debug;

            _logManager.Sources.Add(Trader);
            _logManager.Listeners.Add(new FileLogListener {
                LogDirectory = "StockSharp_Twime"
            });

            TransactionAddress.EndPoint = Trader.TransactionAddress;
            RecoveryAddress.EndPoint    = Trader.RecoveryAddress;
            Login.Text = Trader.Login;
        }
예제 #3
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);
            }