MarketTime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Burdett
    Junior Member
    • Sep 2012
    • 29

    #1

    MarketTime

    Hi

    Getting an object set to null reference, when accessing the market time. My code is below. Is there something wrong with my filters? I'm trying to get a list together of MarketIDs and their respective start times for the day.

    Any help appreciated, probably something stupid I'm overlooking. Thanks.


    public static List<MarketCatalogue> myCatalogueToday(IClient myClient)
    {

    ISet<string> eventypeIds = new HashSet<string>();

    eventypeIds.Add("4339"); // Note 4339 for dogs
    // eventypeIds.Add("7");//horse racing.
    //ListMarketCatalogue: Get next available horse races, parameters:
    var time = new TimeRange();
    time.From = DateTime.Now;
    time.From = time.From.Add(new TimeSpan(0, -2, 0));
    time.To = DateTime.Now.AddHours(18);

    var marketFilter = new MarketFilter();

    marketFilter = new MarketFilter();
    marketFilter.EventTypeIds = eventypeIds;

    marketFilter.MarketStartTime = time;




    //market countries appears to be the location of the events (not legal betting territories)
    marketFilter.MarketCountries = new HashSet<string>() { "GB", "IE" }; //,, "AU" "US",,, ,"FR", "AU" us,"FR", "ZA","SG", "IE", "NZ", "UA", "IN"
    marketFilter.MarketTypeCodes = new HashSet<String>() { "WIN" };

    var marketSort = MarketSort.FIRST_TO_START;


    var maxResults = "120";

    //as an example we requested runner metadata
    ISet<MarketProjection> marketProjections = new HashSet<MarketProjection>();
    marketProjections.Add(MarketProjection.RUNNER_META DATA);
    marketProjections.Add(MarketProjection.RUNNER_DESC RIPTION);

    Console.WriteLine("\nGetting todays catalogue");




    var myList = myClient.listMarketCatalogue(marketFilter, marketProjections, marketSort, maxResults);


    List<MarketCatalogue> myMarketCatalogue = new List<MarketCatalogue>();
    MarketCatalogue Sole = new MarketCatalogue();
    for (int i = 0; i < myList.Count; i++)
    // for (int i = 0; i < 1; i++)
    {
    Sole.MarketId = myList[i].MarketId;
    Sole.MarketName = myList[i].MarketName;
    Sole.IsMarketDataDelayed = myList[i].IsMarketDataDelayed;
    Sole.Runners = myList[i].Runners;
    Sole.Description = myList[i].Description;
    Sole.EventType = myList[i].EventType;
    Sole.Event = myList[i].Event;
    Sole.Competition = myList[i].Competition;


    myMarketCatalogue.Add(Sole);
    }

    return myMarketCatalogue;
    }

    //////////////////////////////////////////////////////////////////////////////////////////////Main Progam/////////////////////////////////////////////////////////////////////////////
    for (int i = 0; i < TodaysCatalogue.Count(); i++)
    {
    //code below is ok
    string A = TodaysCatalogue[i].MarketId;


    Console.WriteLine(A);
    // faulty code next line, returns System.NullReferenceException: 'Object reference not set to an instance of an object.' MarketCatalogue.Description.get returned null.
    Console.WriteLine(" "+TodaysCatalogue[0].MarketId + " " + TodaysCatalogue[0].Description.MarketTime+"");

    }

  • WTPooh
    Member
    • May 2012
    • 88

    #2
    marketProjections.Add(MarketProjection.MARKET_STAR T_TIME);

    Comment

    • Burdett
      Junior Member
      • Sep 2012
      • 29

      #3
      It seems what I now need is the code for object MARKET_START_TIME.
      I don't have it with my original set-up. Perhaps its later edition; but I know it will look something like its cousin: Market Desription.


      public class MarketDescription
      {
      [JsonProperty(PropertyName = "persistenceEnabled")]
      public bool IsPersistenceEnabled { get; set; }

      [JsonProperty(PropertyName = "bspMarket")]
      public bool IsBspMarket { get; set; }

      [JsonProperty(PropertyName = "marketTime")]
      public DateTime MarketTime { get; set; }

      [JsonProperty(PropertyName = "suspendTime")]
      public DateTime? SuspendTime { get; set; }

      [JsonProperty(PropertyName = "settleTime")]
      public DateTime? SettleTime { get; set; }

      [JsonProperty(PropertyName = "bettingType")]
      public MarketBettingType BettingType { get; set; }

      [JsonProperty(PropertyName = "turnInPlayEnabled")]
      public bool IsTurnInPlayEnabled { get; set; }

      [JsonProperty(PropertyName = "marketType")]
      public string MarketType { get; set; }

      [JsonProperty(PropertyName = "regulator")]
      public string Regulator { get; set; }

      [JsonProperty(PropertyName = "marketBaseRate")]
      public double MarketBaseRate { get; set; }

      [JsonProperty(PropertyName = "discountAllowed")]
      public bool IsDiscountAllowed { get; set; }

      [JsonProperty(PropertyName = "wallet")]
      public string Wallet { get; set; }

      [JsonProperty(PropertyName = "rules")]
      public string Rules { get; set; }

      [JsonProperty(PropertyName = "rulesHasDate")]
      public bool RulesHasDate { get; set; }

      [JsonProperty(PropertyName = "clarifications")]
      public string Clarifications { get; set; }

      public override string ToString()
      {
      return new StringBuilder().AppendFormat("{0}", "MarketDescription")
      .AppendFormat(" : BspMarket={0}", IsBspMarket)
      .AppendFormat(" : BettingType={0}", BettingType)
      .AppendFormat(" : MarketType={0}", MarketType)

      .AppendFormat(" : MarketTime={0}", MarketTime)
      .AppendFormat(" : SuspendTime={0}", SuspendTime)
      .AppendFormat(" : SettleTime={0}", SettleTime)
      .AppendFormat(" : MarketBaseRate={0}", MarketBaseRate)

      .AppendFormat(" : IsPersistenceEnabled={0}", IsPersistenceEnabled)
      .AppendFormat(" : IsTurnInPlayEnabled={0}", IsTurnInPlayEnabled)
      .AppendFormat(" : IsDiscountAllowed={0}", IsDiscountAllowed)

      .AppendFormat(" : Regulator={0}", Regulator)
      .AppendFormat(" : Rules={0}", Rules)
      .AppendFormat(" : RulesHasDate={0}", RulesHasDate)
      .AppendFormat(" : Clarifications={0}", Clarifications)

      .AppendFormat(" : Wallet={0}", Wallet)
      .ToString();
      }
      }
      }

      Comment

      • WTPooh
        Member
        • May 2012
        • 88

        #4
        MarketProjection.cs
        Code:
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using Newtonsoft.Json;
        using Newtonsoft.Json.Converters;
        
        namespace Api_ng_sample_code.TO
        {
            [JsonConverter(typeof(StringEnumConverter))]
            public enum MarketProjection
            {
                COMPETITION, EVENT, EVENT_TYPE, [B]MARKET_START_TIME[/B], MARKET_DESCRIPTION, RUNNER_DESCRIPTION, RUNNER_METADATA 
            }
        }

        Comment

        • JohnFromCairnsAustralia
          Junior Member
          • Dec 2018
          • 34

          #5
          Looks like the API-NG sample code hasn't been updated. I'm just working through it myself, looks like there is a fair few outdated changes.

          https://github.com/betfair/API-NG-sa...ng-sample-code

          Does anyone have any updated sample code, or you guys just modify it manually?

          Comment

          • MarkInLondon
            Junior Member
            • Aug 2019
            • 3

            #6
            Forgive me if I've misunderstood the question and/or not read it properly. Below is a cut-down version of one of the methods I use to return a filter, which requests today's Horse Races (WIN only markets) with an optional country code.

            Code:
            [FONT=courier new]        public static MarketFilter HorseRaceFilter(string country = null)
                    {
                        var marketFilter = new MarketFilter();
                        marketFilter.EventTypeIds = new HashSet<string>() { "7" };
                        marketFilter.MarketStartTime = new TimeRange()
                        {
                            From = DateTime.Now,
                            To = DateTime.Now.AddDays(1)
                        };
                        if (country != null)
                            marketFilter.MarketCountries = new HashSet<string>() { country };
                        marketFilter.MarketTypeCodes = new HashSet<String>() { "WIN" };
            
                        return marketFilter;
                    }[/FONT]
            And this is how I call that method, along with other properties, which are not relevant for this post:

            Code:
                    public List<MarketCatalogue> GetTodaysRaces()
                    {
                        List<MarketCatalogue> returnValue = new List<MarketCatalogue>();
            
                        try
                        {
                            // retrieve from the config file, the maximum number of markets we want to retrieve
                            int.TryParse
                            (BetfairAPIHelper.Helper.ValidateStringConfigValueExists
                                    (ConfigurationManager.AppSettings
                                        ["ListMarketCatalogueMaximumResults"], "ListMarketCatalogueMaximumResults"),
                                        out int listMarketCatalogueMaximumResults
                            );
            
                            // call the streaming api helper on the api dll to retrieve a list of all horse racing
                            // markets for today
                            returnValue = _client.ListMarketCatalogue
                            (
                                BFHelpers.HorseRaceFilter(),
                                minimalHorseRaceProjection(),
                                MarketSort.FIRST_TO_START,
                                listMarketCatalogueMaximumResults
                            );
                        }
            
                        catch (Exception ex)
                        {
                            // propagate this exception to the calling method - also, use MethodScraper to generate
                            // the exception message, inlcuding: the current assembly, class and method names,
                            // together with any method parameters and their values
                            throw new Exception(new MethodScraper(ex).GetExceptionMessage());
                        }
            
                        return returnValue;
                    }

            Comment

            • Sasuke2690
              Banned
              • Aug 2022
              • 1

              #7
              Originally posted by MarkInLondon View Post
              Forgive me if I've misunderstood the question and/or not read it properly. Below is a cut-down version of one of the methods I use to return a filter, which requests today's Horse Races (WIN only markets) with an optional country code.

              Code:
              [FONT=courier new] public static MarketFilter HorseRaceFilter(string country = null)
              {
              var marketFilter = new MarketFilter();
              marketFilter.EventTypeIds = new HashSet<string>() { "7" };
              marketFilter.MarketStartTime = new TimeRange()
              {
              From = DateTime.Now,
              To = DateTime.Now.AddDays(1)
              };
              if (country != null)
              marketFilter.MarketCountries = new HashSet<string>() { country };
              marketFilter.MarketTypeCodes = new HashSet<String>() { "WIN" };
              
              return marketFilter;
              }[/FONT]
              And this is how I call that method, along with other properties, which are not relevant for this post:

              Code:
              public List<MarketCatalogue> GetTodaysRaces()
              {
              List<MarketCatalogue> returnValue = new List<MarketCatalogue>();
              
              try
              {
              // retrieve from the config file, the maximum number of markets we want to retrieve
              int.TryParse
              (BetfairAPIHelper.Helper.ValidateStringConfigValueExists
              (ConfigurationManager.AppSettings
              ["ListMarketCatalogueMaximumResults"], "ListMarketCatalogueMaximumResults"),
              out int listMarketCatalogueMaximumResults
              );
              
              // call the streaming api helper on the api dll to retrieve a list of all horse racing
              // markets for today
              returnValue = _client.ListMarketCatalogue 
              (
              BFHelpers.HorseRaceFilter(),
              minimalHorseRaceProjection(),
              MarketSort.FIRST_TO_START,
              listMarketCatalogueMaximumResults
              );
              }
              
              catch (Exception ex)
              {
              // propagate this exception to the calling method - also, use MethodScraper to generate
              // the exception message, inlcuding: the current assembly, class and method names,
              // together with any method parameters and their values
              throw new Exception(new MethodScraper(ex).GetExceptionMessage());
              }
              
              return returnValue;
              }
              The answer is quite good and easy to understand
              spider solitaire 2 suit
              Last edited by Sasuke2690; 16-08-2022, 05:38 AM.

              Comment

              Working...
              X