Exemplo n.º 1
0
        private bool CallConfirmBet(PrepareBetDTO prepareBet, int stake, float oddDef, out string ibetMsg,
                                    bool isLive            = false, bool betAgainst = false,
                                    eServerScan serverScan = eServerScan.Local, bool callSecondIbet = false)
        {
            ibetMsg = null;
            switch (prepareBet.MatchOdd.ServerType)
            {
            case eServerType.Ibet:
                return(IbetEngine.ConfirmBet(stake, out ibetMsg, betAgainst, serverScan));

            case eServerType.Sbo:
                return(SboEngine.ConfirmBet(stake, oddDef, isLive, serverScan));

            default:
                throw new Exception("CallConfirmBet => FAIL : Unknow prepareBet->MatchOdd->eServerType param");
            }
        }
Exemplo n.º 2
0
        private void FireLogScan(MatchPiDTO piMatchOdd, OddDTO piOdd, MatchIsnDTO isnMatch, OddDTO isnOdd, eServerScan serverScan)
        {
            var msg = new LogScanMessage()
            {
                ProcessorName   = this.ProcessorName,
                Time            = DateTime.Now.ToString("HH:mm:ss.fff"),
                HomeTeamName    = piMatchOdd.HomeTeamName,
                AwayTeamName    = piMatchOdd.AwayTeamName,
                OddType         = piOdd.OddType,
                Odd             = piOdd.Odd,
                FirstOddValues  = piOdd.HomeOdd + " | " + piOdd.AwayOdd,
                SecondOddValues = isnOdd.HomeOdd + " | " + isnOdd.AwayOdd,
                ServerScan      = serverScan
            };

            Task.Run(() =>
            {
                DataContainer.LogScanQueue.Enqueue(msg);
                DataContainer.LogScanResetEvent.Set();
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Mr Kiệt version
        /// </summary>
        /// <param name="piMatch"></param>
        /// <param name="piOdd"></param>
        /// <param name="piBetType"></param>
        /// <param name="isnMatch"></param>
        /// <param name="isnOdd"></param>
        /// <param name="isnBetType"></param>
        /// <param name="isLive"></param>
        /// <param name="serverScan"></param>
        /// <returns></returns>
        public bool ProcessPrepareBet(MatchPiDTO piMatch, OddDTO piOdd, eBetType piBetType, MatchIsnDTO isnMatch, OddDTO isnOdd, eBetType isnBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local)
        {
            if (isProcess)
            {
                return(false);
            }

            try
            {
                isProcess = true;


                Task <int> taskMaxBet = Task.Run(() => IsnEngine.GetMax((isnBetType == eBetType.Home ? isnOdd.selectionIdHome : isnOdd.selectionIdAway)));

                var taskpreparePina = Task.Run(() => PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd));


                var prepareBetIsn = IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, isLive, isnOdd.Odd);
                if (taskpreparePina.Result == null || prepareBetIsn == null)
                {
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                    return(false);
                }

                bool  betAny;
                float piOddValue = piBetType == eBetType.Home ? piOdd.HomeOdd : piOdd.AwayOdd;
                bool  isGood     = IsGoodOddPair(piOddValue, prepareBetIsn.NewOdd, CompareValueDifferent, out betAny);

                if (isGood)
                {
                    int piStake;
                    int isnStake;

                    if (CaculateStake(BetStakeType,
                                      piMatch.MatchID, 150, (int)((PendingTicket)taskpreparePina.Result.PendingTicket).TicketItem.MaxRiskAmount,
                                      isnMatch.MatchID, 4, taskMaxBet,
                                      out piStake, out isnStake))
                    {
                        // bet kèo dưới trước
                        #region [Bet pina trước nếu là kèo dưới]
                        if (((piOdd.OddType == eOddType.HCP || piOdd.OddType == eOddType.HalfHCP) && piOdd.Odd >= 0) ||// odd dương là được chấp
                            ((piOdd.OddType == eOddType.OU || piOdd.OddType == eOddType.HalfOU) && piBetType == eBetType.Away))   // dựa vào pina bet type để biết là Under
                        {
                            var piConfirmBet = PiEngine.ConfirmBet((PendingTicket)taskpreparePina.Result.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success);

                            if (piConfirmBet)
                            {
                                if (IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.Success))
                                {
                                    Task.Run(
                                        () =>
                                    {
                                        UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake);
                                        UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake);
                                    });
                                    Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    CountBet++;
                                    LastBetTime = DateTime.Now;
                                    return(true);
                                }
                                else
                                {
                                    Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                                    bool ok = false;
                                    for (int i = 0; i < IsnEngine.Rebet; i++)
                                    {
                                        var prepare = IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, true, isnOdd.Odd);
                                        if (prepare != null)
                                        {
                                            ok = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.MissOddIsn, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;

                                                Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));
                                                return(true);
                                            }
                                        }
                                        Thread.Sleep(500);
                                    }

                                    if (!ok) // ReBet pina
                                    {
                                        var betTypeAgaint = GetAgainstBetType(piBetType);
                                        var prepare       = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, piOdd.Odd);
                                        if (prepare != null)
                                        {
                                            ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                return(true);
                                            }
                                        }
                                    }

                                    IsnEngine.FireLogBet(isnMatch, isnOdd, isnBetType, isnStake, eBetStatusType.Fail, eServerScan.Local);
                                }
                            }
                        }
                        #endregion
                        #region [Bet ISN trước nếu isn là kèo dưới]
                        else // OU
                        {
                            var isnConfirmBet = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.Success);
                            if (isnConfirmBet)
                            {
                                if (PiEngine.ConfirmBet((PendingTicket)taskpreparePina.Result.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success))
                                {
                                    Task.Run(
                                        () =>
                                    {
                                        UpdateBetPool(
                                            eServerType.Isn,
                                            isnMatch.MatchID,
                                            IsnBetPool,
                                            isnStake);

                                        UpdateBetPool(
                                            eServerType.Pina,
                                            piMatch.MatchID,
                                            PiBetPool,
                                            piStake);
                                    });
                                    Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    CountBet++;
                                    LastBetTime = DateTime.Now;
                                    return(true);
                                }
                                else
                                {
                                    Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));

                                    bool ok = false;
                                    for (int i = 0; i < PiEngine.Rebet; i++)
                                    {
                                        var prepare = PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd);
                                        if (prepare != null)
                                        {
                                            ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.MissOddPina, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;

                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                                                return(true);
                                            }
                                        }
                                        Thread.Sleep(500);
                                    }

                                    if (!ok)// Rebet Isn
                                    {
                                        var betTypeAgaint = GetAgainstBetType(isnBetType);
                                        var prepare       = IsnEngine.PrepareBet(isnMatch, isnOdd, betTypeAgaint, true, isnOdd.Odd);
                                        if (prepare != null)
                                        {
                                            ok = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, betTypeAgaint, eBetStatusType.BetAgainIsn, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));
                                                return(true);
                                            }
                                        }
                                    }

                                    PiEngine.FireLogBet(piMatch, piOdd, piBetType, piStake, eBetStatusType.Fail, eServerScan.Local);
                                }
                            }
                        }
                        #endregion



                        // tạm đóng
                        FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                    }
                }
                else
                {
                    // tạm đóng
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                isProcess = false;
            }
        }
Exemplo n.º 4
0
        public bool ProcessPrepareBet(MatchOddDTO ibetMatchOdd, eBetType ibetBetType, MatchOddDTO sboMatchOdd, eBetType sboBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local, bool callSecond = false, string bpMatch = "", PrepareBetDTO sboPrepareBet = null)
        {
            if (isProcess && !callSecond) // || LastProcessPrepare.AddMilliseconds(200) > DateTime.Now
            {
                return(false);
            }

            try
            {
                isProcess = true;
                PrepareBetDTO ibetPrepareBet;
                if (!callSecond)
                {
                    sboMatchOdd.OldOdd = sboBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;

                    var taskPrepareBetSbo =
                        Task.Run(() => CallPrepareBet(sboMatchOdd, sboBetType, isLive, ibetMatchOdd.Odd));
                    ibetPrepareBet = CallPrepareBet(ibetMatchOdd, ibetBetType, isLive, sboMatchOdd.Odd);

                    if (!ibetPrepareBet.IsSuccess || taskPrepareBetSbo.Result == null)
                    {
                        return(false);
                    }

                    sboPrepareBet = taskPrepareBetSbo.Result;
                }
                else
                {
                    Logger.Warn("BAT DAU PREPARE LAN 2");
                    ibetPrepareBet = CallPrepareIbetAgain(ibetMatchOdd, ibetBetType, isLive, sboMatchOdd.Odd, bpMatch);
                    if (!ibetPrepareBet.IsSuccess)
                    {
                        return(false);
                    }
                }


                //sboMatchOdd.OldOdd = sboBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;

                //var taskPrepareBetSbo =
                //    Task.Run(() => CallPrepareBet(sboMatchOdd, sboBetType, isLive, ibetMatchOdd.Odd));
                //PrepareBetDTO ibetPrepareBet = CallPrepareBet(ibetMatchOdd, ibetBetType, isLive, sboMatchOdd.Odd);

                //if (!ibetPrepareBet.IsSuccess || taskPrepareBetSbo.Result == null)
                //{
                //    return false;
                //}
                //PrepareBetDTO sboPrepareBet = taskPrepareBetSbo.Result;

                if (ibetPrepareBet.IsRunning)
                {
                    bool isGood = IsGoodOddPair(ibetPrepareBet.NewOdd, sboPrepareBet.NewOdd, CompareValueDifferent);

                    if (isGood)
                    {
                        int ibetStake;
                        int sboStake;

                        if (CaculateStake(BetStakeType,
                                          ibetPrepareBet.MatchOdd.MatchID,
                                          ibetPrepareBet.MinBet,
                                          ibetPrepareBet.MaxBet,
                                          sboPrepareBet.MatchOdd.MatchID,
                                          sboPrepareBet.MinBet,
                                          sboPrepareBet.MaxBet,
                                          out ibetStake, out sboStake))
                        {
                            string ibetConfirmMsg;

                            if (CallConfirmBet(ibetPrepareBet, ibetStake, sboMatchOdd.Odd, out ibetConfirmMsg, isLive, false, serverScan, callSecond))
                            {
                                LastBetIbetSuccess = DateTime.Now;

                                if (CallConfirmBet(sboPrepareBet, sboStake, ibetMatchOdd.Odd, out ibetConfirmMsg, isLive, false, serverScan))
                                {
                                    Task.Run(
                                        () =>
                                    {
                                        UpdateBetPool(
                                            sboPrepareBet.MatchOdd.ServerType,
                                            sboPrepareBet.MatchOdd.MatchID,
                                            SboBetPool, sboStake);
                                        UpdateBetPool(
                                            ibetPrepareBet.MatchOdd.ServerType,
                                            ibetPrepareBet.MatchOdd.MatchID,
                                            IbetBetPool,
                                            ibetStake);
                                    });
                                    Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    CountBet++;
                                    LastBetTime = DateTime.Now;
                                    return(true);
                                }
                                else
                                {
                                    if (BetAgainstIbet)
                                    {
                                        Logger.Info(ProcessorName + " DAT NGUOC IBET<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

                                        if (!BetAgainstIbetRequest(ibetPrepareBet, ibetMatchOdd, ibetBetType,
                                                                   isLive, sboMatchOdd.Odd, ibetStake, false))
                                        {
                                            Thread.Sleep(3000);
                                            Logger.Info("CALL LAN 2 BET MGUOC IBET<<<<<<<<<<<<<<<<");
                                            if (BetAgainstIbetRequest(ibetPrepareBet, ibetMatchOdd, ibetBetType,
                                                                      isLive, sboMatchOdd.Odd, ibetStake, true))
                                            {
                                                isProcess = false;
                                                return(true);
                                            }
                                            else
                                            {
                                                Logger.Info("DAT NGUOC THAT BAI, KHOI DONG LAI IBET!!!");
                                                IbetEngine.BetAgainstTransactions.Add(new BetAgainstTransaction()
                                                {
                                                    BetType    = GetAgainstBetType(ibetBetType),
                                                    IsLive     = isLive,
                                                    MatchOdd   = ibetMatchOdd,
                                                    OddCompare = sboMatchOdd.Odd,
                                                    Stake      = ibetStake,
                                                    HomeScore  = ibetPrepareBet.HomeScore,
                                                    AwayScore  = ibetPrepareBet.AwayScore
                                                });

                                                Task.Run(() =>
                                                {
                                                    Logger.Info("CALL KHOI DONG LAI IBET!!!");
                                                    IbetEngine.UpdateException(IbetEngine, eExceptionType.LoginFail);
                                                });
                                            }
                                        }
                                        else
                                        {
                                            isProcess = false;
                                            return(true);
                                        }

                                        Logger.Info("BET MGUOC IBET FAIL...DAT NGUOC THAT BAI...");
                                    }
                                }

                                LastBetTime = DateTime.Now;

                                Task.Run(
                                    () =>
                                    UpdateBetPool(ibetPrepareBet.MatchOdd.ServerType,
                                                  ibetPrepareBet.MatchOdd.MatchID, IbetBetPool,
                                                  ibetStake));
                                return(true);
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(ibetConfirmMsg))
                                {
                                    string bpValue = GetBpMatchIbet(ibetConfirmMsg);
                                    Logger.Info("GOI COMPARE LAI LAN 2, bp_match: " + bpValue);
                                    return(ProcessPrepareBet(ibetMatchOdd, ibetBetType, sboMatchOdd, sboBetType,
                                                             isLive,
                                                             serverScan, true, bpValue, sboPrepareBet));
                                }
                            }

                            FireLogScan(ibetMatchOdd, sboMatchOdd, serverScan);
                        }
                    }
                    else
                    {
                        FireLogScan(ibetMatchOdd, sboMatchOdd, serverScan);
                    }
                }
                else
                {
                    FireLogScan(ibetMatchOdd, sboMatchOdd, serverScan);
                }
                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                //LastProcessPrepare = DateTime.Now;
                isProcess = false;
            }
        }
Exemplo n.º 5
0
        public bool ProcessPrepareBet(MatchPiDTO piMatchOdd, OddDTO piOdd, eBetType piBetType, MatchOddDTO sboMatchOdd, eBetType sboBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local)
        {
            if (isProcess)
            {
                return(false);
            }
            string oddCheck = sboMatchOdd.OddID + sboMatchOdd.HomeOdd + sboMatchOdd.AwayOdd + piOdd.HomeOdd +
                              piOdd.AwayOdd;

            if (oddCheck.Equals(OddCheck))
            {
                return(false);
            }

            OddCheck = oddCheck;

            try
            {
                isProcess = true;

                sboMatchOdd.OldOdd = sboBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;

                var prepareBetSbo = CallPrepareBet(sboMatchOdd, sboBetType, isLive, piOdd.PiOdd);

                if (prepareBetSbo == null)
                {
                    return(false);
                }

                bool  betAny;
                float piOddValue = piBetType == eBetType.Home ? piOdd.HomeOdd : piOdd.AwayOdd;
                bool  isGood     = IsGoodOddPair(piOddValue, prepareBetSbo.NewOdd, CompareValueDifferent, out betAny);

                if (isGood)
                {
                    int piStake;
                    int sboStake;

                    if (CaculateStake(BetStakeType,
                                      piMatchOdd.MatchID,
                                      150,
                                      (int)piOdd.max.Value,
                                      prepareBetSbo.MatchOdd.MatchID,
                                      prepareBetSbo.MinBet,
                                      prepareBetSbo.MaxBet,
                                      out piStake, out sboStake))
                    {
                        var piConfirmBet = PiEngine.ConfirmBet(piStake, piMatchOdd, piOdd, piBetType);

                        if (piConfirmBet)
                        {
                            if (SboEngine.ConfirmBet(sboStake, piOdd.PiOdd, isLive, serverScan, piMatchOdd.HomeTeamName, piMatchOdd.AwayTeamName))
                            {
                                Task.Run(
                                    () =>
                                {
                                    UpdateBetPool(
                                        prepareBetSbo.MatchOdd.ServerType,
                                        prepareBetSbo.MatchOdd.MatchID,
                                        SboBetPool, sboStake);
                                    UpdateBetPool(
                                        eServerType.Pina,
                                        piMatchOdd.MatchID,
                                        PiBetPool,
                                        piStake);
                                });
                                Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                CountBet++;
                                LastBetTime = DateTime.Now;
                                return(true);
                            }
                            else
                            {
                                if (BetAgainstIbet)
                                {
                                    Logger.Info(ProcessorName + " DAT NGUOC PINA<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
                                    var betTypeAgaint = GetAgainstBetType(piBetType);

                                    if (!PiEngine.TryConfirmBet(piStake, piMatchOdd, piOdd, betTypeAgaint))
                                    {
                                        Thread.Sleep(15000);
                                        Logger.Info("CALL LAN 2 BET MGUOC PINA<<<<<<<<<<<<<<<<");
                                        if (PiEngine.TryConfirmBet(piStake, piMatchOdd, piOdd, betTypeAgaint))
                                        {
                                            isProcess = false;
                                            return(true);
                                        }
                                        else
                                        {
                                            Logger.Info("CALL LAN 3 BET MGUOC LAI PINA<<<<<<<<<<<<<<<<");
                                            prepareBetSbo = CallPrepareBet(sboMatchOdd, sboBetType, isLive, piOdd.PiOdd);
                                            if (prepareBetSbo == null)
                                            {
                                                Logger.Fatal("CALL LAN 3 Prepare Sbo fail!!!!!");
                                                Thread.Sleep(25000);
                                                if (PiEngine.TryConfirmBet(piStake, piMatchOdd, piOdd, betTypeAgaint))
                                                {
                                                    isProcess = false;
                                                    return(true);
                                                }
                                            }
                                            else
                                            {
                                                if (!SboEngine.ConfirmBet(sboStake, piOdd.PiOdd, isLive, serverScan, piMatchOdd.HomeTeamName, piMatchOdd.AwayTeamName))
                                                {
                                                    Thread.Sleep(25000);
                                                    if (PiEngine.TryConfirmBet(piStake, piMatchOdd, piOdd, betTypeAgaint))
                                                    {
                                                        isProcess = false;
                                                        return(true);
                                                    }
                                                    else
                                                    {
                                                        prepareBetSbo = CallPrepareBet(sboMatchOdd, sboBetType, isLive, piOdd.PiOdd);
                                                        if (prepareBetSbo == null)
                                                        {
                                                            Logger.Fatal("CALL LAN 4 Prepare Sbo fail!!!!!");
                                                            Thread.Sleep(25000);
                                                            PiEngine.TryConfirmBet(piStake, piMatchOdd, piOdd,
                                                                                   betTypeAgaint);
                                                        }
                                                        else
                                                        {
                                                            SboEngine.ConfirmBet(sboStake, piOdd.PiOdd, isLive, serverScan, piMatchOdd.HomeTeamName, piMatchOdd.AwayTeamName);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    isProcess = false;
                                                    return(true);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        isProcess = false;
                                        return(true);
                                    }

                                    Logger.Info("BET MGUOC IBET FAIL...DAT NGUOC THAT BAI...");
                                }
                            }

                            LastBetTime = DateTime.Now;

                            Task.Run(
                                () =>
                                UpdateBetPool(eServerType.Pina, piMatchOdd.MatchID, PiBetPool, piStake));

                            return(true);
                        }

                        FireLogScan(piMatchOdd, piOdd, sboMatchOdd, serverScan);
                    }
                }
                else
                {
                    FireLogScan(piMatchOdd, piOdd, sboMatchOdd, serverScan);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                isProcess = false;
            }
        }
Exemplo n.º 6
0
        public void FireLogBet(MatchDTO match, OddDTO odd, eBetType betType, int stake, eBetStatusType betStatus, eServerScan serverScan)
        {
            var msg = new LogBetMessage()
            {
                Time         = DateTime.Now.ToString("HH:mm:ss.fff"),
                HomeTeamName = match.HomeTeamName,
                AwayTeamName = match.AwayTeamName,
                OddType      = odd.OddType,
                ServerType   = match.ServerType,
                OddValues    = odd.HomeOdd + "|" + odd.AwayOdd,
                Odd          = odd.Odd,
                BetStake     = stake,
                BetType      = betType,
                Status       = betStatus,
                EngineName   = this.EngineName,
                TabCode      = TabCode,
                ServerScan   = serverScan
            };

            Task.Run(() =>
            {
                DataContainer.LogBetQueue.Enqueue(msg);
                DataContainer.LogBetResetEvent.Set();
            });
        }
Exemplo n.º 7
0
        public bool ProcessPrepareBet(MatchPiDTO piMatch, OddDTO piOdd, eBetType piBetType, MatchOddDTO sboMatchOdd, eBetType sboBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local)
        {
            if (isProcess)
            {
                return(false);
            }

            try
            {
                isProcess = true;

                sboMatchOdd.OldOdd = sboBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;

                var prepareBetPina = Task.Run(() => PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd));


                var prepareBetSbo = CallPrepareBet(sboMatchOdd, sboBetType, isLive, piOdd.PiOdd);

                if (prepareBetSbo == null || prepareBetPina.Result == null)
                {
                    FireLogScan(piMatch, piOdd, sboMatchOdd, serverScan);

                    return(false);
                }

                float piOddValue = piBetType == eBetType.Home ? piOdd.HomeOdd : piOdd.AwayOdd;
                bool  isGood     = IsGoodOddPair(piOddValue, prepareBetSbo.NewOdd, CompareValueDifferent);

                if (isGood)
                {
                    float firstOdd = piOdd.Odd;
                    int   piStake;
                    int   sboStake;

                    if (CaculateStake(BetStakeType,
                                      piMatch.MatchID,
                                      150,
                                      (int)((PendingTicket)prepareBetPina.Result.PendingTicket).TicketItem.MaxRiskAmount,
                                      prepareBetSbo.MatchOdd.MatchID,
                                      prepareBetSbo.MinBet,
                                      prepareBetSbo.MaxBet,
                                      out piStake, out sboStake))
                    {
                        var piConfirmBet = PiEngine.ConfirmBet((PendingTicket)prepareBetPina.Result.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success);

                        if (piConfirmBet)
                        {
                            if (SboEngine.ConfirmBet(sboStake, piOdd.PiOdd, isLive, serverScan, piMatch.HomeTeamName, piMatch.AwayTeamName))
                            {
                                Task.Run(
                                    () =>
                                {
                                    UpdateBetPool(
                                        prepareBetSbo.MatchOdd.ServerType,
                                        prepareBetSbo.MatchOdd.MatchID,
                                        SboBetPool, sboStake);
                                    UpdateBetPool(
                                        eServerType.Pina,
                                        piMatch.MatchID,
                                        PiBetPool,
                                        piStake);
                                });
                                Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                CountBet++;
                                LastBetTime = DateTime.Now;
                                return(true);
                            }
                            else
                            {
                                if (BetAgainstIbet)
                                {
                                    var betTypeAgaint = GetAgainstBetType(piBetType);

                                    for (int i = 0; i < SboEngine.Rebet; i++)
                                    {
                                        var prepare = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, firstOdd);
                                        if (prepare != null)
                                        {
                                            var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainstIbet, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                return(true);
                                            }
                                        }
                                        Thread.Sleep(1000);

                                        lock (PiEngine.LockLive)
                                        {
                                            var newPiMatch = PiEngine._matchs.FirstOrDefault(p => p.MatchID == piMatch.MatchID);
                                            if (newPiMatch != null)
                                            {
                                                var newPiOdd = newPiMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == piOdd.OddType);
                                                if (newPiOdd != null)
                                                {
                                                    prepare = PiEngine.PrepareBet(newPiMatch, newPiOdd, betTypeAgaint, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, newPiMatch, newPiOdd, betTypeAgaint, eBetStatusType.BetAgainstIbet, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }



                                        Thread.Sleep(1000);
                                    }

                                    Thread.Sleep(60000);

                                    for (int i = 0; i < SboEngine.Rebet * 2; i++)
                                    {
                                        var prepare = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, firstOdd);
                                        if (prepare != null)
                                        {
                                            var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainstIbet, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                return(true);
                                            }
                                        }
                                        Thread.Sleep(10000);

                                        lock (PiEngine.LockLive)
                                        {
                                            var newPiMatch = PiEngine._matchs.FirstOrDefault(p => p.MatchID == piMatch.MatchID);
                                            if (newPiMatch != null)
                                            {
                                                var newPiOdd = newPiMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == piOdd.OddType);
                                                if (newPiOdd != null)
                                                {
                                                    prepare = PiEngine.PrepareBet(newPiMatch, newPiOdd, betTypeAgaint, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, newPiMatch, newPiOdd, betTypeAgaint, eBetStatusType.BetAgainstIbet, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        Thread.Sleep(1000);
                                    }

                                    Logger.Info("BET MGUOC IBET FAIL...DAT NGUOC THAT BAI...");
                                }
                            }

                            LastBetTime = DateTime.Now;

                            Task.Run(
                                () =>
                                UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                            return(true);
                        }

                        FireLogScan(piMatch, piOdd, sboMatchOdd, serverScan);
                    }
                }
                else
                {
                    FireLogScan(piMatch, piOdd, sboMatchOdd, serverScan);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                isProcess = false;
            }
        }
Exemplo n.º 8
0
        public bool ProcessPrepareBet(MatchPiDTO piMatch, OddDTO piOdd, eBetType piBetType, MatchIsnDTO isnMatch, OddDTO isnOdd, eBetType isnBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local)
        {
            if (isProcess)
            {
                return(false);
            }

            //what?
            //string oddCheck = sboMatchOdd.OddID + sboMatchOdd.HomeOdd + sboMatchOdd.AwayOdd + piOdd.HomeOdd +
            //                  piOdd.AwayOdd;

            //if (oddCheck.Equals(OddCheck))
            //{
            //    return false;
            //}

            //OddCheck = oddCheck;

            try
            {
                isProcess = true;

                // wwhat?
                //sboMatchOdd.OldOdd = piBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;
                //   Logger.Debug("");
                //  Logger.Debug("Before call PREPARE ISN " + piMatch.HomeTeamName + "-" + piMatch.AwayTeamName + " " + piOdd.HomeOdd + "_" + piOdd.AwayOdd + " " + piBetType.ToString());
                //Stopwatch a = new Stopwatch();
                //a.Start();

                Task <int> taskMaxBet = Task.Run(() => IsnEngine.GetMax((isnBetType == eBetType.Home ? isnOdd.selectionIdHome : isnOdd.selectionIdAway)));

                Task <PrepareBetDTO> preparePina = null;
                Task <PrepareBetDTO> prepareIsn  = null;

                if ((isnOdd.OddType == eOddType.OU || isnOdd.OddType == eOddType.HalfOU) && isnBetType == eBetType.Away)
                {
                    preparePina = Task.Run(() => PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd));

                    prepareIsn = Task.Run(() => IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, isLive, isnOdd.Odd));
                }
                else
                {
                    prepareIsn = Task.Run(() => IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, isLive, isnOdd.Odd));

                    preparePina = Task.Run(() => PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd));
                }

                if (preparePina.Result == null || prepareIsn.Result == null)
                {
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);

                    return(false);
                }

                //a.Stop();
                //Debug.WriteLine("Thoi gian prepare: " + a.ElapsedMilliseconds);

                //   float piOddValue = piBetType == eBetType.Home ? piOdd.HomeOdd : piOdd.AwayOdd;
                //bool isGood = IsGoodOddPair(piOddValue, prepareBetIsn.NewOdd, CompareValueDifferent, out betAny);
                bool isGood = IsGoodOddPair(preparePina.Result.NewOdd, prepareIsn.Result.NewOdd, CompareValueDifferent);
                // Logger.Debug("After isGood=" + isGood.ToString() + " " + piOddValue + "_" + prepareBetIsn.NewOdd + " " + piBetType.ToString());

                if (isGood)
                {
                    float firstOdd = piOdd.Odd;

                    int piStake;
                    int isnStake;

                    if (CaculateStake(BetStakeType,
                                      piMatch.MatchID, 300, (int)((PendingTicket)preparePina.Result.PendingTicket).TicketItem.MaxRiskAmount,
                                      isnMatch.MatchID, 4, taskMaxBet,
                                      out piStake, out isnStake))
                    // if (true)
                    {
                        //if (piStake<(int)((PendingTicket)preparePina.Result.PendingTicket).TicketItem.MinRiskAmount)
                        //{
                        //    Logger.Info("Pi lower than riskamout");
                        //    return false;
                        //}
                        // kèo xỉu isn đnáh trước
                        if ((isnOdd.OddType == eOddType.OU || isnOdd.OddType == eOddType.HalfOU) && isnBetType == eBetType.Away)
                        {
                            var isnConfirmBet = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.Success);
                            if (isnConfirmBet)
                            {
                                if (PiEngine.ConfirmBet2((PendingTicket)preparePina.Result.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success))
                                {
                                    Task.Run(
                                        () =>
                                    {
                                        UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake);
                                        UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake);
                                    });
                                    Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    CountBet++;
                                    LastBetTime = DateTime.Now;
                                    return(true);
                                }
                                else
                                {
                                    Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));
                                    var betTypeAgaint = GetAgainstBetType(isnBetType);

                                    for (int i = 0; i < PiEngine.Rebet; i++)
                                    {
                                        lock (IsnEngine.LockLive)
                                        {
                                            var newIsnMatch = IsnEngine._matchs.FirstOrDefault(p => p.MatchID == isnMatch.MatchID);
                                            if (newIsnMatch != null)
                                            {
                                                var newIsnOdd = newIsnMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == isnOdd.OddType);
                                                if (newIsnOdd != null)
                                                {
                                                    var prepare = IsnEngine.PrepareBet(newIsnMatch, newIsnOdd, betTypeAgaint, true, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = IsnEngine.ConfirmBet2(isnStake, newIsnMatch, newIsnOdd, betTypeAgaint, eBetStatusType.BetAgainIsn, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Isn, newIsnMatch.MatchID, IsnBetPool, isnStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }


                                        Thread.Sleep(2000);
                                    }



                                    IsnEngine.FireLogBet(isnMatch, isnOdd, isnBetType, isnStake, eBetStatusType.Fail, eServerScan.Local);
                                }
                            }
                        }
                        else
                        {
                            var piConfirmBet = PiEngine.ConfirmBet((PendingTicket)preparePina.Result.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success);

                            if (piConfirmBet)
                            {
                                if (IsnEngine.ConfirmBet(isnStake, isnMatch, isnOdd, isnBetType))
                                {
                                    Task.Run(
                                        () =>
                                    {
                                        UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake);
                                        UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake);
                                    });
                                    Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                                    CountBet++;
                                    LastBetTime = DateTime.Now;
                                    return(true);
                                }
                                else if (BetAgainstIbet)
                                {
                                    var betTypeAgaint = GetAgainstBetType(piBetType);

                                    for (int i = 0; i < IsnEngine.Rebet; i++)
                                    {
                                        var prepare = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, firstOdd);
                                        if (prepare != null)
                                        {
                                            var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                return(true);
                                            }
                                        }

                                        Thread.Sleep(1000);

                                        lock (PiEngine.LockLive)
                                        {
                                            var newPiMatch = PiEngine._matchs.FirstOrDefault(p => p.MatchID == piMatch.MatchID);
                                            if (newPiMatch != null)
                                            {
                                                var newPiOdd = newPiMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == piOdd.OddType);
                                                if (newPiOdd != null)
                                                {
                                                    prepare = PiEngine.PrepareBet(newPiMatch, newPiOdd, betTypeAgaint, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, newPiMatch, newPiOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        Thread.Sleep(1000);

                                        lock (IsnEngine.LockLive)
                                        {
                                            var newIsnMatch = IsnEngine._matchs.FirstOrDefault(p => p.MatchID == isnMatch.MatchID);
                                            if (newIsnMatch != null)
                                            {
                                                var newIsnOdd = newIsnMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == isnOdd.OddType);
                                                if (newIsnOdd != null)
                                                {
                                                    prepare = IsnEngine.PrepareBet(newIsnMatch, newIsnOdd, isnBetType, true, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = IsnEngine.ConfirmBet2(isnStake, newIsnMatch, newIsnOdd, isnBetType, eBetStatusType.MissOddIsn, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Isn, newIsnMatch.MatchID, IsnBetPool, isnStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        Thread.Sleep(1000);
                                    }

                                    Thread.Sleep(60000);

                                    for (int i = 0; i < IsnEngine.Rebet * 2; i++)
                                    {
                                        var prepare = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, firstOdd);
                                        if (prepare != null)
                                        {
                                            var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                            if (ok)
                                            {
                                                LastBetTime = DateTime.Now;
                                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                return(true);
                                            }
                                        }

                                        Thread.Sleep(10000);

                                        lock (PiEngine.LockLive)
                                        {
                                            var newPiMatch = PiEngine._matchs.FirstOrDefault(p => p.MatchID == piMatch.MatchID);
                                            if (newPiMatch != null)
                                            {
                                                var newPiOdd = newPiMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == piOdd.OddType);
                                                if (newPiOdd != null)
                                                {
                                                    prepare = PiEngine.PrepareBet(newPiMatch, newPiOdd, betTypeAgaint, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, newPiMatch, newPiOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }


                                        Thread.Sleep(10000);

                                        lock (IsnEngine.LockLive)
                                        {
                                            var newIsnMatch = IsnEngine._matchs.FirstOrDefault(p => p.MatchID == isnMatch.MatchID);
                                            if (newIsnMatch != null)
                                            {
                                                var newIsnOdd = newIsnMatch.Odds.FirstOrDefault(p => p.Odd == firstOdd && p.OddType == isnOdd.OddType);
                                                if (newIsnOdd != null)
                                                {
                                                    prepare = IsnEngine.PrepareBet(newIsnMatch, newIsnOdd, betTypeAgaint, true, firstOdd);
                                                    if (prepare != null)
                                                    {
                                                        var ok = IsnEngine.ConfirmBet2(isnStake, newIsnMatch, newIsnOdd, betTypeAgaint, eBetStatusType.MissOddIsn, true);
                                                        if (ok)
                                                        {
                                                            LastBetTime = DateTime.Now;
                                                            Task.Run(() => UpdateBetPool(eServerType.Isn, newIsnMatch.MatchID, IsnBetPool, isnStake));
                                                            return(true);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        Thread.Sleep(10000);
                                    }
                                }

                                LastBetTime = DateTime.Now;

                                Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                                return(true);
                            }
                        }
                        // tạm đóng
                        FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                    }
                }
                else
                {
                    // tạm đóng
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                }

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                isProcess = false;
            }
        }
Exemplo n.º 9
0
        public bool ProcessPrepareBet(MatchPiDTO piMatch, OddDTO piOdd, eBetType piBetType, MatchIsnDTO isnMatch, OddDTO isnOdd, eBetType isnBetType, bool isLive,
                                      eServerScan serverScan = eServerScan.Local)
        {
            if (isProcess)
            {
                return(false);
            }

            //what?
            //string oddCheck = sboMatchOdd.OddID + sboMatchOdd.HomeOdd + sboMatchOdd.AwayOdd + piOdd.HomeOdd +
            //                  piOdd.AwayOdd;

            //if (oddCheck.Equals(OddCheck))
            //{
            //    return false;
            //}

            //OddCheck = oddCheck;

            try
            {
                isProcess = true;

                // wwhat?
                //sboMatchOdd.OldOdd = piBetType == eBetType.Home ? sboMatchOdd.HomeOdd : sboMatchOdd.AwayOdd;
                //   Logger.Debug("");
                //  Logger.Debug("Before call PREPARE ISN " + piMatch.HomeTeamName + "-" + piMatch.AwayTeamName + " " + piOdd.HomeOdd + "_" + piOdd.AwayOdd + " " + piBetType.ToString());
                Stopwatch a = new Stopwatch();
                a.Start();
                Task <int> taskMaxBet = Task.Run(() => IsnEngine.GetMax((isnBetType == eBetType.Home ? isnOdd.selectionIdHome : isnOdd.selectionIdAway)));

                var prepareBetIsn = Task.Run(() => IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, isLive, isnOdd.Odd));

                var preparePina = PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd);

                if (preparePina == null || prepareBetIsn.Result == null)
                {
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                    return(false);
                }

                a.Stop();
                Logger.Info("Total time prepare: " + a.ElapsedMilliseconds + " ms");
                // Debug.WriteLine("Thoi gian prepare: " + a.ElapsedMilliseconds);

                bool betAny;
                //   float piOddValue = piBetType == eBetType.Home ? piOdd.HomeOdd : piOdd.AwayOdd;
                //bool isGood = IsGoodOddPair(piOddValue, prepareBetIsn.NewOdd, CompareValueDifferent, out betAny);
                bool isGood = IsGoodOddPair(preparePina.NewOdd, prepareBetIsn.Result.NewOdd, CompareValueDifferent, out betAny);
                // Logger.Debug("After isGood=" + isGood.ToString() + " " + piOddValue + "_" + prepareBetIsn.NewOdd + " " + piBetType.ToString());

                if (isGood)
                {
                    int piStake;
                    int isnStake;

                    if (CaculateStake(BetStakeType,
                                      piMatch.MatchID, 150, (int)((PendingTicket)preparePina.PendingTicket).TicketItem.MaxRiskAmount,
                                      isnMatch.MatchID, 4, taskMaxBet,
                                      out piStake, out isnStake))
                    // if (true)
                    {
                        a.Restart();
                        Logger.Info("Total time prepare: " + a.ElapsedMilliseconds + " ms");

                        var taskpiConfirmBet = Task.Run(() => PiEngine.ConfirmBet((PendingTicket)preparePina.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.Success));
                        var betisnOk         = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.Success);
                        if (taskpiConfirmBet.Result == true && betisnOk == true)
                        {
                            a.Stop();
                            Logger.Info("Total time prepare: " + a.ElapsedMilliseconds + " ms");

                            Task.Run(
                                () =>
                            {
                                UpdateBetPool(
                                    eServerType.Isn,
                                    isnMatch.MatchID,
                                    IsnBetPool,
                                    isnStake);

                                UpdateBetPool(
                                    eServerType.Pina,
                                    piMatch.MatchID,
                                    PiBetPool,
                                    piStake);
                            });
                            Logger.Info("BET SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                            CountBet++;
                            LastBetTime = DateTime.Now;
                            return(true);
                        }
                        else if (taskpiConfirmBet.Result == false && betisnOk == false)
                        {
                            return(false);
                        }
                        else if (taskpiConfirmBet.Result == true)
                        {
                            Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                            bool ok = false;
                            for (int i = 0; i < IsnEngine.Rebet; i++)
                            {
                                var prepare = IsnEngine.PrepareBet(isnMatch, isnOdd, isnBetType, true, isnOdd.Odd);
                                if (prepare != null)
                                {
                                    ok = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, isnBetType, eBetStatusType.MissOddIsn, true);
                                    if (ok)
                                    {
                                        LastBetTime = DateTime.Now;

                                        Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));
                                        return(true);
                                    }
                                }
                                Thread.Sleep(500);
                            }

                            if (!ok) // ReBet pina
                            {
                                var betTypeAgaint = GetAgainstBetType(piBetType);
                                var prepare       = PiEngine.PrepareBet(piMatch, piOdd, betTypeAgaint, piOdd.Odd);
                                if (prepare != null)
                                {
                                    ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, betTypeAgaint, eBetStatusType.BetAgainPina, true);
                                    if (ok)
                                    {
                                        LastBetTime = DateTime.Now;
                                        Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));
                                        return(true);
                                    }
                                }
                            }

                            IsnEngine.FireLogBet(isnMatch, isnOdd, isnBetType, isnStake, eBetStatusType.Fail, eServerScan.Local);
                        }
                        else if (betisnOk == true)
                        {
                            Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));

                            bool ok = false;
                            for (int i = 0; i < PiEngine.Rebet; i++)
                            {
                                var prepare = PiEngine.PrepareBet(piMatch, piOdd, piBetType, piOdd.Odd);
                                if (prepare != null)
                                {
                                    ok = PiEngine.ConfirmBet((PendingTicket)prepare.PendingTicket, piStake, piMatch, piOdd, piBetType, eBetStatusType.MissOddPina, true);
                                    if (ok)
                                    {
                                        LastBetTime = DateTime.Now;

                                        Task.Run(() => UpdateBetPool(eServerType.Pina, piMatch.MatchID, PiBetPool, piStake));

                                        return(true);
                                    }
                                }
                                Thread.Sleep(500);
                            }

                            if (!ok)// Rebet Isn
                            {
                                var betTypeAgaint = GetAgainstBetType(isnBetType);
                                var prepare       = IsnEngine.PrepareBet(isnMatch, isnOdd, betTypeAgaint, true, isnOdd.Odd);
                                if (prepare != null)
                                {
                                    ok = IsnEngine.ConfirmBet2(isnStake, isnMatch, isnOdd, betTypeAgaint, eBetStatusType.BetAgainIsn, true);
                                    if (ok)
                                    {
                                        LastBetTime = DateTime.Now;
                                        Task.Run(() => UpdateBetPool(eServerType.Isn, isnMatch.MatchID, IsnBetPool, isnStake));
                                        return(true);
                                    }
                                }
                            }

                            PiEngine.FireLogBet(piMatch, piOdd, piBetType, piStake, eBetStatusType.Fail, eServerScan.Local);
                        }

                        return(false);
                    }

                    // tạm đóng
                    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                }
                //else
                //{
                //    // tạm đóng
                //    FireLogScan(piMatch, piOdd, isnMatch, isnOdd, serverScan);
                //}

                return(false);
            }
            catch (Exception ex)
            {
                Logger.Error(ProcessorName, ex);
                return(false);
            }
            finally
            {
                isProcess = false;
            }
        }