コード例 #1
0
ファイル: MtServerInstance.cs プロジェクト: linyunfeng/mtapi
        public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
        {
            Debug.WriteLine("MtApiServerInstance::InitExpert: symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);

            MtServer server = null;
            lock (mServersDictionary)
            {
                if (mServersDictionary.ContainsKey(port))
                {
                    server = mServersDictionary[port];
                }
                else
                {
                    server = new MtServer(port);
                    server.Stopped += new EventHandler(server_Stopped);
                    mServersDictionary[port] = server;

                    server.Start();
                }
            }

            var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler);

            lock (mExpertsDictionary)
            {
                mExpertsDictionary[expert.Handle] = expert;
            }

            server.AddExpert(expert);
        }
コード例 #2
0
        public void AddCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                return;
            }

            var notify = false;

            lock (_locker)
            {
                if (_commandExecutors.Contains(commandExecutor))
                {
                    return;
                }

                _commandExecutors.Add(commandExecutor);
                if (_commandTasks.Count > 0)
                {
                    notify = true;
                }
            }

            commandExecutor.CommandExecuted += CommandExecutor_CommandExecuted;
            commandExecutor.CommandManager   = this;

            if (notify)
            {
                NotifyCommandReady();
            }
        }
コード例 #3
0
        public void RemoveCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                return;
            }

            var notify = false;

            lock (_locker)
            {
                if (_commandExecutors.Contains(commandExecutor) == false)
                {
                    return;
                }

                _commandExecutors.Remove(commandExecutor);
                if (_commandTasks.Count > 0)
                {
                    notify = true;
                }
            }

            commandExecutor.CommandExecuted -= CommandExecutor_CommandExecuted;
            commandExecutor.CommandManager   = null;

            if (notify)
            {
                NotifyCommandReady();
            }
        }
コード例 #4
0
ファイル: MtExecutorManager.cs プロジェクト: plexzhang/mtapi
        public void AddCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                return;
            }

            lock (_locker)
            {
                if (mCommandExecutors.Contains(commandExecutor) == true)
                {
                    return;
                }

                mCommandExecutors.Add(commandExecutor);

                commandExecutor.CommandManager = this;

                if (mCurrentExecutor == null)
                {
                    mCurrentExecutor = commandExecutor;
                    mCurrentExecutor.IsCommandExecutor = true;

                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #5
0
ファイル: MtExecutorManager.cs プロジェクト: plexzhang/mtapi
        public void RemoveCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                return;
            }

            lock (_locker)
            {
                if (mCommandExecutors.Contains(commandExecutor) == false)
                {
                    return;
                }

                mCommandExecutors.Remove(commandExecutor);

                if (mCurrentExecutor == commandExecutor)
                {
                    mCurrentExecutor.IsCommandExecutor = false;
                    mCurrentExecutor = mCommandExecutors.Count > 0 ? mCommandExecutors[0] : null;

                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #6
0
        public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
        {
            Debug.WriteLine("MtApiServerInstance::InitExpert: symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);

            MtServer server = null;

            lock (mServersDictionary)
            {
                if (mServersDictionary.ContainsKey(port))
                {
                    server = mServersDictionary[port];
                }
                else
                {
                    server                   = new MtServer(port);
                    server.Stopped          += new EventHandler(server_Stopped);
                    mServersDictionary[port] = server;

                    server.Start();
                }
            }

            var expert = new MtExpert(expertHandle, new MtQuote(symbol, bid, ask), mtHandler);

            lock (mExpertsDictionary)
            {
                mExpertsDictionary[expert.Handle] = expert;
            }

            server.AddExpert(expert);
        }
コード例 #7
0
ファイル: MtExecutorManager.cs プロジェクト: linyunfeng/mtapi
        public void AddCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
                return;

            lock (_locker)
            {
                if (mCommandExecutors.Contains(commandExecutor) == true)
                    return;

                mCommandExecutors.Add(commandExecutor);

                commandExecutor.CommandManager = this;

                if (mCurrentExecutor == null)
                {
                    mCurrentExecutor = commandExecutor;
                    mCurrentExecutor.IsCommandExecutor = true;

                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #8
0
ファイル: MtAdapter.cs プロジェクト: username77/mtapi
        public void AddExpert(int port, MtExpert expert)
        {
            if (expert == null)
                throw new ArgumentNullException(nameof(expert));

            Log.InfoFormat("AddExpert: begin. expert = {0}", expert);

            MtServer server;
            lock (_servers)
            {
                if (_servers.ContainsKey(port))
                {
                    server = _servers[port];
                }
                else
                {
                    server = new MtServer(port);
                    server.Stopped += server_Stopped;
                    _servers[port] = server;

                    server.Start();
                }
            }

            lock (_experts)
            {
                _experts[expert.Handle] = expert;
            }

            server.AddExpert(expert);
            expert.Deinited += ExpertOnDeinited;

            Log.Info("AddExpert: end");
        }
コード例 #9
0
ファイル: MtAdapter.cs プロジェクト: username77/mtapi
        public void RemoveExpert(int expertHandle)
        {
            Log.InfoFormat("RemoveExpert: begin. expertHandle = {0}", expertHandle);

            MtExpert expert = null;

            lock (_experts)
            {
                if (_experts.ContainsKey(expertHandle))
                {
                    expert = _experts[expertHandle];
                }
            }

            if (expert != null)
            {
                expert.Deinit();
            }
            else
            {
                Log.WarnFormat("RemoveExpert: expert with id {0} has not been found.", expertHandle);
            }

            Log.Info("RemoveExpert: end");
        }
コード例 #10
0
ファイル: MtServer.cs プロジェクト: plexzhang/mtapi
        private void expert_Deinited(object sender, EventArgs e)
        {
            MtExpert expert       = (MtExpert)sender;
            int      expertsCount = 0;

            lock (mExpertsLocker)
            {
                mExperts.Remove(expert);

                expertsCount = mExperts.Count();
            }

            mExecutorManager.RemoveCommandExecutor(expert);

            if (expert != null)
            {
                expert.Deinited     -= expert_Deinited;
                expert.QuoteChanged -= expert_QuoteChanged;

                mService.OnQuoteRemoved(expert.Quote);
            }

            if (expertsCount == 0)
            {
                var stopTimer = new System.Timers.Timer();
                stopTimer.Elapsed += stopTimer_Elapsed;
                stopTimer.Interval = STOP_EXPERT_INTERVAL;
                stopTimer.Start();
            }
        }
コード例 #11
0
ファイル: MtServer.cs プロジェクト: zhao0876/mtapi
        public void AddExpert(MtExpert expert)
        {
            Log.DebugFormat("AddExpert: begin. expert {0}", expert);

            if (expert == null)
            {
                Log.Warn("AddExpert: end. expert is not defined");
                return;
            }

            expert.Deinited     += expert_Deinited;
            expert.QuoteChanged += expert_QuoteChanged;
            expert.OnMtEvent    += Expert_OnMtEvent;

            lock (_experts)
            {
                _experts.Add(expert);
            }

            _executorManager.AddExecutor(expert);

            _service.OnQuoteAdded(expert.Quote);

            Log.Debug("AddExpert: end.");
        }
コード例 #12
0
ファイル: MtServer.cs プロジェクト: zhao0876/mtapi
        private void Expert_OnMtEvent(MtExpert expert, MtEvent e)
        {
            Log.DebugFormat("Expert_OnMtEvent: begin. expert = {0}, event = {1}", expert, e);

            _service.OnMtEvent(e);

            Log.Debug("Expert_OnMtEvent: end.");
        }
コード例 #13
0
ファイル: MtServer.cs プロジェクト: zhao0876/mtapi
        private void expert_QuoteChanged(MtExpert expert, MtQuote quote)
        {
            Log.DebugFormat("expert_QuoteChanged: begin. expert = {0}, quote = {1}", expert, quote);

            _service.QuoteUpdate(quote);

            Log.Debug("expert_QuoteChanged: end.");
        }
コード例 #14
0
        public int GetCommandType(int expertHandle)
        {
            Debug.WriteLine("MtApiServerInstance::GetCommandType: expertHandle = {0}", expertHandle);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            return((expert != null) ? expert.GetCommandType() : 0);
        }
コード例 #15
0
        public object GetCommandParameter(int expertHandle, int index)
        {
            Debug.WriteLine("MtApiServerInstance::GetCommandParameter: expertHandle = {0}, index = {1}", expertHandle, index);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            return((expert != null) ? expert.GetCommandParameter(index) : null);
        }
コード例 #16
0
ファイル: MtServer.cs プロジェクト: plexzhang/mtapi
        public void AddExpert(MtExpert expert)
        {
            if (expert != null)
            {
                expert.Deinited     += new EventHandler(expert_Deinited);
                expert.QuoteChanged += new MtExpert.MtQuoteHandler(expert_QuoteChanged);

                lock (mExpertsLocker)
                {
                    mExperts.Add(expert);
                }

                mExecutorManager.AddCommandExecutor(expert);

                mService.OnQuoteAdded(expert.Quote);
            }
        }
コード例 #17
0
        public void AddExpert(MtExpert expert)
        {
            if (expert != null)
            {
                expert.Deinited     += expert_Deinited;
                expert.QuoteChanged += expert_QuoteChanged;

                lock (_experts)
                {
                    _experts.Add(expert);
                }

                _executorManager.AddCommandExecutor(expert);

                _service.OnQuoteAdded(expert.Quote);
            }
        }
コード例 #18
0
        public void SendQuote(int expertHandle, string symbol, double bid, double ask)
        {
            Debug.WriteLine("MtApiServerInstance::SendQuote: enter. symbol = {0}, bid = {1}, ask = {2}", symbol, bid, ask);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            if (expert != null)
            {
                expert.Quote = new MtQuote(symbol, bid, ask);
            }

            Debug.WriteLine("MtApiServerInstance::SendQuote: finish.");
        }
コード例 #19
0
        public void SendResponse(int expertHandle, MtResponse response)
        {
            Debug.WriteLine("MtApiServerInstance::SendResponse: id = {0}, response = {1}", expertHandle, response);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            if (expert != null)
            {
                expert.SendResponse(response);
            }

            Debug.WriteLine("MtApiServerInstance::SendResponse: finish");
        }
コード例 #20
0
        public void SendEvent(int expertHandle, int eventType, string payload)
        {
            Debug.WriteLine("MtApiServerInstance::SendEvent called. eventType = {0}, payload = {1}", eventType, payload);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                expert = mExpertsDictionary[expertHandle];
            }

            if (expert != null)
            {
                expert.SendEvent(new MtEvent(eventType, payload));
            }

            Debug.WriteLine("MtApiServerInstance::SendEvent: finished");
        }
コード例 #21
0
        public void DeinitExpert(int expertHandle)
        {
            Debug.WriteLine("MtApiServerInstance::DeinitExpert: expertHandle = {0}", expertHandle);

            MtExpert expert = null;

            lock (mExpertsDictionary)
            {
                if (mExpertsDictionary.ContainsKey(expertHandle) == true)
                {
                    expert = mExpertsDictionary[expertHandle];
                    mExpertsDictionary.Remove(expertHandle);
                }
            }

            if (expert != null)
            {
                expert.Deinit();
            }
        }
コード例 #22
0
        public void InitExpert(int expertHandle, int port, string symbol, double bid, double ask, IMetaTraderHandler mtHandler)
        {
            if (mtHandler == null)
            {
                throw new ArgumentNullException(nameof(mtHandler));
            }

            Log.InfoFormat("InitExpert: begin. symbol = {0}, expertHandle = {1}, port = {2}", symbol, expertHandle, port);

            MtServer server;

            lock (_servers)
            {
                if (_servers.ContainsKey(port))
                {
                    server = _servers[port];
                }
                else
                {
                    server          = new MtServer(port);
                    server.Stopped += server_Stopped;
                    _servers[port]  = server;

                    server.Start();
                }
            }

            var expert = new MtExpert(expertHandle, new MtQuote {
                Instrument = symbol, Bid = bid, Ask = ask, ExpertHandle = expertHandle
            }, mtHandler);

            lock (_experts)
            {
                _experts[expert.Handle] = expert;
            }

            server.AddExpert(expert);

            Log.Info("InitExpert: end");
        }
コード例 #23
0
ファイル: MtExecutorManager.cs プロジェクト: plexzhang/mtapi
        public void OnCommandExecuted(MtExpert expert, MtCommand command, MtResponse response)
        {
            if (expert == null)
            {
                return;
            }

            if (CommandExecuted != null)
            {
                CommandExecuted(this, new MtCommandExecuteEventArgs(command, response));
            }

            lock (_locker)
            {
                if (expert == mCurrentExecutor)
                {
                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #24
0
        public void RemoveCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                throw new ArgumentNullException(nameof(commandExecutor));
            }

            Log.DebugFormat("RemoveCommandExecutor: begin. commandExecutor = {0}", commandExecutor);

            var notify = false;

            lock (_locker)
            {
                if (_commandExecutors.Contains(commandExecutor) == false)
                {
                    Log.Warn("RemoveCommandExecutor: end. Command executor is not exist in collection.");
                    return;
                }

                _commandExecutors.Remove(commandExecutor);
                if (_commandTasks.Count > 0)
                {
                    notify = true;
                }
            }

            commandExecutor.CommandExecuted -= CommandExecutor_CommandExecuted;
            commandExecutor.CommandManager   = null;

            if (notify)
            {
                NotifyCommandReady();
            }

            Log.Debug("RemoveCommandExecutor: end.");
        }
コード例 #25
0
        public void AddCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
            {
                throw new ArgumentNullException(nameof(commandExecutor));
            }

            Log.DebugFormat("AddCommandExecutor: begin. commandExecutor = {0}", commandExecutor);

            var notify = false;

            lock (_locker)
            {
                if (_commandExecutors.Contains(commandExecutor))
                {
                    Log.Warn("AddCommandExecutor: end. Command executor already exist.");
                    return;
                }

                _commandExecutors.Add(commandExecutor);
                if (_commandTasks.Count > 0)
                {
                    notify = true;
                }
            }

            commandExecutor.CommandExecuted += CommandExecutor_CommandExecuted;
            commandExecutor.CommandManager   = this;

            if (notify)
            {
                NotifyCommandReady();
            }

            Log.Debug("AddCommandExecutor: end.");
        }
コード例 #26
0
ファイル: MtExecutorManager.cs プロジェクト: linyunfeng/mtapi
        public void RemoveCommandExecutor(MtExpert commandExecutor)
        {
            if (commandExecutor == null)
                return;

            lock (_locker)
            {
                if (mCommandExecutors.Contains(commandExecutor) == false)
                    return;

                mCommandExecutors.Remove(commandExecutor);

                if (mCurrentExecutor == commandExecutor)
                {
                    mCurrentExecutor.IsCommandExecutor = false;
                    mCurrentExecutor = mCommandExecutors.Count > 0 ? mCommandExecutors[0] : null;

                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #27
0
ファイル: MtServer.cs プロジェクト: plexzhang/mtapi
 private void expert_QuoteChanged(MtExpert expert, MtQuote quote)
 {
     mService.QuoteUpdate(quote);
 }
コード例 #28
0
ファイル: MtExecutorManager.cs プロジェクト: linyunfeng/mtapi
        public void OnCommandExecuted(MtExpert expert, MtCommand command, MtResponse response)
        {
            if (expert == null)
                return;

            if (CommandExecuted != null)
            {
                CommandExecuted(this, new MtCommandExecuteEventArgs(command, response));
            }

            lock (_locker)
            {
                if (expert == mCurrentExecutor)
                {
                    if (mCommands.Count > 0)
                    {
                        mCurrentExecutor.NotifyCommandReady();
                    }
                }
            }
        }
コード例 #29
0
ファイル: MtServer.cs プロジェクト: linyunfeng/mtapi
        public void AddExpert(MtExpert expert)
        {
            if (expert != null)
            {
                expert.Deinited += new EventHandler(expert_Deinited);
                expert.QuoteChanged += new MtExpert.MtQuoteHandler(expert_QuoteChanged);

                lock (mExpertsLocker)
                {
                    mExperts.Add(expert);
                }

                mExecutorManager.AddCommandExecutor(expert);

                mService.OnQuoteAdded(expert.Quote);
            }
        }
コード例 #30
0
ファイル: MtServer.cs プロジェクト: linyunfeng/mtapi
 private void expert_QuoteChanged(MtExpert expert, MtQuote quote)
 {
     mService.QuoteUpdate(quote);
 }