コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            lock (this)
            {
                if (_orders != null)
                {
                    _orders.UnInitialize();
                    _orders.Dispose();
                    _orders = null;
                }

                if (_adapter != null)
                {
                    _adapter = null;
                }

                if (_core != null)
                {
                    _desk = null;
                    _core = null;
                }

                if (_messageLoopOperator != null)
                {
                    _messageLoopOperator.Stop();
                    _messageLoopOperator.Dispose();
                    _messageLoopOperator = null;
                }

                ChangeOperationalState(OperationalStateEnum.Disposed);
            }

            //GC.Collect();
        }
コード例 #2
0
        /// <summary>
        /// Perform logout.
        /// </summary>
        public bool Logout()
        {
            ChangeOperationalState(OperationalStateEnum.NotOperational);

            GeneralHelper.DefaultDelegate del = delegate()
            {
                if (_core != null && _desk.IsLoggedIn())
                {
                    Managed_Unsubscribe();

                    _desk.Logout();

                    _desk = null;
                    _core = null;
                }
            };

            BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator;

            if (messageLoopOperator == null || messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180)) == false)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Perform a login.
        /// </summary>
        public bool Login(string username, string password, string serviceUrl, string accountType, out string operationResultMessage)
        {
            _messageLoopOperator.Start();

            if (OperationalState != OperationalStateEnum.Initialized &&
                OperationalState != OperationalStateEnum.Initializing &&
                OperationalState != OperationalStateEnum.Constructed)
            {
                operationResultMessage = "Login already started.";
                return(false);
            }

            this._serviceUrl = serviceUrl;

            string operationResultMessageCopy = string.Empty;

            ChangeOperationalState(OperationalStateEnum.Initializing);

            object result = false;

            GeneralHelper.GenericReturnDelegate <bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);

                    Managed_Subscribe();

                    SystemMonitor.Report("FXCM Service subscribed.");
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    operationResultMessageCopy = "Failed to log in [" + exception.Message + "].";
                    SystemMonitor.OperationError(operationResultMessageCopy);
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return(_desk.IsLoggedIn());
            };

            if (_messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result) == false || (bool)result == false)
            {
                ChangeOperationalState(OperationalStateEnum.NotOperational);
                operationResultMessage = operationResultMessageCopy;
                return(false);
            }

            operationResultMessage = operationResultMessageCopy;
            return((bool)result);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Logout()
        {
            if (_core != null && _desk.IsLoggedIn())
            {
                Unsubscribe();

                _desk.Logout();

                _desk = null;
                _core = null;
            }

            ChangeOperationalState(OperationalStateEnum.NotOperational);
            return(true);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password, string serviceUrl, string accountType)
        {
            if (OperationalState != OperationalStateEnum.Initialized &&
                OperationalState != OperationalStateEnum.Initializing &&
                OperationalState != OperationalStateEnum.Constructed)
            {
                return(false);
            }

            object result = false;

            GeneralHelper.GenericReturnDelegate <bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                lock (this)
                {
                    _orders.Initialize(_adapter, this);
                }

                ChangeOperationalState(OperationalStateEnum.Initializing);

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);
                    Subscribe();
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    SystemMonitor.OperationError("Failed to log in [" + exception.Message + "].");
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return(_desk.IsLoggedIn());
            };

            _messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result);

            return((bool)result);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            ChangeOperationalState(OperationalStateEnum.Disposed);

            _desk = null;
            _core = null;
            _tradeDeskEventsSink = null;

            BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator;

            if (messageLoopOperator != null)
            {
                messageLoopOperator.Stop();
                messageLoopOperator.Dispose();
            }

            _messageLoopOperator = null;

            GC.Collect();
        }
コード例 #7
0
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            lock (this)
            {
                if (_orders != null)
                {
                    _orders.UnInitialize();
                    _orders.Dispose();
                    _orders = null;
                }

                if (_adapter != null)
                {
                    _adapter = null;
                }

                if (_core != null)
                {
                    _desk = null;
                    _core = null;
                }

                if (_messageLoopOperator != null)
                {
                    _messageLoopOperator.Stop();
                    _messageLoopOperator.Dispose();
                    _messageLoopOperator = null;
                }

                ChangeOperationalState(OperationalStateEnum.Disposed);
            }

            //GC.Collect();
        }
コード例 #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Logout()
        {
            if (_core != null && _desk.IsLoggedIn())
            {
                Unsubscribe();

                _desk.Logout();

                _desk = null;
                _core = null;
            }

            ChangeOperationalState(OperationalStateEnum.NotOperational);
            return true;
        }
コード例 #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Login(string username, string password, string serviceUrl, string accountType)
        {
            if (OperationalState != OperationalStateEnum.Initialized
                 && OperationalState != OperationalStateEnum.Initializing
                && OperationalState != OperationalStateEnum.Constructed)
            {
                return false;
            }

            object result = false;

            GeneralHelper.GenericReturnDelegate<bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                lock (this)
                {
                    _orders.Initialize(_adapter, this);
                }

                ChangeOperationalState(OperationalStateEnum.Initializing);

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);
                    Subscribe();
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    SystemMonitor.OperationError("Failed to log in [" + exception.Message + "].");
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return _desk.IsLoggedIn();
            };

            _messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result);

            return (bool)result;
        }
コード例 #10
0
        /// <summary>
        /// Perform logout.
        /// </summary>
        public bool Logout()
        {
            ChangeOperationalState(OperationalStateEnum.NotOperational);

            GeneralHelper.DefaultDelegate del = delegate()
            {
                if (_core != null && _desk.IsLoggedIn())
                {
                    Managed_Unsubscribe();

                    _desk.Logout();

                    _desk = null;
                    _core = null;
                }
            };

            BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator;

            if (messageLoopOperator == null || messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180)) == false)
            {
                return false;
            }

            return true;
        }
コード例 #11
0
        /// <summary>
        /// Perform a login.
        /// </summary>
        public bool Login(string username, string password, string serviceUrl, string accountType, out string operationResultMessage)
        {
            _messageLoopOperator.Start();

            if (OperationalState != OperationalStateEnum.Initialized
                 && OperationalState != OperationalStateEnum.Initializing
                && OperationalState != OperationalStateEnum.Constructed)
            {
                operationResultMessage = "Login already started.";
                return false;
            }

            this._serviceUrl = serviceUrl;

            string operationResultMessageCopy = string.Empty;

            ChangeOperationalState(OperationalStateEnum.Initializing);

            object result = false;
            GeneralHelper.GenericReturnDelegate<bool> del = delegate()
            {
                if (_core == null)
                {
                    _core = new FXCore.CoreAutClass();
                    _desk = (FXCore.TradeDeskAut)_core.CreateTradeDesk("trader");
                }

                try
                {
                    _desk.Login(username, password, serviceUrl, accountType);

                    Managed_Subscribe();

                    SystemMonitor.Report("FXCM Service subscribed.");
                    ChangeOperationalState(OperationalStateEnum.Operational);
                }
                catch (Exception exception)
                {
                    operationResultMessageCopy = "Failed to log in [" + exception.Message + "].";
                    SystemMonitor.OperationError(operationResultMessageCopy);
                    ChangeOperationalState(OperationalStateEnum.NotOperational);
                }

                return _desk.IsLoggedIn();
            };

            if (_messageLoopOperator.Invoke(del, TimeSpan.FromSeconds(180), out result) == false || (bool)result == false)
            {
                ChangeOperationalState(OperationalStateEnum.NotOperational);
                operationResultMessage = operationResultMessageCopy;
                return false;
            }

            operationResultMessage = operationResultMessageCopy;
            return (bool)result;
        }
コード例 #12
0
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            ChangeOperationalState(OperationalStateEnum.Disposed);

            _desk = null;
            _core = null;
            _tradeDeskEventsSink = null;

            BackgroundMessageLoopOperator messageLoopOperator = _messageLoopOperator;
            if (messageLoopOperator != null)
            {
                messageLoopOperator.Stop();
                messageLoopOperator.Dispose();
            }

            _messageLoopOperator = null;

            GC.Collect();
        }