コード例 #1
0
ファイル: OlimpClient.cs プロジェクト: isdmitriev/Pinnacle
        public MoneyLine getMoneylineFoEvent(HtmlNode node, string eventId)
        {
            MoneyLine moneyLine = new MoneyLine();

            try
            {
                foreach (HtmlNode node2 in node.ChildNodes)
                {
                    if (node2.OriginalName == "div" && this.GetAtributeValueByName(node2, "id").StartsWith(eventId) == true)
                    {
                        var result = this._htmlOddsParse.GetLineThree(node2.ChildNodes[1]);

                        moneyLine.Home = result.k1;
                        moneyLine.Draw = result.k2;
                        moneyLine.Away = result.k3;
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(moneyLine);
        }
コード例 #2
0
        private void SetMoneyLinePricesToDatabase(MoneyLine moneyLine)
        {
            if (moneyLine != null)
            {
                this.pinaccle.HOME           = moneyLine.Home;
                this.pinaccle.AWAY           = moneyLine.Away;
                this.pinaccle.DRAW           = moneyLine.Draw;
                this.pinaccle.HOME_computed_ = moneyLine.HomeComputed;
                this.pinaccle.DRAW_computed_ = moneyLine.DrawCompute;
                this.pinaccle.AWAY_computed_ = moneyLine.AwayComputed;
                this.pinaccle.HOME_disc      = moneyLine.HomeDisc;
                this.pinaccle.AWAY_disc      = moneyLine.AwayDisc;
                this.pinaccle.DRAW_disc      = moneyLine.DrawDisc;

                //List<decimal?> discs = new List<decimal?>();

                //discs.Add(this.pinaccle.HOME_disc);
                //discs.Add(this.pinaccle.AWAY_disc);
                //discs.Add(this.pinaccle.DRAW_disc);
                //var result = MathClass.GetStatsForMarket(discs);

                //this.pinaccle.MoneyLine_disc_max = result.maxDisc;
                //this.pinaccle.MoneyLine_disc_average =decimal.Round((decimal)result.averageDisc,3);
                //this.pinaccle.MoneyLine_disc_mediana = MathClass.GetMedForMarket(discs);

                //this.eventDiscs.Add(moneyLine.HomeDisc);
                //this.eventDiscs.Add(moneyLine.DrawDisc);
                //this.eventDiscs.Add(moneyLine.AwayDisc);
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iteratorSport"></param>
        /// <returns></returns>
        private IMoneyLine MoneyLinePinnacleParse(XPathNodeIterator iteratorMoneyLine)
        {
            IMoneyLine     _moneyline           = new MoneyLine();
            XPathNavigator _choiceNameNavigator = iteratorMoneyLine.Current.Clone();

            _moneyline.AwayPrice = !string.IsNullOrEmpty(_choiceNameNavigator.SelectSingleNode("awayPrice").Value) ? float.Parse(_choiceNameNavigator.SelectSingleNode("awayPrice").Value) : 0;
            _moneyline.HomePrice = !string.IsNullOrEmpty(_choiceNameNavigator.SelectSingleNode("homePrice").Value) ? float.Parse(_choiceNameNavigator.SelectSingleNode("homePrice").Value) : 0;
            _moneyline.DrawPrice = !string.IsNullOrEmpty(_choiceNameNavigator.SelectSingleNode("drawPrice").Value) ? float.Parse(_choiceNameNavigator.SelectSingleNode("drawPrice").Value) : 0;
            return(_moneyline);
        }
コード例 #4
0
        /// <summary>
        /// Устанавливает вычисленные к-ты и расхождения для события на исходы:1X2
        /// </summary>
        /// <param name="prices"></param>
        /// <param name="oddEvent"></param>
        private static void SetMoneyLineComputedPrices(Dictionary <string, decimal> prices, OddEvent oddEvent)
        {
            MoneyLine moneyLine = oddEvent.Periods[0].MoneyLine;

            if (moneyLine != null)
            {
                decimal?margin = MathClass.GetMargin3(moneyLine.Home, moneyLine.Draw, moneyLine.Away);

                moneyLine.FairHome = (moneyLine.Home / (1 - margin));
                moneyLine.FairDraw = (moneyLine.Draw / (1 - margin));
                moneyLine.FairAway = (moneyLine.Away / (1 - margin));



                if (moneyLine != null)
                {
                    foreach (KeyValuePair <string, decimal> keyValuePair in prices)
                    {
                        decimal?price;
                        if (keyValuePair.Key.Equals("ML 1") == true)
                        {
                            price = keyValuePair.Value;
                            moneyLine.HomeComputed = price;
                            moneyLine.HomeDisc     = GetDiscByCoefs(moneyLine.FairHome, moneyLine.HomeComputed);
                        }

                        if (keyValuePair.Key.Equals("ML X") == true)
                        {
                            price = keyValuePair.Value;
                            moneyLine.DrawCompute = price;
                            moneyLine.DrawDisc    = GetDiscByCoefs(moneyLine.FairDraw, moneyLine.DrawCompute);
                        }

                        if (keyValuePair.Key.Equals("ML 2") == true)
                        {
                            price = keyValuePair.Value;
                            moneyLine.AwayComputed = price;
                            moneyLine.AwayDisc     = GetDiscByCoefs(moneyLine.FairAway, moneyLine.AwayComputed);
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: OlimpClient.cs プロジェクト: isdmitriev/Pinnacle
        public async Task <OlimpOddEvent> GetOddsByEventId(OlimpEvent olimpEvent)
        {
            string   url          = "/en/sports/match/" + olimpEvent.EventId;
            HtmlNode documentNode = this.GetDocumentNodeByUrl(url);

            if (documentNode != null)
            {
                HtmlNode oddsContainer = documentNode.QuerySelector(".coef");

                MoneyLine       moneyLine    = new MoneyLine();
                DoubleChance    doubleChance = new DoubleChance();
                List <Total>    totals       = new List <Total>();
                List <Handicap> handicaps    = new List <Handicap>();

                List <Total> homeTotals = new List <Total>();
                List <Total> awayTotals = new List <Total>();

                OlimpOddEvent olimpOddEvent = new OlimpOddEvent();



                try
                {
                    foreach (HtmlNode node in oddsContainer.ChildNodes)
                    {
                        if (node.OriginalName == "div" && this.GetAtributeValueByName(node, "class") == "")
                        {
                            foreach (HtmlNode htmlNode in node.ChildNodes)
                            {
                                if (htmlNode.OriginalName == "div" && this.GetAtributeValueByName(htmlNode, "class") == "livelineheader")
                                {
                                    string type = this.GetMarketTypeByLiveheaderNode(htmlNode);

                                    if (type == "FULL TIME RESULT")

                                    {
                                        moneyLine = this.getMoneylineFoEvent(node, olimpEvent.EventId);
                                    }


                                    if (type == "DOUBLE CHANCE")
                                    {
                                        doubleChance = this.getDoubleChanceFoEvent(node, olimpEvent.EventId);
                                    }
                                    if (type == "TOTAL GOALS")
                                    {
                                        Total t = this.GetTotalForEvent(node, olimpEvent.EventId);
                                        if (t != null)
                                        {
                                            totals.Add(t);
                                        }
                                    }

                                    if (type == "ALTERNATIVE TOTAL GOALS")
                                    {
                                        List <Total> totals2 = this.GetTotalGoals(node, olimpEvent.EventId);
                                        if (totals2 != null)
                                        {
                                            totals.AddRange(totals2);
                                        }
                                    }
                                    if (type == "HANDICAP RESULT")
                                    {
                                        Handicap h = this.GetHandicap(node, olimpEvent.EventId);
                                        if (h != null)
                                        {
                                            handicaps.Add(h);
                                        }
                                    }

                                    if (type == "ALTERNATIVE HANDICAP RESULT")
                                    {
                                        List <Handicap> hdps = this.GetHandicaps(node, olimpEvent.EventId);
                                        if (hdps != null)
                                        {
                                            handicaps.AddRange(hdps);
                                        }
                                    }


                                    if (type == "TEAM TOTAL")
                                    {
                                        var result = this.GetTeamTotals(node, olimpEvent);
                                        if (result.home != null)
                                        {
                                            awayTotals = result.away;
                                            homeTotals = result.home;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }



                olimpOddEvent.moneyLine    = moneyLine;
                olimpOddEvent.doubleChance = doubleChance;
                olimpOddEvent.Totals       = totals;
                olimpOddEvent.Handicaps    = handicaps;
                olimpOddEvent.AwayTotals   = awayTotals;
                olimpOddEvent.HomeTotals   = homeTotals;


                olimpOddEvent.EventId    = olimpEvent.EventId;
                olimpOddEvent.HomeTeam   = olimpEvent.HomeTeam;
                olimpOddEvent.AwayTeam   = olimpEvent.AwayTeam;
                olimpOddEvent.LeagueName = olimpEvent.LeagueName;
                olimpOddEvent.StartDate  = olimpEvent.StartDate;
                olimpOddEvent.DateAdded  = DateTime.Now.ToString();

                return(olimpOddEvent);
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private List <ISport> XMLParse1()
        {
            List <ISport> sport         = new List <ISport>();
            string        urlPathSport  = string.Empty;
            string        urlPathLeague = string.Empty;
            string        urlPathFeed   = string.Empty;

            urlPathSport = Constant.SourceXML.PINNACLESPORTSURL;
            if (urlPathSport.IndexOf("http://") > -1)
            {
                urlPathLeague = Constant.SourceXML.PINNACLELEAGUEURL;
                urlPathFeed   = Constant.SourceXML.PINNACLEFEEDURL;
            }
            else
            {
                string[] arrPlitUrl = urlPathSport.Split('_');
                string   timetick   = arrPlitUrl[2].Replace(".xml", "");
                urlPathLeague = arrPlitUrl[0] + "_league_{0}_" + timetick + ".xml";
                urlPathFeed   = arrPlitUrl[0] + "_feed_{0}_{1}_" + timetick + ".xml";
            }


            //sport
            XmlTextReader readerSport = new XmlTextReader(urlPathSport);

            // Skip non-significant whitespace
            readerSport.WhitespaceHandling = WhitespaceHandling.Significant;
            XPathDocument  doc = new XPathDocument(readerSport, XmlSpace.Preserve);
            XPathNavigator nav = doc.CreateNavigator();

            XPathExpression exprSport;

            exprSport = nav.Compile("/rsp/sports/sport");
            XPathNodeIterator iteratorSport = nav.Select(exprSport);

            try
            {
                // Loop all sports
                while (iteratorSport.MoveNext())
                {
                    XPathNavigator _sportNameNavigator = iteratorSport.Current.Clone();
                    int            feedContentSport    = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", ""));
                    if (feedContentSport > 0)
                    {
                        ISport _sport = new Sport();
                        _sport.ID   = Convert.ToInt32(_sportNameNavigator.GetAttribute("id", ""));
                        _sport.Name = _sportNameNavigator.Value;
                        //Add sport to List
                        // sports.Add(_sport);
                        //league- event
                        XmlTextReader readerLeague = new XmlTextReader(string.Format(urlPathLeague, _sport.ID));
                        readerLeague.WhitespaceHandling = WhitespaceHandling.Significant;
                        XPathDocument  docLeague = new XPathDocument(readerLeague, XmlSpace.Preserve);
                        XPathNavigator navLeague = docLeague.CreateNavigator();

                        XPathExpression exprLeague;
                        exprLeague = navLeague.Compile("/rsp/leagues/league");
                        XPathNodeIterator iteratorLeague = navLeague.Select(exprLeague);
                        // Loop all Leagues in each sport
                        while (iteratorLeague.MoveNext())
                        {
                            XPathNavigator _eventNameNavigator = iteratorLeague.Current.Clone();
                            int            feedContentLeague   = Convert.ToInt32(_sportNameNavigator.GetAttribute("feedContents", ""));
                            if (feedContentLeague > 0)
                            {
                                ILeague _league = new League();
                                _league.ID   = Convert.ToInt32(_eventNameNavigator.GetAttribute("id", ""));
                                _league.Name = _eventNameNavigator.Value;
                                //Add the current League to the latest sport
                                sports[sports.Count - 1].Leagues.Add(_league);

                                //match - home team - awayteam
                                XmlTextReader readerMatch = new XmlTextReader(string.Format(urlPathFeed, _sport.ID, _league.ID));
                                readerMatch.WhitespaceHandling = WhitespaceHandling.Significant;
                                XPathDocument  docMatch = new XPathDocument(readerMatch, XmlSpace.Preserve);
                                XPathNavigator navMatch = docMatch.CreateNavigator();

                                XPathExpression exprematch;
                                exprematch = navMatch.Compile("/rsp/fd/sports/sport/leagues/league");
                                XPathNodeIterator iteratorMatch = navMatch.Select(exprematch);
                                // Loop in each League
                                while (iteratorMatch.MoveNext())
                                {
                                    XPathNavigator _matchNameNavigator = iteratorMatch.Current.Clone();

                                    XPathExpression exprematchEvent;
                                    exprematchEvent = _matchNameNavigator.Compile("events/event");
                                    XPathNodeIterator iteratorMatchEvent = _matchNameNavigator.Select(exprematchEvent);
                                    while (iteratorMatchEvent.MoveNext())
                                    {
                                        //  _matchId++;
                                        XPathNavigator _matchEventNameNavigator = iteratorMatchEvent.Current.Clone();
                                        IMatch         _match = new Match();
                                        _match.ID = Convert.ToInt32(_matchEventNameNavigator.GetAttribute("id", ""));;
                                        //_match.eventId = _eventId;
                                        //_match.nameMatch = _matchNameNavigator.GetAttribute("name", "");
                                        _match.HomeTeam      = _matchEventNameNavigator.SelectSingleNode("homeTeam").SelectSingleNode("name").Value;
                                        _match.AwayTeam      = _matchEventNameNavigator.SelectSingleNode("awayTeam").SelectSingleNode("name").Value;
                                        _match.StartDateTime = Convert.ToDateTime(_matchEventNameNavigator.SelectSingleNode("startDateTime").Value);
                                        // Add the match into current League


                                        // Loop all in Periods
                                        if (_matchEventNameNavigator.HasChildren)
                                        {
                                            XPathExpression exprebet;
                                            exprebet = _matchEventNameNavigator.Compile("periods/period");
                                            XPathNodeIterator iteratorBet = _matchEventNameNavigator.Select(exprebet);
                                            //Loop each period
                                            while (iteratorBet.MoveNext())
                                            {
                                                //  _betId++;
                                                XPathNavigator _betNameNavigator = iteratorBet.Current.Clone();
                                                IPeriod        _period           = new Period();
                                                _period.Description = _betNameNavigator.SelectSingleNode("description").Value;;

                                                // Add period to Match

                                                //handicap
                                                XPathExpression exprehandicap;
                                                exprehandicap = _matchEventNameNavigator.Compile("spreads/spread");
                                                XPathNodeIterator iteratorHandicap = _matchEventNameNavigator.Select(exprehandicap);
                                                //total
                                                XPathExpression expretotal;
                                                expretotal = _matchEventNameNavigator.Compile("totals/total");
                                                XPathNodeIterator iteratorTotal = _matchEventNameNavigator.Select(expretotal);
                                                //moneyline
                                                XPathExpression expremoneyline;
                                                expremoneyline = _matchEventNameNavigator.Compile("moneyLine");
                                                XPathNodeIterator iteratorMoneyLine = _matchEventNameNavigator.Select(expremoneyline);

                                                while (iteratorHandicap.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorHandicap.Current.Clone();
                                                    ISpread        _spread = new Spread();
                                                    _spread.AwaySpread = float.Parse(_choiceNameNavigator.SelectSingleNode("awaySpread").Value);
                                                    _spread.AwayPrice  = float.Parse(_choiceNameNavigator.SelectSingleNode("awayPrice").Value);
                                                    _spread.HomeSpread = float.Parse(_choiceNameNavigator.SelectSingleNode("homeSpread").Value);
                                                    _spread.HomePrice  = float.Parse(_choiceNameNavigator.SelectSingleNode("homePrice").Value);
                                                    _period.Spreads.Add(_spread);
                                                }

                                                while (iteratorTotal.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorTotal.Current.Clone();
                                                    ITotal         _total = new Total();
                                                    _total.Point      = float.Parse(_choiceNameNavigator.SelectSingleNode("points").Value);
                                                    _total.OverPrice  = float.Parse(_choiceNameNavigator.SelectSingleNode("overPrice").Value);
                                                    _total.UnderPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("underPrice").Value);
                                                    _period.Totals.Add(_total);
                                                }

                                                while (iteratorMoneyLine.MoveNext())
                                                {
                                                    XPathNavigator _choiceNameNavigator = iteratorMoneyLine.Current.Clone();
                                                    IMoneyLine     _moneyline           = new MoneyLine();

                                                    _moneyline.AwayPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("awayPrice").Value);
                                                    _moneyline.HomePrice = float.Parse(_choiceNameNavigator.SelectSingleNode("homePrice").Value);
                                                    _moneyline.DrawPrice = float.Parse(_choiceNameNavigator.SelectSingleNode("drawPrice").Value);
                                                    _period.MoneyLines.Add(_moneyline);
                                                }

                                                _match.Periods.Add(_period);
                                            }

                                            _league.Matches.Add(_match);
                                        }
                                    }
                                }

                                _sport.Leagues.Add(_league);
                            }
                        }
                        sport.Add(_sport);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                sports = null;
            }
            return(sport);
        }
コード例 #7
0
        public PinacclePrices ConvertPinnacleEventToDatabasePrices(OddEvent oddEvent)
        {
            eventDiscs.Clear();
            this.pinaccle = new PinacclePrices();



            this.pinaccle.IsLive    = oddEvent.IsLive;
            this.pinaccle.DateAdded = oddEvent.DateAdded;

            this.pinaccle.EventId   = oddEvent.EventId.ToString();
            this.properties         = this.pinaccle.GetType().GetProperties();
            this.pinaccle.HomeTeam  = oddEvent.HomeTeam;
            this.pinaccle.AwayTeam  = oddEvent.AwayTeam;
            this.pinaccle.StartTime = oddEvent.StartTime;
            OddPeriod oddPeriod = oddEvent.Periods[0];

            MoneyLine moneyLine = oddPeriod.MoneyLine;

            List <Handicap> handicaps = oddPeriod.Handicaps;

            List <Total> totals = oddPeriod.Totals;

            DoubleChance doubleChance = oddPeriod.DoubleChance;

            if (oddPeriod.TeamTotal != null)
            {
                Total homeTotal = oddPeriod.TeamTotal.Home;

                Total awayTeamTotal = oddPeriod.TeamTotal.Away;
                if (homeTotal != null)
                {
                    this.SetHomeTeamTotalPricesTodatabase(homeTotal);
                }

                if (awayTeamTotal != null)
                {
                    this.SetAwayTeamTotalPricesToDatabase(awayTeamTotal);
                }
            }


            this.SetMoneyLinePricesToDatabase(moneyLine);
            //this.SetDoubleChanceToDatabasePrices(doubleChance);

            this.SetTotalPricesToDatabase(totals);

            //this.SetHomeTeamTotalPricesTodatabase(homeTotal);

            //this.SetAwayTeamTotalPricesToDatabase(awayTeamTotal);

            this.SetHandicapPricesToDatabase(handicaps);

            //var result = MathClass.GetStatsForMarket(this.eventDiscs);

            //this.pinaccle.EventDiscMax = result.maxDisc;

            //this.pinaccle.EventDiscAverage = result.averageDisc;

            //this.pinaccle.EventMediana = MathClass.GetMedForMarket(this.eventDiscs);

            return(this.pinaccle);
        }