Example #1
0
File: Market.cs Project: BFMS/BFMS
        public Market(MarketBook book)
        {
            marketCatalogue = book.marketCatalogue;
            MarketId = book.MarketId;
            RefreshNr = book.RefreshNr;
            Status = book.Status.ToString();
            IsInplay = book.IsInplay;
            EventName = book.marketCatalogue.Event.Venue;
            Name = book.marketCatalogue.MarketName;
            Type = book.marketCatalogue.Description.MarketType;
            LocalStartDate = book.marketCatalogue.LocalStartTime.Date;
            LocalStartTime = book.marketCatalogue.LocalStartTime;
            NumberOfWinners = book.NumberOfWinners;
            NumberOfRunners = book.NumberOfRunners;
            NumberOfActiveRunners = book.NumberOfActiveRunners;
            Ovr = book.OVRLay;
            TotalMatched = book.TotalMatched;
            Runners = new List<MarketItem>();
            if (book.Runners != null)
            {
                foreach (Runner runner in book.Runners)
                {
                    MarketItem mi = new MarketItem(runner, book.marketCatalogue.Runners.Find(c => c.SelectionId == runner.SelectionId).RunnerName);
                    Runners.Add(mi);
                    if (runner.LastPrices != null)
                    {
                        runner.LastPrices = null;
                    }

                }
            }
        }
Example #2
0
File: DBAPI.cs Project: BFMS/BFMS
        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;
        }
Example #3
0
File: MainFrm.cs Project: BFMS/BFMS
        private void EventDGV_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MarketCatalogue mc = (MarketCatalogue)((DataGridView)sender).SelectedRows[0].DataBoundItem;
            if (!editorPane1.TabPages.ContainsKey(mc.MarketId))
            {
                TabPage newTabPage;
                if (editorPane1.TabCount == 1 && tabPage1.Name == "tabPage1")
                {
                    tabPage1.Name = mc.MarketId;
                    tabPage1.Text = mc.Event.Venue + " " + mc.LocalStartTimeHM;
                    newTabPage = tabPage1;
                }
                else
                {
                    newTabPage = new TabPage(mc.Event.Venue + " " + mc.LocalStartTimeHM);
                    newTabPage.Name = mc.MarketId;
                    editorPane1.TabPages.Add(newTabPage);
                }
                DataGridView dgv = new DataGridView();
                InitMarketDGV(dgv);
                newTabPage.Controls.Add(dgv);
                newTabPage.Controls.Add(InitMarketHeader());

                RichTextBox rtb = new RichTextBox();
                rtb.Size = editorPane1.Size;
                rtb.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
                editorPane1.TabPages[editorPane1.TabPages.Count - 1].Controls.Add(rtb);
                editorPane1.SelectTab(editorPane1.TabPages.Count - 1);

                //MarketBook mb = service.GetMarketBook(mc.MarketId);
                MarketBook mb = new MarketBook();
                //MarketBook mb = ((List<MarketBook>)Util.DeserializeObj("BFMS.marketBooks" + ((DataGridView)sender).SelectedRows[0].Index + 0)).Find(c => c.MarketId == mc.MarketId);
                mb.marketCatalogue = mc;
                if (Config.ServiceMode == Config.Mode.DB)
                {
                    mc.Runners = dba.GetRunnerDesc(mc.MarketId);
                }
                Market market = new Market(mc);
                markets.Add(market.MarketId, market);

                dgv.DataSource = market;
                dgv.CurrentCell = null;
                marketUpdate.AddMarket(mc);
            }
            else
            {
                editorPane1.SelectTab(mc.MarketId);
            }
        }
Example #4
0
File: MainFrm.cs Project: BFMS/BFMS
 private void editorPane1_OnTabClose(object sender, TabCloseEventArgs e)
 {
     if (editorPane1.TabPages.Count == 1)
     {
         // e.Accept = false;
     }
     //editorPane1.SelectTab(e.TabIndex);
     TabPage tp = (TabPage)sender;
     if (editorPane1.TabPages.ContainsKey(tp.Name) && tp.Controls.Count > 0)
     {
         MarketCatalogue market = marketCat.Find(x => x.MarketId == tp.Name);
         marketUpdate.RemoveMarket(market.MarketId);
         MarketBook mb =new MarketBook();
         marketUpdate.LastBooks.TryRemove(market.MarketId, out mb);
         markets.Remove(tp.Name);
     }
 }
Example #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));

            }
        }