예제 #1
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));
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        protected async override Task ExecuteAsync(CancellationToken cancellationToken)
        {
            cancellationToken.Register(() =>
            {
                logger.LogInformation("Stoping service...");
                pumping.Disconnect();
                logger.LogInformation("Stoped service");
            });

            pumping.PUMP_UPDATE_TRADES += (type, trade, param) =>
            {
                try
                {
                    if (trade.Cmd == TradeCommand.BALANCE)
                    {
                        logger.LogInformation(trade.ToString());
                        if (Regex.IsMatch(trade.Comment, option.Value.DepositCommentRegex))
                        {
                            if (option.Value.Logins != null && option.Value.Logins.Count > 0)
                            {
                                if (!option.Value.Logins.Contains(trade.Login))
                                {
                                    logger.LogInformation($"login: {trade.Login} is not allowed in settings");
                                    return;
                                }
                            }
                            var charged = trade.Profit * option.Value.Percent / 100;

                            var user  = manager.UserRequest(trade.Login, codePage: 1251);
                            var group = groups.FirstOrDefault(p => p.Name == user.Group);
                            if (group != null)
                            {
                                var currency = group.Currency;
                                if (option.Value.Max.TryGetValue(currency, out double max))
                                {
                                    if (charged > max)
                                    {
                                        charged = max;
                                    }
                                }
                            }

                            if (charged > 0)
                            {
                                ChargeCashback(trade.Login, charged, string.Format(option.Value.Comment, trade.Order));
                            }
                            else
                            {
                                logger.LogWarning($"charged amount invalid: {charged}. order: {trade}");
                            }
                        }
                        else
                        {
                            logger.LogInformation($"non deposit operation. pattern: {option.Value.DepositCommentRegex}");
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.LogError($"error unexpected: {e.Message}");
                }
            };

            pumping.PUMP_STOP_PUMPING += (param) =>
            {
                logger.LogInformation($"stoped pumping");

                if (!cancellationToken.IsCancellationRequested)
                {
                    ConnectionLoop(cancellationToken);
                }
            };

            ConnectionLoop(cancellationToken);
            await Task.CompletedTask;
        }