예제 #1
0
        private void FillAccountsDictionary()
        {
            try
            {
                var accounts = signalServiceRepository.GetAccountsMt4Location();

                foreach (var account in accounts)
                {
                    var serverName = serversDictionary[account.AccountType];

                    if (mt4AccountsDictionary.ContainsKey(serverName))
                    {
                        mt4AccountsDictionary[serverName].Add(account.Login, account.AccountId);
                    }
                    else
                    {
                        mt4AccountsDictionary.Add(serverName, new Dictionary <int, long> {
                            { account.Login, account.AccountId }
                        });
                    }

                    AccountsDictionary.Add(account.AccountId, new Tuple <string, int>(serverName, account.Login));
                }
            }
            catch (Exception e)
            {
                SignalService.Logger.Error(e.Message);
            }
        }
예제 #2
0
        public void Validate()
        {
            try
            {
                InitDictionaries();

                SignalService.Logger.Debug("Consistency validate started...");

                var serversResult = accountService.GetAccountTypesWithServers();
                if (!serversResult.IsSuccess)
                {
                    SignalService.Logger.Error(serversResult.Error);
                    return;
                }
                serversDictionary = serversResult.Result.ToDictionary(x => (int)x.AccountType, x => x.ServerName);

                var serverNames = serversDictionary.Values.Distinct().ToArray();

                handlersDictionary = serverNames.ToDictionary(x => x,
                                                              x => new EventWaitHandle(false, EventResetMode.ManualReset));

                var mt4Locations = repository.GetAccountsMt4Location();

                accountsDictionary = mt4Locations.ToDictionary(x => x.AccountId,
                                                               x => new Tuple <string, int>(serversDictionary[x.AccountType], x.Login));

                var waitHandles = new WaitHandle[serverNames.Count()];

                for (var i = 0; i < serverNames.Count(); i++)
                {
                    var j      = i;
                    var server = serverNames[j];
                    var thread = new Thread(() =>
                    {
                        var typeIds = serversDictionary.Where(x => x.Value == server).Select(x => x.Key).ToList();
                        var request = new OrdersStatusRequest();
                        request.logins.AddRange(mt4Locations.Where(x => typeIds.Contains(x.AccountType)).Select(x => x.Login));
                        serverController.OrdersStatusRequestsOnNext(new Tuple <string, OrdersStatusRequest>(server, request));
                        SignalService.Logger.Debug("Orders status request sended to server - {0}", server);
                    });
                    waitHandles[j] = handlersDictionary[server];
                    thread.Start();
                }

                var result = WaitHandle.WaitAll(waitHandles, waitHandleTimeout);
                if (!result)
                {
                    SignalService.Logger.Error("Some responses from mt4 were not handled");
                    return;
                }

                CheckConsistency();

                TradeSignalProcessor.OpenedOrdersDictionary = openedOrderDictionary;
            }
            catch (Exception e)
            {
                SignalService.Logger.Error("Consistency validation exception: {0}", e.ToString());
            }
        }