Panel CreateSessionPanel(PlatformExpertSession session)
        {
            Panel panel = new Panel();

            // Session not found, create new button for it.
            PlatformExpertSessionControl sessionChartControl = new PlatformExpertSessionControl();
            sessionChartControl.Dock = DockStyle.Fill;
            sessionChartControl.CreateControl();
            sessionChartControl.Session = session;

            panel.Controls.Add(sessionChartControl);

            if (session.OrderExecutionProvider != null)
            {
                Splitter splitter = new SplitterEx();
                splitter.Dock = DockStyle.Bottom;
                panel.Controls.Add(splitter);
                splitter.Height = 6;

                OrdersControl ordersControl = new OrdersControl();
                ordersControl.Dock = DockStyle.Bottom;
                ordersControl.CreateControl();
                ordersControl.SingleSession = session;
                ordersControl.VisibleChanged += delegate(object sender, EventArgs e)
                {
                    splitter.Visible = ordersControl.Visible;
                };
                //ordersControl.Manager = this._expert.Manager;
                panel.Controls.Add(ordersControl);

                sessionChartControl.CorrespondingOrdersControl = ordersControl;

                Splitter splitter2 = new Splitter();
                splitter2.Dock = DockStyle.Bottom;
                panel.Controls.Add(splitter2);

                AccountControl accountControl = new AccountControl();
                accountControl.Dock = DockStyle.Bottom;
                accountControl.CreateControl();
                accountControl.Account = session.OrderExecutionProvider.DefaultAccount;
                panel.Controls.Add(accountControl);
            }

            panel.Tag = sessionChartControl;

            panel.Visible = false;
            panel.Dock = DockStyle.Fill;

            return panel;
        }
        /// <summary>
        /// Create a and setup a dataDelivery provider for this sourceSourceId, and to the given sessionInformation.
        /// </summary>
        /// <param name="sourceSourceId"></param>
        /// <returns></returns>
        public SessionDataProvider CreateSessionDataProvider(ComponentId sourceId, PlatformExpertSession session /*, bool isBackTest*/)
        {
            // Create dataDelivery delivery (mandatory).
            ISourceDataDelivery dataDelivery = ObtainDataDelivery(sourceId);

            if (dataDelivery == null)
            {
                SystemMonitor.OperationError("Failed to create data delivery.");
                return(null);
            }

            SessionDataProvider dataProvider = new SessionDataProvider();

            // Setup the provider with the delivery.
            if (dataProvider.SetInitialParameters(this, sourceId, session) == false)
            {
                SystemMonitor.OperationError("Failed to create session data provider.");
                return(null);
            }

            return(dataProvider);
        }
Beispiel #3
0
        public PlatformExpertSession CreateExpertSession(DataSessionInfo?selectedSession,
                                                         ComponentId dataSourceId, ComponentId?orderExecuteId, bool isBackTest, out string operationResultMessage)
        {
            // Create sessionInformation (mandatory)
            PlatformExpertSession session = new PlatformExpertSession(selectedSession.Value);

            ComponentId actualDataSourceId = dataSourceId;

            if (isBackTest)
            {// We shall create a special backtesting data delivery for this session, and register it
                // and use its componentId.
                BackTestDataDelivery delivery = new BackTestDataDelivery();
                if (delivery.SetInitialParameters(this, dataSourceId, session) == false ||
                    delivery.Initialize() == false)
                {
                    operationResultMessage = "Failed to create and setup back test data delivery.";
                    return(null);
                }

                // Register the new delivery with its own ID.
                this.AddElement(delivery.SourceId, delivery);

                actualDataSourceId = delivery.SourceId;
            }

            // Create dataDelivery provider (mandatory).
            SessionDataProvider dataProvider = CreateSessionDataProvider(actualDataSourceId, session);

            if (dataProvider == null)
            {// Failed to create data provider.
                // When using back test data delivery, data provider creation not expected to fail so no need to handle this case.
                operationResultMessage = "Failed to create required session data provider for this source and session.";
                return(null);
            }

            dataProvider.Initialize(selectedSession.Value);

            // Create order executor and order history (optional).
            ISourceOrderExecution executionProvider = null;

            if (orderExecuteId.HasValue)
            {
                executionProvider = ObtainOrderExecutionProvider(orderExecuteId.Value, actualDataSourceId);
            }

            if (session.SetInitialParameters(dataProvider, executionProvider) == false)
            {
                operationResultMessage = "Failed to set sessin initial parameters.";
                return(null);
            }

            if (session.Initialize(selectedSession.Value) == false)
            {
                operationResultMessage = "Failed to initialize session.";
                session.Dispose();
                return(null);
            }

            operationResultMessage = string.Empty;
            return(session);
        }
        /// <summary>
        /// Create a and setup a dataDelivery provider for this sourceSourceId, and to the given sessionInformation.
        /// </summary>
        /// <param name="sourceSourceId"></param>
        /// <returns></returns>
        public SessionDataProvider CreateSessionDataProvider(ComponentId sourceId, PlatformExpertSession session/*, bool isBackTest*/)
        {
            // Create dataDelivery delivery (mandatory).
            ISourceDataDelivery dataDelivery = ObtainDataDelivery(sourceId);

            if (dataDelivery == null)
            {
                SystemMonitor.OperationError("Failed to create data delivery.");
                return null;
            }

            SessionDataProvider dataProvider = new SessionDataProvider();

            // Setup the provider with the delivery.
            if (dataProvider.SetInitialParameters(this, sourceId, session) == false)
            {
                SystemMonitor.OperationError("Failed to create session data provider.");
                return null;
            }

            return dataProvider;
        }
        public PlatformExpertSession CreateExpertSession(DataSessionInfo? selectedSession,
            ComponentId dataSourceId, ComponentId? orderExecuteId, bool isBackTest, out string operationResultMessage)
        {
            // Create sessionInformation (mandatory)
            PlatformExpertSession session = new PlatformExpertSession(selectedSession.Value);

            ComponentId actualDataSourceId = dataSourceId;

            if (isBackTest)
            {// We shall create a special backtesting data delivery for this session, and register it
                // and use its componentId.
                BackTestDataDelivery delivery = new BackTestDataDelivery();
                if (delivery.SetInitialParameters(this, dataSourceId, session) == false
                    || delivery.Initialize() == false)
                {
                    operationResultMessage = "Failed to create and setup back test data delivery.";
                    return null;
                }

                // Register the new delivery with its own ID.
                this.AddElement(delivery.SourceId, delivery);

                actualDataSourceId = delivery.SourceId;
            }

            // Create dataDelivery provider (mandatory).
            SessionDataProvider dataProvider = CreateSessionDataProvider(actualDataSourceId, session);
            if (dataProvider == null)
            {// Failed to create data provider.
                // When using back test data delivery, data provider creation not expected to fail so no need to handle this case.
                operationResultMessage = "Failed to create required session data provider for this source and session.";
                return null;
            }

            dataProvider.Initialize(selectedSession.Value);

            // Create order executor and order history (optional).
            ISourceOrderExecution executionProvider = null;
            if (orderExecuteId.HasValue)
            {
                executionProvider = ObtainOrderExecutionProvider(orderExecuteId.Value, actualDataSourceId);
            }

            if (session.SetInitialParameters(dataProvider, executionProvider) == false)
            {
                operationResultMessage = "Failed to set sessin initial parameters.";
                return null;
            }

            if (session.Initialize(selectedSession.Value) == false)
            {
                operationResultMessage = "Failed to initialize session.";
                session.Dispose();
                return null;
            }

            operationResultMessage = string.Empty;
            return session;
        }