public SelectionList ConvertToObject(string tradedVolumeData)
        {
            if (tradedVolumeData == null)
            {
                return null;
            }
            //Step 1 - Create the response object
            var runnerList = new SelectionList();

            //Step 2 - Split the runners out
            var runnerStringArray = tradedVolumeData.Split(":".ToCharArray());

            //Step 3 - Loop through each runner
            for (var x = 0; x < runnerStringArray.Length; x++)
            {
                //Check that the array is not empty
                if (runnerStringArray[x].Length > 0)
                {
                    //Create the runner object
                    var runner = new Selection();

                    //Step 4 - Split out the runner object items
                    var tradedVolumeStringArray = runnerStringArray[x].Split("|".ToCharArray());

                    //Step 5 - Check that the array is equal or greater than 1
                    if (tradedVolumeStringArray.Length > 1)
                    {
                        //Step 6 - Populate the runner data
                        var runnerInfoStringArray = tradedVolumeStringArray[0].Split(("~").ToCharArray());

                        runner.selectionId = Convert.ToInt32(runnerInfoStringArray[0]);
                        runner.asianLineId = Convert.ToInt32(runnerInfoStringArray[1]);
                        runner.actualSPPrice = Convert.ToDouble(runnerInfoStringArray[2]);
                        //runner.totalBSPBackMatchedAmount = runnerInfoStringArray[3];
                        //runner.totalBSPLiabilityMatchedAmount = runnerInfoStringArray[4];

                        //Step 7 - Get all the traded increments
                        for (var count = 1; count < tradedVolumeStringArray.Length; count++)
                        {
                            if (!tradedVolumeStringArray[count].Contains("~")) continue;
                            var traded = new TradedVolume();
                            var runnerPricesStringArray =
                                tradedVolumeStringArray[count].Split(("~").ToCharArray());

                            traded.odds = Convert.ToDouble(runnerPricesStringArray[0]);
                            traded.totalMatchedAmount = Convert.ToDouble(runnerPricesStringArray[1]);
                            runner.tradedVolume.Add(traded);
                        }

                        //Step 8 - Sort the list items
                        runner.tradedVolume.Sort(new TradedVolumeDepthComparer());
                    }

                    runnerList.Add(runner);
                }
            }

            //Step 9 - Done
            return runnerList;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectionView"/> class.
        /// </summary>
        public SelectionView()
        {
            InitializeComponent();

            m_selectionPriceButtons = new[] { btnBack1, btnBack2, btnBack3, btnLay1, btnLay2, btnLay3, btnSPBack, btnSPLay };

            SelectionData = new Selection
                                {
                                    runnerDisplayDetail = new RacecardInfo(),
                                    pricesToBack = new PriceList(),
                                    pricesToLay = new PriceList()
                                };
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Does the list contain the following Runner
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(Selection item)
 {
     lock (List.SyncRoot)
     {
         return List.Contains(item);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Add a Runner to the IList
 /// </summary>
 /// <param name="item">The item.</param>
 public virtual void Add(Selection item)
 {
     lock (List.SyncRoot)
     {
         //forward our Add method on to
         //CollectionBase.IList.Add
         List.Add(item);
     }
 }
        /// <summary>
        /// Extract the results of a Betfair GetMarketPricesCompressedresp.marketPrices string to a response object
        /// No prices get updated during suspend and closed market status state.
        /// The following values get updated during a normal update:
        /// </summary>
        /// <param name="completeMarketPrices">The complete market prices.</param>
        /// <param name="exchangeId">The exchange id.</param>
        /// <param name="status">The status.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="pricesUpdateTime">The time to set the Market.lastRunnerPricesLoad value to</param>
        /// <returns></returns>
        public Market ConvertToObject(string completeMarketPrices, int exchangeId, MarketStatus status, string currency,
                                      DateTime pricesUpdateTime)
        {
            if (completeMarketPrices != null && status == MarketStatus.ACTIVE)
            {
                //Step 1 - Create the response object
                var market = new Market {status = status};

                //Step 2 - Clean up the break characters
                completeMarketPrices = HelperMethods.ProtectBreakChars(completeMarketPrices);

                //Step 3 - Split
                string[] marketData = completeMarketPrices.Split(":".ToCharArray());

                //Step 4 - Clean before split
                marketData[0] = HelperMethods.RemoveTrailingTilde(marketData[0]);

                //Step 5 - Get the market data segment
                string[] marketDataArray = marketData[0].Split("~".ToCharArray());

                //Step 6 - Populate the response object
                market.marketId = Convert.ToInt32(marketDataArray[0]);
                market.betDelay = Convert.ToInt32(marketDataArray[1]);
                market.currency = currency;
                market.lastRunnerPricesLoad = pricesUpdateTime;

                market.exchangeId = exchangeId;

                string removedRunners = "";
                if (marketDataArray.Length > 2)
                {
                    removedRunners = marketDataArray[2];
                }

                //Step 7 - Process the removed runner list
                if (removedRunners.Length > 0)
                {
                    if (removedRunners.Substring((removedRunners.Length - 1), 1) == ";")
                        removedRunners = removedRunners.Remove((removedRunners.Length - 1), 1);

                    string[] removedRunnersArray = removedRunners.Split(";".ToCharArray());
                    market.removedRunners = new RemovedRunner[removedRunnersArray.Length];

                    for (int x = 0; x < market.removedRunners.Length; x++)
                    {
                        string[] removedRunnerItems = removedRunnersArray[x].Split(",".ToCharArray());
                        var r = new RemovedRunner
                                    {
                                        name = removedRunnerItems[0],
                                        removedDate = removedRunnerItems[1],
                                        adjustmentFactor = Convert.ToDouble(removedRunnerItems[2])
                                    };
                        market.removedRunners[x] = r;
                    }
                }

                //Step 8 - Loop through the runners
                market.runners = new SelectionList();

                for (int x = 1; x < marketData.Length; x++)
                {
                    //Step 9 - Get the individual runners data from the string
                    string[] runnerDataArray = marketData[x].Split("|".ToCharArray());

                    //Step 10 - Create an data array for the 3 data objects
                    string[] runnerInfoArray =
                        HelperMethods.RemoveTrailingTilde(runnerDataArray[0]).Split("~".ToCharArray());
                    string[] runnerPricesArray =
                        HelperMethods.RemoveTrailingTilde(runnerDataArray[1]).Split("~".ToCharArray());

                    //Step 11 - Create the runner response object
                    var runner = new Selection
                                     {
                                         selectionId = Convert.ToInt32(runnerInfoArray[0])
                                     };

                    //Step 12 - Populate the data

                    if (runnerInfoArray[1].Length > 0)
                        runner.orderIndex = Convert.ToInt32(runnerInfoArray[1]);

                    if (runnerInfoArray[2].Length > 0)
                        runner.totalAmountMatched = Convert.ToDouble(runnerInfoArray[2]);

                    if (runnerInfoArray[3].Length > 0)
                        runner.lastPriceMatched = Convert.ToDouble(runnerInfoArray[3]);

                    if (runnerInfoArray[4].Length > 0)
                        runner.handiCap = Convert.ToDouble(runnerInfoArray[4]);

                    if (runnerInfoArray[5].Length > 0)
                        runner.reductionFactor = Convert.ToDouble(runnerInfoArray[5]);

                    if (runnerInfoArray[6].Length > 0)
                        runner.vacant = Convert.ToBoolean(runnerInfoArray[6]);

                    if (runnerInfoArray[7].Length > 0)
                        runner.asianLineId = Convert.ToInt32(runnerInfoArray[7]);

                    if (runnerInfoArray[8].Length > 0)
                        runner.farSPPrice = Convert.ToDouble(runnerInfoArray[8]);

                    if (runnerInfoArray[9].Length > 0)
                        runner.nearSPPrice = Convert.ToDouble(runnerInfoArray[9]);

                    if (runnerInfoArray[10].Length > 0)
                        runner.actualSPPrice = Convert.ToDouble(runnerInfoArray[10]);

                    //Step 13 - Add the prices
                    if (runnerPricesArray.Length > 1)
                    {
                        int countPrice = 0;
                        while (countPrice < (runnerPricesArray.Length))
                        {
                            if (runner.pricesToBack == null)
                                runner.pricesToBack = new PriceList();

                            if (Convert.ToDouble(runnerPricesArray[1 + countPrice]) > 0)
                            {
                                var backPrice = new Price
                                                    {
                                                        price = Convert.ToDouble(runnerPricesArray[0 + countPrice]),
                                                        amountAvailable =
                                                            Convert.ToDouble(runnerPricesArray[1 + countPrice]),
                                                        type = BetTypeOptions.L
                                                    };
                                runner.pricesToBack.Add(backPrice);
                            }

                            if (runner.pricesToLay == null)
                                runner.pricesToLay = new PriceList();

                            if (Convert.ToDouble(runnerPricesArray[2 + countPrice]) > 0)
                            {
                                var layPrice = new Price
                                                   {
                                                       price = Convert.ToDouble(runnerPricesArray[0 + countPrice]),
                                                       amountAvailable =
                                                           Convert.ToDouble(runnerPricesArray[2 + countPrice]),
                                                       type = BetTypeOptions.B
                                                   };
                                runner.pricesToLay.Add(layPrice);
                            }
                            countPrice += 5;
                        }

                        //Add the price depth and organize the data
                        runner.pricesToBack.Sort(new PriceDepthComparerReverse());
                        for (int depth = 0; depth < runner.pricesToBack.Count; depth++)
                            runner.pricesToBack[depth].depth = (depth + 1);

                        runner.pricesToLay.Sort(new PriceDepthComparer());
                        for (int depth = 0; depth < runner.pricesToLay.Count; depth++)
                            runner.pricesToLay[depth].depth = (depth + 1);
                    }
                    market.runners.Add(runner);
                }
                return market;
            }
            return null;
        }
Ejemplo n.º 6
0
            /// <summary>
            /// Adds the specified selection.
            /// </summary>
            /// <param name="selection">The selection.</param>
            private void Add(Selection selection)
            {
                if (selection == null) return;
                if (selection.selectionId <= 0 && selection.asianLineId <= 0) return;

                var key = String.Format("SID:{0}AID:{1}", selection.selectionId, selection.asianLineId);

                if (Controls.ContainsKey(key) && Controls[key].GetType() == typeof (SelectionView))
                {
                    var selectionViewControl = (SelectionView) Controls[key];

                    selectionViewControl.SelectionData = selection;
                    selectionViewControl.RefreshControlPrices();
                }
                else
                {
                    var selectionViewControl = new SelectionView
                                                   {
                                                       Name = key,
                                                       MarketId = MarketId,
                                                       ExchangeId = ExchangeId,
                                                       Currency = Currency,
                                                       ShowStartingPricesIfAvailable = ShowStartingPricesIfAvailable,
                                                       IsBSPMarket = IsBSPMarket,
                                                       SelectionData = selection,
                                                       Dock = DockStyle.Top
                                                   };

                    selectionViewControl.RefreshControl();

                    if (Controller != null) selectionViewControl.Controller = Controller;

                    Controls.Add(selectionViewControl);
                    selectionViewControl.BringToFront();
                }

                Height = Controls.Count*40;
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Extract the results of a Betfair GetMarketPricesCompressedresp.marketPrices string to a RunnerList object
        /// No prices get updated during suspend and closed market status state
        /// </summary>
        /// <param name="marketPrices">The market prices.</param>
        /// <param name="exchangeId">The exchange id.</param>
        /// <param name="pricesUpdateTime">The time to set the Market.lastRunnerPricesLoad value to</param>
        /// <returns></returns>
        public Market ConvertToObject(string marketPrices, int exchangeId, DateTime pricesUpdateTime)
        {
            try
            {
                if (marketPrices != null)
                {
                    //Step 1 - Clean up the break characters
                    marketPrices = HelperMethods.ProtectBreakChars(marketPrices);

                    //Step 2 - Split
                    string[] marketData = marketPrices.Split(":".ToCharArray());

                    //Step 3 - Clean before split (We don't use the SplitOptions because empty spaces serve a purpose)
                    marketData[0] = HelperMethods.RemoveTrailingTilde(marketData[0]);

                    //Step 4 - Create the response object
                    var market = new Market();

                    //Step 5 - Get the market data segment
                    string[] marketDataArray = marketData[0].Split("~".ToCharArray());

                    //Step 6 - Populate the response object
                    market.marketId = Convert.ToInt32(marketDataArray[0]);
                    market.exchangeId = exchangeId;
                    market.currency = marketDataArray[1];
                    market.status = (MarketStatus) Enum.Parse(typeof (MarketStatus), marketDataArray[2]);
                    market.betDelay = Convert.ToInt32(marketDataArray[3]);
                    market.numberOfWinners = Convert.ToInt32(marketDataArray[4]);
                    market.marketInformation = HelperMethods.RestoreBreakChars(marketDataArray[5]);
                    market.discountAllowed = Convert.ToBoolean(marketDataArray[6]);
                    market.marketBaseRate = Convert.ToDouble(marketDataArray[7]);
                    market.apiMarketDataLastRefresh = Convert.ToInt64(marketDataArray[8]);
                    string removedRunners = marketDataArray[9];
                    if (marketDataArray[10] == "Y")
                    {
                        market.bspMarket = true;
                    }
                    market.lastRunnerPricesLoad = pricesUpdateTime;
                    market.numberOfRunners = marketData.Length - 1; //The first row is market info

                    //Step 7 - Process the removed runner list
                    if (removedRunners.Length > 0)
                    {
                        if (removedRunners.Substring((removedRunners.Length - 1), 1) == ";")
                            removedRunners = removedRunners.Remove((removedRunners.Length - 1), 1);

                        string[] removedRunnersArray = removedRunners.Split(";".ToCharArray());
                        market.removedRunners = new RemovedRunner[removedRunnersArray.Length];

                        for (var x = 0; x < market.removedRunners.Length; x++)
                        {
                            string[] removedRunnerItems = removedRunnersArray[x].Split(",".ToCharArray());
                            var r = new RemovedRunner
                                        {
                                            name = removedRunnerItems[0],
                                            removedDate = removedRunnerItems[1],
                                            adjustmentFactor = Convert.ToDouble(removedRunnerItems[2])
                                        };
                            market.removedRunners[x] = r;
                        }
                    }

                    //Step 8 - Loop through the runners
                    market.runners = new SelectionList();
                    for (var x = 1; x < marketData.Length; x++)
                    {
                        //Step 9 - Get the individual runners data from the string
                        string[] runnerDataArray = marketData[x].Split("|".ToCharArray());

                        //Step 10 - Create an data array for the 3 data objects
                        string[] runnerInfoArray =
                            HelperMethods.RemoveTrailingTilde(runnerDataArray[0]).Split("~".ToCharArray());
                        string[] runnerBackPricesArray =
                            HelperMethods.RemoveTrailingTilde(runnerDataArray[1]).Split("~".ToCharArray());
                        string[] runnerLayPricesArray =
                            HelperMethods.RemoveTrailingTilde(runnerDataArray[2]).Split("~".ToCharArray());

                        //Step 11 - Create the runner response object
                        var runner = new Selection
                                         {
                                             pricesToBack = new PriceList(),
                                             pricesToLay = new PriceList(),
                                             selectionId = Convert.ToInt32(runnerInfoArray[0])
                                         };

                        //Step 12 - Populate the data
                        if (runnerInfoArray[1].Length > 0)
                            runner.orderIndex = Convert.ToInt32(runnerInfoArray[1]);

                        if (runnerInfoArray[2].Length > 0)
                            runner.totalAmountMatched = Convert.ToDouble(runnerInfoArray[2]);

                        if (runnerInfoArray[3].Length > 0)
                            runner.lastPriceMatched = Convert.ToDouble(runnerInfoArray[3]);

                        if (runnerInfoArray[4].Length > 0)
                            runner.handiCap = Convert.ToDouble(runnerInfoArray[4]);

                        if (runnerInfoArray[5].Length > 0)
                            runner.reductionFactor = Convert.ToDouble(runnerInfoArray[5]);

                        if (runnerInfoArray[6].Length > 0)
                            runner.vacant = Convert.ToBoolean(runnerInfoArray[6]);

                        if (runnerInfoArray[7].Length > 0)
                            runner.farSPPrice = Convert.ToDouble(runnerInfoArray[7]);

                        if (runnerInfoArray[8].Length > 0)
                            runner.nearSPPrice = Convert.ToDouble(runnerInfoArray[8]);

                        if (runnerInfoArray[9].Length > 0)
                            runner.actualSPPrice = Convert.ToDouble(runnerInfoArray[9]);

                        //Step 13 - Add the Back prices
                        if (runnerBackPricesArray.Length > 1)
                        {
                            int countPrice = 0;
                            while (countPrice < (runnerBackPricesArray.Length))
                            {
                                var price = new Price
                                                {
                                                    price = Convert.ToDouble(runnerBackPricesArray[0 + countPrice]),
                                                    amountAvailable =
                                                        Convert.ToDouble(runnerBackPricesArray[1 + countPrice]),
                                                    type = BetTypeOptions.L,
                                                    depth = Convert.ToInt32(runnerBackPricesArray[3 + countPrice])
                                                };

                                runner.pricesToBack.Add(price);
                                countPrice += 4;
                            }
                        }

                        //Step 14 - Add the Lay prices
                        if (runnerLayPricesArray.Length > 1)
                        {
                            int countPrice = 0;
                            while (countPrice < (runnerLayPricesArray.Length))
                            {
                                var price = new Price
                                                {
                                                    price = Convert.ToDouble(runnerLayPricesArray[0 + countPrice]),
                                                    amountAvailable =
                                                        Convert.ToDouble(runnerLayPricesArray[1 + countPrice]),
                                                    type = BetTypeOptions.B,
                                                    depth = Convert.ToInt32(runnerLayPricesArray[3 + countPrice])
                                                };

                                runner.pricesToLay.Add(price);
                                countPrice += 4;
                            }
                        }
                        market.runners.Add(runner);
                    }
                    return market;
                }
                return null;
            }
            catch
            {
                throw new Exception(marketPrices);
            }
        }