Ejemplo n.º 1
0
        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");
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private void server_Stopped(object sender, EventArgs e)
        {
            MtServer server = (MtServer)sender;

            server.Stopped -= server_Stopped;

            var port = server.Port;

            lock (mServersDictionary)
            {
                if (mServersDictionary.ContainsKey(port))
                {
                    mServersDictionary.Remove(port);
                }
            }
        }
Ejemplo n.º 5
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");
        }