Beispiel #1
0
 public MarketItem(Runner runner,string name)
 {
     SelectionId = runner.SelectionId;
     Status=runner.Status;
     LastPriceTraded = runner.LastPriceTraded == null ? (double)0 : (double)runner.LastPriceTraded;
     TotalMatched = Math.Round(runner.MatchedVol, 0);
     Matched = Math.Round(runner.ActMatched,0);
     RunnerName = name;
     RelativeExposure=runner.RelativeExposure;
     AvgOdds=runner.AvgPrice;
     VolumeBack = Math.Round(runner.VolumeBack,0);
     VolumeLay = Math.Round(runner.VolumeLay,0);
     InsMoneyBack = Math.Round(runner.InsMoneyBack,0);
     InsMoneyLay = Math.Round(runner.InsMoneyLay,0);
     Indikator1=runner.Indikator1;
     Indikator2=runner.Indikator2;
 }
Beispiel #2
0
        public MarketBook GetMarketBook(string marketId)
        {
            MarketBook mb = new MarketBook();
            try
            {
                long lastRefreshNr = 0; ;
                if (LastRefreshNr.ContainsKey(marketId))
                {
                    LastRefreshNr.TryGetValue(marketId, out lastRefreshNr);
                }
                else
                {
                    LastRefreshNr.Add(marketId, lastRefreshNr);
                }
                using (var ctx = new bfmsEntities())
                {
                string query = "SELECT * FROM marketbook JOIN runner USING(Marketid,RefreshNr) " +
                                      "JOIN volume USING (Marketid,Refreshnr,Selectionid) " +
                                      "WHERE Marketid=@MarketId  AND refreshNr=" +
                                      "(SELECT MAX(RefreshNr) FROM marketbook WHERE Marketid=@MarketId AND IsInPlay='False')";
                //"(SELECT MIN(RefreshNr) FROM Marketbook WHERE Marketbook.Marketid=@MarketId AND Marketbook.Status='OPEN' AND Marketbook.IsInPlay='False' AND Marketbook.RefreshNr>@LastRefreshNr)";
                var MaxRefrNr = (from book in ctx.marketbooks where book.MarketId == marketId && book.IsInplay=="False" select book.RefreshNr).Max();
                var MarketCatList = (from book in ctx.marketbooks
                                     from run in ctx.runners
                                     from vol in ctx.volumes
                                     where (book.MarketId==run.MarketId && book.RefreshNr==run.RefreshNr)&&
                                     (run.MarketId==vol.MarketId&&run.SelectionId==vol.SelectionId&&run.RefreshNr==vol.RefreshNr)
                                     && (book.MarketId == marketId) && (book.RefreshNr == MaxRefrNr)
                                     select new {book,run, vol}).ToList();

                    mb.Runners = new List<Runner>();
                    Runner r = null;
                    long lastSelectionId = 0;
                    foreach (var row in MarketCatList)
                    {
                        if (lastSelectionId == 0)
                        {
                            mb.MarketId = row.book.MarketId;
                            mb.RefreshNr =row.book.RefreshNr;
                            mb.RefreshTS = (DateTime)row.book.RefreshTS;
                            mb.IsMarketDataDelayed = "False".Equals(row.book.IsMarketDataDelayed) ? false : true;
                            mb.Status = (MarketStatus)Enum.Parse(typeof(MarketStatus), row.book.Status.ToString());
                            mb.BetDelay = (int)row.book.BetDelay;
                            mb.IsInplay = "False".Equals(row.book.IsInplay) ? false : true;
                            mb.NumberOfWinners = (int)row.book.NumberOfWinners;
                            mb.NumberOfActiveRunners = (int)row.book.NumberOfActiveRunners;
                            mb.NumberOfRunners = (int)row.book.NumberOfRunners;
                            mb.TotalMatched = (double)row.book.TotalMatched;
                            mb.TotalAvailable = (double)row.book.TotalAvailable;
                            mb.OVRBack = (double)row.book.OVRBack;
                            mb.OVRLay = (double)row.book.OVRLay;

                            LastRefreshNr[marketId] = mb.RefreshNr;

                        }
                        if (lastSelectionId != (int)row.run.SelectionId)
                        {
                            r = new Runner();
                            r.ExchangePrices = new ExchangePrices();
                            r.ExchangePrices.AvailableToBack = new List<PriceSize>();
                            r.ExchangePrices.AvailableToLay = new List<PriceSize>();
                            r.ExchangePrices.TradedVolume = new List<PriceSize>();

                            r.SelectionId = (int)row.run.SelectionId;
                            r.RefreshNr = (int)row.run.RefreshNr;
                            r.RunnerName = (string)row.run.Name;
                            r.Status = (RunnerStatus)Enum.Parse(typeof(RunnerStatus), row.run.RunnerStatus.ToString());
                            r.AdjustmentFactor = (double)row.run.AdjustmentFactor;
                            r.ToBackTotal = (double)row.run.ToBackTotal;
                            r.ToLayTotal = (double)row.run.ToLayTotal;
                            r.BackLayRatio = (double)row.run.BackLayRatio;
                            r.LastPriceTraded = row.run.LastPriceTraded.ToString() == "" ? 0 : (double)row.run.LastPriceTraded;
                            r.VolPrice = (double)row.run.VolPrice;
                            r.AvgPrice = (double)row.run.AvgPrice;
                            r.ActMatched = (double)row.run.Matched;
                            r.MatchedVol = (double)row.run.MatchedTotal;//Namenskonflikt mit Marketbook
                            //r.TotalMatched = (double)row[27];
                            r.VolumeBack = (double)row.run.VolumeBack;
                            r.VolumeLay = (double)row.run.VolumeLay;
                            r.InsMoneyBack = (double)row.run.InsMoneyBack;
                            r.InsMoneyLay = (double)row.run.InsMoneyLay;
                            r.Indikator1 = (double)row.run.Indikator1;
                            r.Indikator2 = (double)row.run.Indikator2;
                            lastSelectionId = r.SelectionId;
                            mb.Runners.Add(r);
                        }
                        if (("ATB").Equals(row.vol.Type.ToString()))
                        {
                            PriceSize ps = new PriceSize();
                            ps.Price = (double)row.vol.Price;
                            ps.Size = (double)row.vol.Size;
                            r.ExchangePrices.AvailableToBack.Add(ps);
                        }
                        if (("ATL").Equals(row.vol.Type.ToString()))
                        {
                            PriceSize ps = new PriceSize();
                            ps.Price = (double)row.vol.Price;
                            ps.Size = (double)row.vol.Size;
                            r.ExchangePrices.AvailableToLay.Add(ps);
                        }
                        if (("TVOL").Equals(row.vol.Type.ToString()))
                        {
                            PriceSize ps = new PriceSize();
                            ps.Price = (double)row.vol.Price;
                            ps.Size = (double)row.vol.Size;
                            r.ExchangePrices.TradedVolume.Add(ps);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;

            }

            return mb;
        }
Beispiel #3
0
        public void CalcSeries(Runner runner)
        {
            if ((runner.ActMatched > 0 || BFSeriesLst[(int)BFSeriesEnum.BackOdds].Count < 32) &&
                  runner.ExchangePrices.AvailableToLay.Count > 0 && runner.ExchangePrices.AvailableToBack.Count > 0)
            {
                AddY(BFSeriesEnum.LayOdds, runner.ExchangePrices.AvailableToLay[0].Price);
                AddY(BFSeriesEnum.BackOdds, runner.ExchangePrices.AvailableToBack[0].Price);

                //if (runner.amountMatchedPerRefresh > 0)
                //{
                //    AddY(BFSeriesEnum.LastPriceMatched, runner.lastPriceMatched);
                //    AddY(BFSeriesEnum.LastPriceMatchedInc, Prices.getPriceIdx(runner.lastPriceMatched));
                //}
                //else
                //{   //Außschließlich für die ersten 32 Werte
                //    AddY(BFSeriesEnum.LastPriceMatched, runner.pricesToBack[0].price);
                //    AddY(BFSeriesEnum.LastPriceMatchedInc, Prices.getPriceIdx(runner.pricesToBack[0].price));
                //}

                //AddY(BFSeriesEnum.NearSPPrice, runner.nearSPPrice);
                //AddY(BFSeriesEnum.Volume, runner.amountMatchedPerRefresh);
                //AddY(BFSeriesEnum.AVG_ODDS, runner.avgOdds);
                ////AddY(BFSeriesEnum.AVG_ODDS, market.totalAmountMatched / this.totalAmountMatched);

                //AddY(BFSeriesEnum.BLRatio, Math.Round(runner.backLayRatio * 100));
                //AddY(BFSeriesEnum.EMABLRatio, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.BLRatio], 20, Core.MAType.Ema));
                //AddY(BFSeriesEnum.EMAVolume, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.Volume], 64, Core.MAType.Ema));

                //AddY(BFSeriesEnum.SMABackOdds, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.BackOdds], 16, Core.MAType.Ema));
                //AddY(BFSeriesEnum.SMAFastBackOdds, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.LastPriceMatched], 16, Core.MAType.Ema));
                //AddY(BFSeriesEnum.SMAFastBackOddsInc, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.LastPriceMatchedInc], 16, Core.MAType.Ema));

                //AddY(BFSeriesEnum.KAMASlowBackOdds, TA.getKAMA(BFSeriesLst[(int)BFSeriesEnum.LastPriceMatched], 32));
                //AddY(BFSeriesEnum.KAMASlowBackOddsInc, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.LastPriceMatchedInc], 32, Core.MAType.Ema));

                //AddY(BFSeriesEnum.LinRegSlopeFastBackOdds, TA.getLinearRegAngle(BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOddsInc], 8));
                //AddY(BFSeriesEnum.SMALinRegSlopeFastBackOdds, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.LinRegSlopeFastBackOdds], 16, Core.MAType.Ema));

                //AddY(BFSeriesEnum.LinRegSlopeSlowBackOdds, TA.getLinearRegAngle(BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOddsInc], 8));
                //AddY(BFSeriesEnum.SMALinRegSlopeSlowBackOdds, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.LinRegSlopeSlowBackOdds], 16, Core.MAType.Ema));

                //AddY(BFSeriesEnum.Plus_DI, TA.getPLUS_DI(BFSeriesLst[(int)BFSeriesEnum.LayOdds], BFSeriesLst[(int)BFSeriesEnum.BackOdds], BFSeriesLst[(int)BFSeriesEnum.LastPriceMatched], 32));
                //AddY(BFSeriesEnum.Minus_DI, TA.getMINUS_DI(BFSeriesLst[(int)BFSeriesEnum.LayOdds], BFSeriesLst[(int)BFSeriesEnum.BackOdds], BFSeriesLst[(int)BFSeriesEnum.LastPriceMatched], 32));

                //AddY(BFSeriesEnum.SMA_Plus_DI, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.Plus_DI], 16, Core.MAType.Ema));
                //AddY(BFSeriesEnum.SMA_Minus_DI, TA.getMA(BFSeriesLst[(int)BFSeriesEnum.Minus_DI], 16, Core.MAType.Ema));

                //TA.Ohlc ohlc = TA.getAROON(BFSeriesLst[(int)BFSeriesEnum.LastPriceMatched], BFSeriesLst[(int)BFSeriesEnum.BackOdds], 32);
                //AddY(BFSeriesEnum.AROON_Up, ohlc.high);
                //AddY(BFSeriesEnum.AROON_Down, ohlc.low);

                ////AddY(BFSeriesEnum.RSI, rmi.Calc(BFSeriesLst[(int)BFSeriesEnum.AVG_ODDS], 32, 16).rmi);
                //AddY(BFSeriesEnum.RSI, (TA.getRSI(BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds], 32) + TA.getRSI(BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds], 24) + BFSeriesLst[(int)BFSeriesEnum.BLRatio][BFSeriesLst[(int)BFSeriesEnum.EMABLRatio].Count - 1]) / 3);
                ////AddY(BFSeriesEnum.RSI, (TA.getRSI(BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds], 32)));
                ////AddY(BFSeriesEnum.RSI, (TA.getRSI(BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds], 16) + TA.getRSI(BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds], 16)) / 2);

                //runner.slowIndikator = BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds][BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds].Count - 1];
                //runner.fastIndikator = BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds].Count - 1];
            }
        }
Beispiel #4
0
        //FastLayOdds	|STEADY	   UP	DOWN	STRONG_UP	STRONG_DOWN
        //-------------------------------------------------------------
        //STEADY	    |STEADY	   UP	DOWN	STRONG_UP   STRONG_DOWN
        //UP		    |          UP
        //DOWN			|               DOWN
        //STRONG_UP		|		                STRONG_UP
        //STRONG_DOWN	|				                    STRONG_DOWN
        public TrendEnum checkOddsTrend(Runner runnerPrices)
        {
            TrendEnum result = TrendEnum.GLEI;

            int len = BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds].Count;

            if (((BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 1] > BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds][len - 1] &&
                BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 2] > BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds][len - 2] &&
                BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 3] > BFSeriesLst[(int)BFSeriesEnum.KAMASlowBackOdds][len - 3])
                //&&
                //(BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 1] > BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 2] &&
                //BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 2] > BFSeriesLst[(int)BFSeriesEnum.SMAFastBackOdds][len - 3])
               &&
                (BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 1] > BFSeriesLst[(int)BFSeriesEnum.SMA_Minus_DI][len - 1] &&
                BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 2] > BFSeriesLst[(int)BFSeriesEnum.SMA_Minus_DI][len - 2] &&
                BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 3] > BFSeriesLst[(int)BFSeriesEnum.SMA_Minus_DI][len - 3])
                //&&
                // (BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 1] > BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 2] &&
                // BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 2] > BFSeriesLst[(int)BFSeriesEnum.SMA_Plus_DI][len - 3])
                &&
                (BFSeriesLst[(int)BFSeriesEnum.AROON_Up][len - 1] > 95 &&
                BFSeriesLst[(int)BFSeriesEnum.AROON_Up][len - 2] > 95 &&
                BFSeriesLst[(int)BFSeriesEnum.AROON_Up][len - 3] > 95)
                ))
            {
                //result = true;
            }
            return result;
        }
Beispiel #5
0
        private void InsertVolume(Runner runner, MarketBook marketBook)
        {
            try
            {
                if (runner.ActTradedVol != null && runner.ActTradedVol.Count > 0)
                {
                    using (var ctx = new bfmsEntities())
                    {
                        string query = "INSERT INTO volume (MarketId, SelectionId,RefreshNr,Type,Price,Size) VALUES ";
                        int cnt = 0;
                        List<MySqlParameter> parms = new List<MySqlParameter>();
                        foreach (Volume ps in runner.ActTradedVol)
                        {
                            query = query + "(@MarketId" + cnt + ",@SelectionId" + cnt + ",@RefreshNr" + cnt + ",@Type" + cnt + ",@Price" + cnt + ",@Size" + cnt + "),";

                            parms.Add(new MySqlParameter("@MarketId" + cnt, marketBook.MarketId));
                            parms.Add(new MySqlParameter("@SelectionId" + cnt, runner.SelectionId));
                            parms.Add(new MySqlParameter("@RefreshNr" + cnt, runner.RefreshNr));
                            parms.Add(new MySqlParameter("@Type" + cnt, ps.Type.ToString()));
                            parms.Add(new MySqlParameter("@Price" + cnt, ps.Price));
                            parms.Add(new MySqlParameter("@Size" + cnt, ps.Size));

                            ++cnt;
                        }
                        query = query.Remove(query.Length - 1, 1) + ";";
                        int noOfRows = ctx.Database.ExecuteSqlCommand(query, parms.ToArray());
                    }
                }

                if (runner.ExchangePrices != null && runner.ExchangePrices.AvailableToBack.Count > 0)
                {
                    using (var ctx = new bfmsEntities())
                    {
                        string query = "INSERT INTO volume (MarketId, SelectionId,RefreshNr,Type,Price,Size) VALUES ";

                        int cnt = 0;
                        List<MySqlParameter> parms = new List<MySqlParameter>();
                        foreach (PriceSize ps in runner.ExchangePrices.AvailableToBack)
                        {

                            query = query + "(@MarketId" + cnt + ",@SelectionId" + cnt + ",@RefreshNr" + cnt + ",@Type" + cnt + ",@Price" + cnt + ",@Size" + cnt + "),";
                            parms.Add(new MySqlParameter("@MarketId" + cnt, marketBook.MarketId));
                            parms.Add(new MySqlParameter("@SelectionId" + cnt, runner.SelectionId));
                            parms.Add(new MySqlParameter("@RefreshNr" + cnt, runner.RefreshNr));
                            parms.Add(new MySqlParameter("@Type" + cnt, "ATB"));
                            parms.Add(new MySqlParameter("@Price" + cnt, ps.Price));
                            parms.Add(new MySqlParameter("@Size" + cnt, ps.Size));

                            ++cnt;
                        }
                        query = query.Remove(query.Length - 1, 1) + ";";
                        int noOfRows = ctx.Database.ExecuteSqlCommand(query, parms.ToArray());
                    }
                }

                if (runner.ExchangePrices != null && runner.ExchangePrices.AvailableToLay.Count > 0)
                {
                    using (var ctx = new bfmsEntities())
                    {
                        string query = "INSERT INTO volume (MarketId, SelectionId,RefreshNr,Type,Price,Size) VALUES ";
                        int cnt = 0;
                        List<MySqlParameter> parms = new List<MySqlParameter>();
                        foreach (PriceSize ps in runner.ExchangePrices.AvailableToLay)
                        {
                            query = query + "(@MarketId" + cnt + ",@SelectionId" + cnt + ",@RefreshNr" + cnt + ",@Type" + cnt + ",@Price" + cnt + ",@Size" + cnt + "),";
                            parms.Add(new MySqlParameter("@MarketId" + cnt, marketBook.MarketId));
                            parms.Add(new MySqlParameter("@SelectionId" + cnt, runner.SelectionId));
                            parms.Add(new MySqlParameter("@RefreshNr" + cnt, runner.RefreshNr));
                            parms.Add(new MySqlParameter("@Type" + cnt, "ATL"));
                            parms.Add(new MySqlParameter("@Price" + cnt, ps.Price));
                            parms.Add(new MySqlParameter("@Size" + cnt, ps.Size));

                            ++cnt;
                        }
                        query = query.Remove(query.Length - 1, 1) + ";";
                        int noOfRows = ctx.Database.ExecuteSqlCommand(query, parms.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(Util.FormatExc(ex));

            }
        }