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); }
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(); } }
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(); } }
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(); } } } }
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(); } } } }
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(); } } } }
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"); }
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"); }
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(); } }
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."); }
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."); }
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."); }
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); }
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); }
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); } }
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); } }
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."); }
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"); }
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"); }
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(); } }
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"); }
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(); } } } }
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."); }
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."); }
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(); } } } }
private void expert_QuoteChanged(MtExpert expert, MtQuote quote) { mService.QuoteUpdate(quote); }
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(); } } } }