Example #1
0
        protected override bool OnStart(out string operationResultMessage)
        {
            if (OperationalState == OperationalStateEnum.Operational ||
                OperationalState == OperationalStateEnum.Initializing ||
                OperationalState == OperationalStateEnum.Initializing)
            {
                operationResultMessage = "Adapter already started.";
                return(false);
            }

            if (_manager == null)
            {
                _manager = new FXCMConnectionManager();
            }

            // FXCM API is COM, and sometimes fails to release itself, so make sure we shall not hang.
            SeppukuWatchdog.Activate();

            StatusSynchronizationEnabled = true;
            StatusSynchronizationSource  = _manager;

            FXCMConnectionManager manager = _manager;

            if (manager.OperationalState != OperationalStateEnum.Initialized &&
                manager.OperationalState != OperationalStateEnum.Constructed)
            {
                operationResultMessage = "The FXCM Adapter can only be started once each application session. Restart the Open Forex Platform to start it again.";
                return(false);
            }

            if (manager.Login(Username, Password, _serviceUrl, _accountType, out operationResultMessage) == false)
            {
                operationResultMessage = "Failed to log in to FXCM [" + operationResultMessage + "].";
                SystemMonitor.OperationError(operationResultMessage);
                return(false);
            }
            else
            {
                if (_data.Initialize() == false || _orders.Initialize() == false)
                {
                    operationResultMessage = "Failed to initialize FXCMOrders or FXCMData.";
                    SystemMonitor.OperationError(operationResultMessage);
                    return(false);
                }

                operationResultMessage = string.Empty;

                StartSources();
                return(true);
            }
        }
Example #2
0
        protected override bool OnStart(out string operationResultMessage)
        {
            bool constructResult = Construct();

            // MBTrading API is COM, and often fails to release itself, so make sure we shall not hang.
            SeppukuWatchdog.Activate();

            MBTradingConnectionManager manager = _manager;

            if (manager == null)
            {
                operationResultMessage = "Manager not created.";
                return(false);
            }

            base.StatusSynchronizationSource = manager;

            lock (this)
            {
                if (manager.OperationalState != OperationalStateEnum.Initialized &&
                    manager.OperationalState != OperationalStateEnum.Constructed)
                {
                    operationResultMessage = "The MBTrading Adapter can only be started once each application session. Restart the Open Forex Platform to start it again.";
                    return(false);
                }

                ChangeOperationalState(OperationalStateEnum.Initializing);
            }

            if (manager.Login(Username, Password) == false)
            {
                operationResultMessage = "Failed to log in to MBT.";
                SystemMonitor.OperationError(operationResultMessage);
                return(false);
            }
            else
            {
                operationResultMessage = string.Empty;

                StartSources();
                return(true);
            }
        }