Example #1
0
        /// <summary>
        /// Checks for emty runner instances.
        /// </summary>
        /// <param name="market">The market.</param>
        /// <returns></returns>
        private static Market CheckForEmtyRunnerInstances(Market market)
        {
            if (market == null || market.runners == null)
            {
                return(market);
            }

            int removeAt = -1;

            for (int x = 0; x < market.runners.Count; x++)
            {
                if (market.runners[x].selectionId <= 0)
                {
                    removeAt = x;
                }
            }

            if (removeAt > -1)
            {
                market.runners.RemoveAt(removeAt);
            }

            market.numberOfRunners = market.runners.Count;

            return(market);
        }
Example #2
0
        internal MarketProcessor(string id, Market market, StrategyLoadPatern strategy)
        {
            this.id = id;
            this.market = market;
            this.strategy = strategy;

            raceCourseAbreviations = new RaceCourseAbreviations();
            run = false;

            asyncResponsesWaiting = new Dictionary<string, DateTime>();
        }
Example #3
0
        private void StartMarketProcessorThread(int exchangeId, int marketId, StrategyLoadPatern strategy)
        {
            // Create the ID to use for this item
            var processId = String.Format("MARKET_PROCESSOR:{0}:{1}", exchangeId, marketId);

            if (LigniteEngineThreads.ContainsKey(processId)) return;

            var market = new Market {exchangeId = exchangeId, marketId = marketId};

            // Make sure the requested strategy is complete, if not replace empty elements with the default config
            var defaultPatern = settings.GetDefaultStrategyLoadPatern();

            if (strategy.OnMarketLoadActions == null)
            {
                strategy.OnMarketLoadActions = defaultPatern.OnMarketLoadActions;
            }

            if (strategy.DataLoadPaterns.Default == null)
            {
                strategy.DataLoadPaterns.Default = defaultPatern.DataLoadPaterns.Default;
            }

            if (strategy.DataLoadPaterns.HasBets == null)
            {
                strategy.DataLoadPaterns.HasBets = defaultPatern.DataLoadPaterns.HasBets;
            }

            if (strategy.DataLoadPaterns.HasUnmatchedBets == null)
            {
                strategy.DataLoadPaterns.HasUnmatchedBets = defaultPatern.DataLoadPaterns.HasUnmatchedBets;
            }

            if (strategy.DataLoadPaterns.Inactive == null)
            {
                strategy.DataLoadPaterns.Inactive = defaultPatern.DataLoadPaterns.Inactive;
            }

            if (strategy.DataLoadPaterns.InPlay == null)
            {
                strategy.DataLoadPaterns.InPlay = defaultPatern.DataLoadPaterns.InPlay;
            }

            if (strategy.DataLoadPaterns.Suspended == null)
            {
                strategy.DataLoadPaterns.Suspended = defaultPatern.DataLoadPaterns.Suspended;
            }

            // Declare the MarketLoader class to be threaded
            var marketProcessor = new MarketProcessor(processId, market, strategy);

            // Create the thread and start it
            var marketProcessorThread = new Thread(marketProcessor.Start);
            marketProcessorThread.Start();

            // Now lets store the thread so that we can access it later
            LigniteEngineThreads.Add(processId, marketProcessorThread);

            // Notify the user
            SendMessage(String.Format("New market submitted for processing. ID = {0}", processId));
        }
Example #4
0
        private bool UpdateMarketPrices(bool completeDepth)
        {
            var retryCount = 0;

            while (retryCount < 3)
            {
                try
                {
                    if (completeDepth)
                    {
                        // Get the fresh data from the Betfair API
                        var result = Core.betfairAPI.GetCompleteMarketPricesCompressedObject(market.exchangeId,
                                                                                                market.marketId,
                                                                                                market.status);
                        if (result != null)
                        {
                            // Lets synchronize the new data with our local Collections.Market object
                            market =
                                new Betfair.Utilities.BetfairObjectSync.Market().CompleteMarketPricessCompressedToMarket
                                    (market, result);
                            return true;
                        }
                        return false;
                    }
                    else
                    {
                        // Get the fresh data from the Betfair API
                        var result = Core.betfairAPI.GetMarketPricesCompressedObject(market.exchangeId,
                                                                                        market.marketId);
                        if (result != null)
                        {
                            // Lets synchronize the new data with our local Collections.Market object
                            market =
                                new Betfair.Utilities.BetfairObjectSync.Market().MarketPricessCompressedToMarket(
                                    market, result);
                            return true;
                        }
                        return false;
                    }
                }
                catch (Exception ex)
                {
                    retryCount++;
                    SendErrorMessage(String.Format("EXCEPTION: Thread ID:{0} MESSAGE:{1}", ID, ex.Message));

                    if (retryCount > 3)
                    {
                        return false;
                    }

                    Thread.Sleep(10);
                }
            }
            return false;
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExampleStrategy"/> class.
 /// </summary>
 public MyStrategy()
 {
     m_market = new Market();
     Bets = new List<Bet>();
 }
Example #6
0
        /// <summary>
        /// Run the StartUp logic and initializers.
        /// </summary>
        /// <param name="processorId">The processor id.</param>
        /// <param name="market"></param>
        /// <param name="requestTimeGmt">The request time GMT.</param>
        /// <returns></returns>
        public bool StartUp(string processorId, Market market, DateTime requestTimeGmt)
        {
            m_market = market;

            return (true);
        }
Example #7
0
        /// <summary>
        /// The shutdown method in your class gets excuted when the thread terminates.
        /// use this to elegantly close down data sources etc.
        /// </summary>
        /// <param name="processorId">The processor id.</param>
        /// <param name="market"></param>
        /// <param name="requestTimeGmt">The request time GMT.</param>
        /// <returns></returns>
        public bool ShutDown(string processorId, Market market, DateTime requestTimeGmt)
        {
            m_market = null;

            return (true);
        }
Example #8
0
 /// <summary>
 /// Does the list contain the following MarketItem
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(Market item)
 {
     lock (List.SyncRoot)
     {
         return List.Contains(item);
     }
 }
Example #9
0
 /// <summary>
 /// Add a MarketItem to the IList
 /// </summary>
 /// <param name="item">The item.</param>
 public virtual void Add(Market item)
 {
     lock (List.SyncRoot)
     {
         //forward our Add method on to
         //CollectionBase.IList.Add
         List.Add(item);
     }
 }
Example #10
0
        /// <summary>
        /// Checks for emty runner instances.
        /// </summary>
        /// <param name="market">The market.</param>
        /// <returns></returns>
        private static Market CheckForEmtyRunnerInstances(Market market)
        {
            if (market == null || market.runners == null) return market;

            int removeAt = -1;

            for (int x = 0; x < market.runners.Count; x++)
            {
                if (market.runners[x].selectionId <= 0) removeAt = x;
            }

            if (removeAt > -1) market.runners.RemoveAt(removeAt);

            market.numberOfRunners = market.runners.Count;

            return market;
        }
Example #11
0
        /// <summary>
        /// The API GetMarket service allows the customer to input a
        /// Market ID and retrieve all static market data for the
        /// market requested. To get a Market ID for the betting
        /// market associated with an event you are interested in,
        /// use the GetEvents command.
        /// </summary>
        /// <param name="exchangeId">The exchange id.</param>
        /// <param name="marketId">The market id.</param>
        /// <returns></returns>
        public Market GetMarketObject(int exchangeId, int marketId)
        {
            BetfairExchangeAPI.Market bfMarket = GetMarket(exchangeId, marketId);
            var marketToUpdate = new Market();
            if (bfMarket != null)
            {
                marketToUpdate.apiMarketDataLastRefresh = bfMarket.lastRefresh;
                marketToUpdate.bspMarket = bfMarket.bspMarket;
                marketToUpdate.country = bfMarket.countryISO3;
                marketToUpdate.currency = _currency;
                marketToUpdate.discountAllowed = bfMarket.discountAllowed;
                marketToUpdate.eventDate = bfMarket.marketTime;
                marketToUpdate.eventHierarchy = bfMarket.eventHierarchy;
                marketToUpdate.eventTypeId = bfMarket.eventTypeId;
                marketToUpdate.exchangeId = exchangeId;
                marketToUpdate.lastMarketInfoLoad = DateTime.Now;
                marketToUpdate.marketBaseRate = bfMarket.marketBaseRate;
                marketToUpdate.marketId = marketId;
                marketToUpdate.marketInformation = bfMarket.marketDescription;
                marketToUpdate.name = bfMarket.name;
                marketToUpdate.numberOfRunners = bfMarket.runners.Length;
                marketToUpdate.numberOfWinners = bfMarket.numberOfWinners;
                marketToUpdate.runnersMayBeAdded = bfMarket.runnersMayBeAdded;
                marketToUpdate.status =
                    (MarketStatus) Enum.Parse(typeof (MarketStatus), bfMarket.marketStatus.ToString());
                marketToUpdate.type = bfMarket.marketType.ToString();
                marketToUpdate.menuPath = bfMarket.menuPath;

                if (marketToUpdate.runners == null)
                {
                    marketToUpdate.runners = new SelectionList();
                }

                foreach (var runner in bfMarket.runners)
                {
                    var indexNo = marketToUpdate.runners.GetRunnerIndexNoBySelectionId(runner.selectionId);

                    if (indexNo < 0)
                    {
                        var r = new Collections.Selection
                                    {
                                        asianLineId = runner.asianLineId,
                                        handiCap = runner.handicap,
                                        name = runner.name,
                                        selectionId = runner.selectionId
                                    };
                        marketToUpdate.runners.Add(r);
                    }
                    else
                    {
                        Collections.Selection r = marketToUpdate.runners[indexNo];
                        r.asianLineId = runner.asianLineId;
                        r.handiCap = runner.handicap;
                        r.name = runner.name;
                        r.selectionId = runner.selectionId;
                        marketToUpdate.runners[indexNo] = r;
                    }
                }

                return CheckForEmtyRunnerInstances(marketToUpdate);
            }
            return null;
        }
Example #12
0
        /// <summary>
        /// The API GetMarket service allows the customer to input a
        /// Market ID and retrieve all static market data for the
        /// market requested. To get a Market ID for the betting
        /// market associated with an event you are interested in,
        /// use the GetEvents command.
        /// </summary>
        /// <param name="exchangeId">The exchange id.</param>
        /// <param name="marketId">The market id.</param>
        /// <returns></returns>
        public Market GetMarketObject(int exchangeId, int marketId)
        {
            BetfairExchangeAPI.Market bfMarket = GetMarket(exchangeId, marketId);
            var marketToUpdate = new Market();

            if (bfMarket != null)
            {
                marketToUpdate.apiMarketDataLastRefresh = bfMarket.lastRefresh;
                marketToUpdate.bspMarket          = bfMarket.bspMarket;
                marketToUpdate.country            = bfMarket.countryISO3;
                marketToUpdate.currency           = _currency;
                marketToUpdate.discountAllowed    = bfMarket.discountAllowed;
                marketToUpdate.eventDate          = bfMarket.marketTime;
                marketToUpdate.eventHierarchy     = bfMarket.eventHierarchy;
                marketToUpdate.eventTypeId        = bfMarket.eventTypeId;
                marketToUpdate.exchangeId         = exchangeId;
                marketToUpdate.lastMarketInfoLoad = DateTime.Now;
                marketToUpdate.marketBaseRate     = bfMarket.marketBaseRate;
                marketToUpdate.marketId           = marketId;
                marketToUpdate.marketInformation  = bfMarket.marketDescription;
                marketToUpdate.name              = bfMarket.name;
                marketToUpdate.numberOfRunners   = bfMarket.runners.Length;
                marketToUpdate.numberOfWinners   = bfMarket.numberOfWinners;
                marketToUpdate.runnersMayBeAdded = bfMarket.runnersMayBeAdded;
                marketToUpdate.status            =
                    (MarketStatus)Enum.Parse(typeof(MarketStatus), bfMarket.marketStatus.ToString());
                marketToUpdate.type     = bfMarket.marketType.ToString();
                marketToUpdate.menuPath = bfMarket.menuPath;

                if (marketToUpdate.runners == null)
                {
                    marketToUpdate.runners = new SelectionList();
                }

                foreach (var runner in bfMarket.runners)
                {
                    var indexNo = marketToUpdate.runners.GetRunnerIndexNoBySelectionId(runner.selectionId);

                    if (indexNo < 0)
                    {
                        var r = new Collections.Selection
                        {
                            asianLineId = runner.asianLineId,
                            handiCap    = runner.handicap,
                            name        = runner.name,
                            selectionId = runner.selectionId
                        };
                        marketToUpdate.runners.Add(r);
                    }
                    else
                    {
                        Collections.Selection r = marketToUpdate.runners[indexNo];
                        r.asianLineId = runner.asianLineId;
                        r.handiCap    = runner.handicap;
                        r.name        = runner.name;
                        r.selectionId = runner.selectionId;
                        marketToUpdate.runners[indexNo] = r;
                    }
                }

                return(CheckForEmtyRunnerInstances(marketToUpdate));
            }
            return(null);
        }
        /// <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;
        }
Example #14
0
 /// <summary>
 /// Resets the control data.
 /// </summary>
 public void UpdateControl(Market market)
 {
     MarketData = market;
 }
        /// <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);
            }
        }
Example #16
0
        /// <summary>
        /// Extract the results of a Betfair GetAllMarketsResp.data string to a MarketList object
        /// </summary>
        /// <param name="marketData"></param>
        /// <returns></returns>
        public MarketList ConvertToObject(string marketData)
        {
            if (marketData != null)
            {
                //Step 1 - Create the response object
                var marketList = new MarketList();

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

                //Step 3 - Split the markets out
                string[] marketStringArray = marketData.Split(":".ToCharArray());

                //Step 4 - Loop through the markets and split out the market items
                for (int x = 0; x < marketStringArray.Length; x++)
                {
                    //Check that the array is not empty
                    if (marketStringArray[x].Length > 0)
                    {
                        //Create the market object
                        var market = new Market();

                        //Step 5 - Split out the markets component items
                        string[] marketItemsStringArray = marketStringArray[x].Split("~".ToCharArray());

                        //Step 6 - Check that the array is equal or greater than 15
                        if (marketItemsStringArray.Length >= 15)
                        {
                            //Step 7 - Restore the break characters
                            for (int y = 0; y < marketItemsStringArray.Length; y++)
                            {
                                marketItemsStringArray[y] = HelperMethods.RestoreBreakChars(marketItemsStringArray[y]);
                            }

                            //Step 8 - Update the market values
                            market.marketId = Convert.ToInt32(marketItemsStringArray[0]);
                            market.name = marketItemsStringArray[1];
                            market.type = marketItemsStringArray[2];
                            market.status = (MarketStatus) Enum.Parse(typeof (MarketStatus), marketItemsStringArray[3]);
                            market.eventDate =
                                new DateTimeCalculations().UnixTimeStampToDateTime(
                                    Convert.ToDouble(marketItemsStringArray[4]));
                            market.menuPath = marketItemsStringArray[5];
                            market.eventHierarchy = HelperMethods.SplitToInt32Array("/", marketItemsStringArray[6]);
                            market.betDelay = Convert.ToInt32(marketItemsStringArray[7]);
                            market.exchangeId = Convert.ToInt32(marketItemsStringArray[8]);
                            market.country = marketItemsStringArray[9];
                            market.apiMarketDataLastRefresh = Convert.ToInt64(marketItemsStringArray[10]);
                            market.numberOfRunners = Convert.ToInt32(marketItemsStringArray[11]);
                            market.numberOfWinners = Convert.ToInt32(marketItemsStringArray[12]);
                            market.totalAmountMatched = Convert.ToDouble(marketItemsStringArray[13]);
                            if (marketItemsStringArray[14].ToLower() == "y") market.bspMarket = true;
                            if (marketItemsStringArray[15].ToLower() == "y") market.turningInPlay = true;

                            //Step 9 - Add the new market item to the response object
                            marketList.Add(market);
                        }
                    }
                }

                //Step 10 - Sort the list items
                marketList.Sort(new MarketDateComparer());

                //Step 11 - Done
                return marketList;
            }
            return null;
        }