Beispiel #1
0
        private void IbetEnOnUpdateLiveDataChange(List <MatchOddDTO> matchOddDtos, bool isLive)
        {
            try
            {
                var sellMatchs = SellMatchs.Where(sm => !sm.FinishCheck);
                //dung LiveMatchOddBag
                if (sellMatchs.Any())
                {
                    int countCheck = 0;

                    foreach (var sellTran in sellMatchs)
                    {
                        ////Kiem tra xem tran do co vao ty so chua
                        var checkMatchScored = ScoredMatchs.Any(m =>
                                                                (String.Equals(m.HomeTeamName, sellTran.BuyMatchOdd.HomeTeamName, StringComparison.CurrentCultureIgnoreCase) ||
                                                                 String.Equals(m.AwayTeamName, sellTran.BuyMatchOdd.AwayTeamName, StringComparison.CurrentCultureIgnoreCase)) &&
                                                                sellTran.SumScore != (m.HomeScore + m.AwayScore));

                        if (checkMatchScored)
                        {
                            sellTran.FinishCheck = true;
                            UpdateWriteTextLog(string.Format("Trận đấu {0} vs {1} có tỷ số mới, hủy quét giá bán!", sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName), eLogTextType.Error, eBrokerStatus.GoalFailBet);
                            continue;
                        }


                        if (countCheck > 0)
                        {
                            Thread.Sleep(500);
                        }

                        countCheck++;

                        var         sboMatchSell = GetValidSboMatchOdd(sellTran.BuyMatchOdd, true);
                        eServerType serverSell   = eServerType.Unknown;
                        float       sellOddScan  = 0f;
                        if (sboMatchSell != null)
                        {
                            var sellPrepareSbo = SboEnScan.PrepareBetBroker(sboMatchSell, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);

                            if (sellPrepareSbo == null)
                            {
                                sboMatchSell = GetValidSboMatchOdd(sellTran.BuyMatchOdd, false);
                                if (sboMatchSell != null)
                                {
                                    sellPrepareSbo = SboEn.PrepareBetBroker(sboMatchSell, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                }
                            }

                            if (sellPrepareSbo != null)
                            {
                                serverSell  = eServerType.Sbo;
                                sellOddScan = sellPrepareSbo.NewOdd;
                                OddDTO ibetOdd;
                                if (GetValidIbetMatchOdd(sellTran.BuyMatchOdd, out ibetOdd))
                                {
                                    var newIbetOdd = IbetEnScan.PrepareBet(ibetOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                    if (newIbetOdd != null)
                                    {
                                        if ((newIbetOdd.Value * sellPrepareSbo.NewOdd > 0 && newIbetOdd.Value > sellPrepareSbo.NewOdd) ||
                                            (newIbetOdd.Value * sellPrepareSbo.NewOdd < 0 && newIbetOdd.Value < 0))
                                        {
                                            serverSell  = eServerType.Ibet;
                                            sellOddScan = newIbetOdd.Value;
                                        }
                                    }
                                }
                            }

                            UpdateWriteTextLog(string.Format("-----> quét {0} vs {1} {2}:{3} result {4}: {5}",
                                                             sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                             sellTran.BuyMatchOdd.OddType, sellTran.BuyMatchOdd.Odd, sellTran.SellBetType, sellOddScan), eLogTextType.LowLevel);
                        }
                        else
                        {
                            OddDTO ibetOdd;
                            if (GetValidIbetMatchOdd(sellTran.BuyMatchOdd, out ibetOdd))
                            {
                                var newIbetOdd = IbetEn.PrepareBet(ibetOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                if (newIbetOdd != null)
                                {
                                    serverSell  = eServerType.Ibet;
                                    sellOddScan = newIbetOdd.Value;
                                    UpdateWriteTextLog(string.Format("-----> quét {0} vs {1} {2}:{3} result {4}: {5}",
                                                                     sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                     sellTran.BuyMatchOdd.OddType, sellTran.BuyMatchOdd.Odd, sellTran.SellBetType, sellOddScan), eLogTextType.LowLevel);
                                }
                            }
                        }

                        lock (LockBetSellEngine)
                        {
                            BetSellEngines.Shuffle();

                            if (sellTran.BuyTime.AddMinutes(sellTran.TimeCheckScan) < DateTime.Now)
                            {
                                foreach (var sellEngine in BetSellEngines)
                                {
                                    if (serverSell != eServerType.Unknown && sellEngine.ServerType != serverSell)
                                    {
                                        continue;
                                    }

                                    if ((serverSell == eServerType.Ibet && sellEngine.EngineId == LastIbetEngineIdSell) ||
                                        (serverSell == eServerType.Sbo && sellEngine.EngineId == LastSboEngineIdSell))
                                    {
                                        continue;
                                    }

                                    var sellPrepare = sellEngine.PrepareBetBroker(sellTran.BuyMatchOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                    if (sellPrepare != null)
                                    {
                                        var odd       = sellPrepare.NewOdd;
                                        int sellPoint = ConvertMoneyToPoint(sellTran.SellMoneyAverage, sellEngine.ExchangeRate);
                                        if (sellPoint > sellPrepare.MaxBet)
                                        {
                                            sellPoint = sellPrepare.MaxBet;
                                        }

                                        sellPoint = GetGoodPoint(sellPoint, sellPrepare.MaxBet, true);
                                        if (sellEngine.ConfirmBetBroker(sellPoint))
                                        {
                                            if (serverSell == eServerType.Ibet)
                                            {
                                                LastIbetEngineIdSell = sellEngine.EngineId;
                                            }
                                            else
                                            {
                                                LastSboEngineIdSell = sellEngine.EngineId;
                                            }

                                            sellTran.SumMoneyBuy -= ConvertPointToMoney(sellPoint, sellEngine.ExchangeRate);

                                            UpdateWriteTextLog(string.Format("BÁN NHANH [{3}] {0} vs {1} sau {2} phút ODD: {5}  *stake: {4}",
                                                                             sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                             sellTran.TimeCheckScan, sellEngine.UserName, sellPoint, odd), eLogTextType.Warning, eBrokerStatus.Sell);

                                            lock (LockSellTrans)
                                            {
                                                sellTran.SellTimer   = new System.Threading.Timer(SellCallBack, sellTran, WaitSellTimes[R.Next(WaitSellTimes.Count)], 60000);
                                                sellTran.FinishCheck = true;
                                                sellTran.FastSell    = true;
                                                sellTran.ServerSell  = serverSell;
                                                sellTran.SellSuccessCount++;
                                                SellTrans.Add(sellTran);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (serverSell != eServerType.Unknown && IsValidOddPair(sellTran.BuyOdd, sellOddScan))
                                {
                                    foreach (var sellEngine in BetSellEngines)
                                    {
                                        if (sellEngine.ServerType != serverSell)
                                        {
                                            continue;
                                        }

                                        if ((serverSell == eServerType.Ibet && sellEngine.EngineId == LastIbetEngineIdSell) ||
                                            (serverSell == eServerType.Sbo && sellEngine.EngineId == LastSboEngineIdSell))
                                        {
                                            continue;
                                        }

                                        var sellPrepare = sellEngine.PrepareBetBroker(sellTran.BuyMatchOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                        if (sellPrepare != null)
                                        {
                                            int sellPoint = ConvertMoneyToPoint(sellTran.SellMoneyAverage, sellEngine.ExchangeRate);
                                            if (sellPoint > sellPrepare.MaxBet)
                                            {
                                                sellPoint = sellPrepare.MaxBet;
                                            }

                                            sellPoint = GetGoodPoint(sellPoint, sellPrepare.MaxBet, true);

                                            if (sellEngine.ConfirmBetBroker(sellPoint))
                                            {
                                                if (serverSell == eServerType.Ibet)
                                                {
                                                    LastIbetEngineIdSell = sellEngine.EngineId;
                                                }
                                                else
                                                {
                                                    LastSboEngineIdSell = sellEngine.EngineId;
                                                }

                                                sellTran.SumMoneyBuy -= ConvertPointToMoney(sellPoint, sellEngine.ExchangeRate);
                                                UpdateWriteTextLog(string.Format("BÁN [{6}]: {0} vs {1} {2}:{3} PICK {4}: {5}  **stake: {7}",
                                                                                 sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                                 sellTran.BuyMatchOdd.OddType, sellTran.BuyMatchOdd.Odd, sellTran.SellBetType, sellOddScan, sellEngine.UserName, sellPoint), eLogTextType.Warning, eBrokerStatus.Sell);

                                                lock (LockSellTrans)
                                                {
                                                    sellTran.SellTimer   = new System.Threading.Timer(SellCallBack, sellTran, WaitSellTimes[R.Next(WaitSellTimes.Count)], 60000);
                                                    sellTran.FinishCheck = true;
                                                    sellTran.SellSuccessCount++;
                                                    sellTran.ServerSell = serverSell;
                                                    SellTrans.Add(sellTran);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    continue;
                                }
                            }
                        }
                    }
                }

                lock (LockSellTrans)
                {
                    SellTrans.RemoveAll(sm => sm.FinishTransaction);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("IbetEnOnUpdateLiveDataChange func", ex);
            }
        }
        private void IbetEnOnUpdateLiveDataChange(List <MatchOddDTO> matchOddDtos, bool isLive)
        {
            try
            {
                //dung LiveMatchOddBag
                lock (LockSellMatch)
                {
                    if (SellMatchs.Any())
                    {
                        int countCheck = 0;

                        foreach (var sellTran in SellMatchs)
                        {
                            ////Kiem tra xem tran do co vao ty so chua
                            lock (LockScoredMatch)
                            {
                                var checkMatchScored = ScoredMatchs.FirstOrDefault(m =>
                                                                                   (String.Equals(m.HomeTeamName, sellTran.BuyMatchOdd.HomeTeamName, StringComparison.CurrentCultureIgnoreCase) ||
                                                                                    String.Equals(m.AwayTeamName, sellTran.BuyMatchOdd.AwayTeamName, StringComparison.CurrentCultureIgnoreCase)) &&
                                                                                   sellTran.SumScore != (m.HomeScore + m.AwayScore));

                                if (checkMatchScored != null)
                                {
                                    sellTran.FinishCheck = true;
                                    UpdateWriteTextLog(string.Format("Trận đấu {0}-{1} có tỷ số mới, hủy quét giá bán!", sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName), eLogTextType.Error, eBrokerStatus.Bet);
                                    continue;
                                }
                            }

                            if (countCheck > 0)
                            {
                                Thread.Sleep(500);
                            }

                            countCheck++;

                            if (sellTran.BuyTime.AddMinutes(sellTran.TimeCheckScan) < DateTime.Now)
                            {
                                foreach (var sellEngine in sellTran.BetSellEngine)
                                {
                                    var sellPrepare = sellEngine.PrepareBetBroker(sellTran.BuyMatchOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                    if (sellPrepare != null)
                                    {
                                        int sellPoint = ConvertMoneyToPoint(sellTran.SellMoneyAverage, sellEngine.ExchangeRate);
                                        if (sellPoint > sellPrepare.MaxBet)
                                        {
                                            sellPoint = sellPrepare.MaxBet;
                                        }

                                        sellPoint = GetGoodPoint(sellPoint);
                                        if (sellEngine.ConfirmBetBroker(sellPoint))
                                        {
                                            sellTran.SumMoneyBuy -= ConvertPointToMoney(sellPoint, sellEngine.ExchangeRate);

                                            UpdateWriteTextLog(string.Format("BÁN NHANH [{3}] {0}-{1} sau {2} phút  *stake: {4}",
                                                                             sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                             sellTran.TimeCheckScan, sellEngine.UserName, sellPoint), eLogTextType.Warning, eBrokerStatus.Bet);

                                            lock (LockSellTrans)
                                            {
                                                sellTran.SellTimer   = new System.Threading.Timer(SellCallBack, sellTran, WaitSellTimes[R.Next(WaitSellTimes.Count)], 60000);
                                                sellTran.FinishCheck = true;
                                                sellTran.FastSell    = true;
                                                sellTran.SellSuccessCount++;
                                                SellTrans.Add(sellTran);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                var sboMatchSell = GetValidSboMatchOdd(sellTran.BuyMatchOdd);
                                if (sboMatchSell != null)
                                {
                                    var sellPrepareSbo = SboEn.PrepareBetBroker(sboMatchSell, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                    if (sellPrepareSbo != null)
                                    {
                                        UpdateWriteTextLog(string.Format("-----> Quet {0}-{1} {2}:{3} result {4}: {5}",
                                                                         sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                         sellTran.BuyMatchOdd.OddType, sellTran.BuyMatchOdd.Odd, sellTran.SellBetType, sellPrepareSbo.NewOdd), eLogTextType.LowLevel);

                                        if (IsValidOddPair(sellTran.BuyOdd, sellPrepareSbo.NewOdd))
                                        {
                                            foreach (var sellEngine in sellTran.BetSellEngine)
                                            {
                                                var sellPrepare = sellEngine.PrepareBetBroker(sellTran.BuyMatchOdd, sellTran.SellBetType, sellTran.BuyMatchOdd.Odd);
                                                if (sellPrepare != null && IsValidOddPair(sellTran.BuyOdd, sellPrepare.NewOdd))
                                                {
                                                    int sellPoint = ConvertMoneyToPoint(sellTran.SellMoneyAverage, sellEngine.ExchangeRate);
                                                    if (sellPoint > sellPrepare.MaxBet)
                                                    {
                                                        sellPoint = sellPrepare.MaxBet;
                                                    }

                                                    sellPoint = GetGoodPoint(sellPoint);

                                                    if (sellEngine.ConfirmBetBroker(sellPoint))
                                                    {
                                                        sellTran.SumMoneyBuy -= ConvertPointToMoney(sellPoint, sellEngine.ExchangeRate);
                                                        UpdateWriteTextLog(string.Format("BÁN [{6}]: {0}-{1} {2}:{3} PICK {4}: {5}  **stake: {7}",
                                                                                         sellTran.BuyMatchOdd.HomeTeamName, sellTran.BuyMatchOdd.AwayTeamName,
                                                                                         sellTran.BuyMatchOdd.OddType, sellTran.BuyMatchOdd.Odd, sellTran.SellBetType, sellPrepareSbo.NewOdd, sellEngine.UserName, sellPoint), eLogTextType.Warning, eBrokerStatus.Bet);

                                                        lock (LockSellTrans)
                                                        {
                                                            sellTran.SellTimer   = new System.Threading.Timer(SellCallBack, sellTran, WaitSellTimes[R.Next(WaitSellTimes.Count)], 60000);
                                                            sellTran.FinishCheck = true;
                                                            sellTran.SellSuccessCount++;
                                                            SellTrans.Add(sellTran);
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            continue;
                                        }
                                    }
                                }
                            }
                        }

                        SellMatchs.RemoveAll(sm => sm.FinishCheck);
                    }
                }

                lock (LockSellTrans)
                {
                    SellTrans.RemoveAll(sm => sm.FinishTransaction);
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal("IbetEnOnUpdateLiveDataChange func", ex);
            }
        }