//Receive new deal info from all servers and compere them public void NewFullDealReceive(clsDealInfo SmallDeal) { this.LastDealID++; SmallDeal.myID = this.LastDealID; this.LastDeals.Add(SmallDeal); FindCheating(SmallDeal); }
//Try find and log any suspicious activity private void FindCheating(clsDealInfo ValidateDeal) { Console.WriteLine($"New Deal .. Symbol={ValidateDeal.Symbol} time={ValidateDeal.OpenTime} Volume/Balane={ValidateDeal.Volume / ValidateDeal.Balance}"); if (this.LastDeals != null & this.LastDeals.Count > 0) { var similar = this.LastDeals.Where(x => x.myID != ValidateDeal.myID && x.Symbol == ValidateDeal.Symbol && Math.Abs(x.uOpenTime - ValidateDeal.uOpenTime) <= 1 && Math.Abs(x.Volume / x.Balance - ValidateDeal.Volume / ValidateDeal.Balance) <= 0.05 ); if (similar != null && similar.Count() > 0) { common.DisplayAndLog("Find Some similar deals."); foreach (var actDeal in similar) { common.DisplayAndLog($"A) Deal Server= {ValidateDeal.Server} Symbol={ValidateDeal.Symbol} Account={ValidateDeal.UserLogin} PositionID={ValidateDeal.PositionID} OpenTime={ValidateDeal.OpenTime}"); common.DisplayAndLog($"B) Deal Server= {actDeal.Server} Symbol={ValidateDeal.Symbol} Account={actDeal.UserLogin} PositionID={actDeal.PositionID} OpenTime={actDeal.OpenTime}"); } } } //delete all old items DateTime dNow = DateTime.Now.AddHours(1); //Server has differ dime, so we need to shift it this.LastDeals.RemoveAll(x => (dNow - x.OpenTime).TotalSeconds > 10); }
//call outside function to proced new Deal public void TellOutsideNewDealFull(clsDealInfo SmallDeal) { SmallDeal.Server = this.Connection.Server; this.ExternalNewDeallFullReport(SmallDeal); }
//Receive new deal info from server, find balance and tell it back to main thread public void NewDealReceive(clsDealInfo SmallDeal) { SmallDeal.Balance = this.GetBalanceNow(SmallDeal.UserLogin); this.TellOutsideNewDealFull(SmallDeal); }
//generate report for given server private bool CollectDeals4OneServer(clsServerConnectionInfo ServerInfo) { using (clsMT5 mt5 = new clsMT5()) { mt5.Initialize(); try { var log_result = mt5.m_manager.Connect(ServerInfo.Server, ServerInfo.uLogin, ServerInfo.Password, "", MetaQuotes.MT5ManagerAPI.CIMTManagerAPI.EnPumpModes.PUMP_MODE_FULL, 10000); } catch (Exception ex) { Console.WriteLine(ex); return(false); } //get all groups at server MTRetCode res = MTRetCode.MT_RET_ERROR; var GroupList = mt5.GetAllGroups(out res); if (!(res == MTRetCode.MT_RET_OK || res == MTRetCode.MT_RET_ERR_NOTFOUND)) { return(false); } GroupList.RemoveAll(x => x.Group() == this.ExcludedGroup); foreach (var actGroup in GroupList) { var newGroup2add = new clsServerXGroup() { Server = ServerInfo.Server, Group = actGroup.Group() }; this.AllGroups.Add(newGroup2add); } foreach (var actGroup in GroupList) { //get all Users at server var userList = mt5.GetAllUsersAtGroup(actGroup.Group(), out res); if (!(res == MTRetCode.MT_RET_OK || res == MTRetCode.MT_RET_ERR_NOTFOUND)) { return(false); } userList.RemoveAll(x => x.Login() == this.uExcludedUser); foreach (var actUser in userList) { //get all deals as server var dealList = mt5.GetAllDeals(actUser.Login(), out res, this.StartDate, this.StopDate); Console.WriteLine($"user {actUser.Login()} trades count={dealList.Count()}"); if (!(res == MTRetCode.MT_RET_OK || res == MTRetCode.MT_RET_ERR_NOTFOUND)) { return(false); } foreach (var actDeal in dealList) { var dataNode = new clsDealInfo(); dataNode.Server = ServerInfo.Server; dataNode.Group = actGroup.Group(); dataNode.Profit = actDeal.Profit(); dataNode.Volume = actDeal.Volume(); dataNode.BuySell = (int)actDeal.Action(); dataNode.uOpenTime = actDeal.Time(); this.CollectedData.Add(dataNode); } } } } return(true); }