Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
        }