Ejemplo n.º 1
0
        public void Connect_incorrect_auth()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            Assert.Throws <MT4BadAccountInfoExeption>(() => manager.Login(connect_incorrect_auth.login, connect_incorrect_auth.password));
        }
Ejemplo n.º 2
0
        public void Connect_success()
        {
            var manager = new MT4Manager(options);
            var ex      = Record.Exception(() => manager.Connect(connect.server));

            Assert.Null(ex);
        }
Ejemplo n.º 3
0
        public void network_problem_if_not_authorization_in_request_data()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);

            Assert.Throws <MT4NetworkProblemExeption>(() => manager.CfgRequestCommon(1251));
        }
Ejemplo n.º 4
0
        public void network_problem_if_not_authorization_in_request()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);

            Assert.Throws <MT4NetworkProblemExeption>(() => manager.SymbolsRefresh());
        }
Ejemplo n.º 5
0
        public void auto_reconnect_if_disconnected_in_request_returned_array()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);
            manager.Disconnect();

            Assert.NotEmpty(manager.TradesRequest(1251));
        }
Ejemplo n.º 6
0
        public void auto_reconnect_if_disconnected_in_request()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);
            manager.Disconnect();

            var ex = Record.Exception(() => manager.SymbolsRefresh());

            Assert.Null(ex);
        }
Ejemplo n.º 7
0
        public void auto_reconnect_if_disconnected_in_request_data()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);
            manager.Disconnect();

            var ex = Record.Exception(() => manager.CfgRequestCommon(1251));

            Assert.Null(ex);
        }
Ejemplo n.º 8
0
        public void request_not_correspond_in_pumping()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);
            manager.PumpingSwitch(code =>
            {
            }, IntPtr.Zero, 0, 0);


            Assert.Throws <MT4RequestNotCorrespondException>(() => manager.Ping());
        }
Ejemplo n.º 9
0
        public void check_pumping_functions()
        {
            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);
            manager.PumpingSwitchEx(0, 0);

            var newsTotal = manager.NewsTotal();
            var news      = manager.NewsGet(1251);
            var users     = manager.GroupsGet(1251);

            Assert.True(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Производит реконнект к серверу
        /// Функция используется в асинхронном режиме
        /// </summary>
        public static void ReconnectOnServer(this MT4Manager mt4Service, MT4ConnectOption setting)
        {
            while (true)
            {
                try
                {
                    mt4Service.Connect(setting.server);
                    mt4Service.Login(setting.login, setting.password);

                    if (!mt4Service.CheckConnection())
                    {
                        continue;
                    }
                    break;
                }
                catch (MT4NetworkProblemExeption) { }
                catch (MT4NoConnectionExeption) { }
                catch (MT4CommonErrorExeption) { }
            }
        }
Ejemplo n.º 11
0
        public void ConnectionLoop(CancellationToken cancellationToken)
        {
            new Thread(() =>
            {
                var connected = false;
                while (!cancellationToken.IsCancellationRequested && !connected)
                {
                    try
                    {
                        logger.LogInformation($"try connect to {option.Value.mt4.server}...");
                        pumping.Connect(option.Value.mt4.server);
                        manager.Connect(option.Value.mt4.server);
                        logger.LogInformation($"connected to {option.Value.mt4.server}");

                        logger.LogInformation($"try logining from {option.Value.mt4.login}...");
                        pumping.Login(option.Value.mt4.login, option.Value.mt4.password);
                        manager.Login(option.Value.mt4.login, option.Value.mt4.password);
                        logger.LogInformation($"logining success");

                        pumping.SymbolsRefresh();
                        manager.SymbolsRefresh();

                        this.groups = manager.GroupsRequest();

                        logger.LogInformation($"switch to pumping mode...");
                        pumping.PumpingSwitchEx(flags: PumpingFlags.HIDE_TICKS, param: null);
                        logger.LogInformation($"pumping mode ok");
                        connected = true;
                    }
                    catch (Exception e)
                    {
                        logger.LogError($"common error: {e.Message}");
                        Thread.Sleep(TimeSpan.FromSeconds(3));
                    }
                }
            })
            {
                IsBackground = true
            }.Start();
        }
Ejemplo n.º 12
0
 public static void Communication(this MT4Manager manager, MT4ConnectOption connection)
 {
     manager.Connect(connection.server);
     manager.Login(connection.login, connection.password);
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var options = new MT4NativeOption();
            var connect = new MT4ConnectOption();

            optionSet(out options, out connect);

            var manager = new MT4Manager(options);

            manager.Connect(connect.server);
            manager.Login(connect.login, connect.password);

            manager.PUMP_PING += (param) =>
            {
                Console.WriteLine($"{DateTime.Now} ping");
            };

            manager.PUMP_START_PUMPING += (param) =>
            {
                Console.WriteLine($"{DateTime.Now} start pumping");
            };

            manager.PUMP_STOP_PUMPING += (param) =>
            {
                Console.WriteLine($"{DateTime.Now} stop pumping");
            };

            manager.PUMP_UPDATE_ACTIVATION += (type, param) =>
            {
                foreach (var t in manager.TradesGet())
                {
                    Console.WriteLine($"{DateTime.Now} activation {t}");
                }
            };

            manager.PUMP_UPDATE_BIDASK += (param) =>
            {
                var infos = manager.SymbolInfoUpdated(10000);
                foreach (var info in infos)
                {
                    Console.WriteLine(info);
                }
            };

            manager.PUMP_UPDATE_GROUPS += (type, group, param) =>
            {
                Console.WriteLine($"{DateTime.Now} {type} group {group}");
            };

            manager.PUMP_UPDATE_MAIL += (type, news, param) =>
            {
                Console.WriteLine($"{type} mail {news}, param: {param}");
            };

            var newsKeys = new List <NewsTopicNew>();

            manager.PUMP_UPDATE_NEWS_NEW += (type, news, param) =>
            {
                Console.WriteLine(news);
            };

            manager.PUMP_UPDATE_NEWS_BODY += (type, param) =>
            {
                foreach (var n in newsKeys)
                {
                    var body = manager.NewsBodyGet(n.Key, n.Language);
                    Console.WriteLine(body);
                }
            };

            manager.PUMP_UPDATE_NEWS += (type, news, param) =>
            {
                Console.WriteLine($"update news: {news}");
            };

            manager.PUMP_UPDATE_MARGINCALL += (type, param) =>
            {
                foreach (var m in manager.MarginsGet())
                {
                    Console.WriteLine(m);
                }
            };

            manager.PUMP_UPDATE_ONLINE += (type, group, param) =>
            {
                foreach (var l in manager.OnlineGet())
                {
                    Console.WriteLine(l);
                }
            };

            manager.PUMP_UPDATE_PLUGINS += (type, param) =>
            {
                foreach (var p in manager.PluginsGet())
                {
                    Console.WriteLine(p);
                }
            };

            manager.PUMP_UPDATE_REQUESTS += (type, request, param) =>
            {
                Console.WriteLine(request);
                foreach (var p in manager.RequestsGet())
                {
                    //Console.WriteLine(p);
                }
            };

            manager.PUMP_UPDATE_SYMBOLS += (type, symbol, param) =>
            {
                Console.WriteLine(symbol);
                foreach (var p in manager.SymbolsGetAll())
                {
                    //Console.WriteLine(p);
                }
            };

            manager.PUMP_UPDATE_TRADES += (type, trade, param) =>
            {
                Console.WriteLine(trade);
                foreach (var p in manager.TradesGet())
                {
                    //Console.WriteLine(p);
                }
            };

            manager.PUMP_UPDATE_USERS += (type, user, param) =>
            {
                Console.WriteLine(user);
                foreach (var p in manager.UsersGet())
                {
                    //Console.WriteLine(p);
                }
            };

            manager.SymbolsRefresh();

            manager.PumpingSwitchEx(flags: 0, param: null);

            Console.WriteLine("ready");
            Console.ReadLine();
            Console.WriteLine("exit");
        }
Ejemplo n.º 14
0
        public void Connect_incorrect_server()
        {
            var manager = new MT4Manager(options);

            Assert.Throws <MT4NoConnectionExeption>(() => manager.Connect(connect_incorrect_server.server));
        }