Filter by Horse Name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ghostbusters 2
    Junior Member
    • Apr 2015
    • 16

    #1

    Filter by Horse Name

    Hello,

    I've just started using the API and am new to it all!
    I'm doing something like this to filter upcoming races

    Code:
        $params = '{"filter":{"eventTypeIds":["' . $horseRacingEventTypeId . '"],
    	      "venues":["Brighton"],
                  "marketTypeCodes":["WIN"],
                  "marketStartTime":{"from":"' . date('c') . '"}},
                  "sort":"FIRST_TO_START",
                  "maxResults":"20",
                  "marketProjection": [
                    "MARKET_START_TIME",
                    "RUNNER_DESCRIPTION",
    		"RUNNER_METADATA",
                    "EVENT_TYPE",
                    "EVENT",
                    "COMPETITION"
    		]}';
    
        $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listMarketCatalogue', $params);
    However, as well as filtering by venue, I want to filter by horse name but I can't work out how do it.
    I looked at the link below for any way to filter the market by horse name but there wasn't anything that i saw.
    https://api.developer.betfair.com/se...s-MarketFilter

    More simply, all I'm trying to do is use the API to bet on a horse of a known name.

    I hope it's something simple I've missed. Thanks for any help!
  • Franklin1
    Junior Member
    • Mar 2012
    • 91

    #2
    I don't think this can be done because the runnerName field is not queried by the MarketFilter. I know it can be done in the betfair website search, but believe that query is different.

    You're going to need to look through the data returned by betfair for the runner yourself.

    I would suggest this as the leanest alternative:

    call listMarketCatalogue
    with:
    MarketFilter.eventTypeIds = '7' (horse racing)
    MarketProjection = RUNNER_DESCRIPTION
    maxResults=1000
    I would also recommend filtering on marketStartTime and marketTypeCodes (PLACE, WIN) depending on your requirements

    This call has a data request weight of 0 so will get you upto 1000 results. If get less than 1000 then you know you have an exhaustive list and this keeps things simple.

    Then you need to look through the MarketCatalogue.runners.runnerName items to find your horse.

    Comment

    • Ghostbusters 2
      Junior Member
      • Apr 2015
      • 16

      #3
      thanks for the reply.

      I've spent the day trying to use that, only am having issues interpreting the response! I think my php skills are very bad which doesn't help.

      The first function that I run is this

      Code:
      $AllHorseRacingMarket = getAllUkHorseRacingMarket($APP_KEY, $SESSION_TOKEN);
      function getAllUkHorseRacingMarket($appKey, $sessionToken)
      {
      
          $params = '{"filter":{"eventTypeIds":["7"],
      	      "venues":["Epsom"],
                    "marketTypeCodes":["WIN"],
                    "marketStartTime":{"from":"' . date('c') . '"}},
                    "sort":"FIRST_TO_START",
                    "maxResults":"1000",
                    "marketProjection": [
                      "RUNNER_DESCRIPTION"
      		]}';
      
          $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listMarketCatalogue', $params);
          print_r($jsonResponse);
          return $jsonResponse;//[0]->result[0];
      }
      and while it looks like an array to me, running a function on the results doesn't seem to agree.

      the code for the next function is

      Code:
      function printMarketIdAndRunners($AllHorseRacingMarket)
      {
      
      //THIS LOOP DOESNT WORK
          foreach ($AllHorseRacingMarket->marketId as $marketID) {
              echo "MarketId: " . $marketId . "\n";
          }
      
      
      //THIS LOOP WORKS when the return of the first function is set to return $jsonResponse[0]->result[0]; (i.e. looking at only the first market)
      //    foreach ($AllHorseRacingMarket->runners as $runner) {
      //       echo "SelectionId: " . $runner->selectionId . " RunnerName: " . $runner->runnerName . "\n";
      //    }
      }
      it didn't like the ->marketId (trying to get property of non object) so I changed it to ['marketId'] but that was still not good (undefined object)

      if anyone can help that would be much appreciated.

      Comment

      • Ghostbusters 2
        Junior Member
        • Apr 2015
        • 16

        #4
        as far as i can tell, in the first function, $JsonResponse is an array, but when it's returned into $AllHorseRacingMarket it's no longer an array.

        How do i get the results as an array?
        after that, i think I can just loop through the marketId's and then loop through those to get the runners...

        Comment

        • Franklin1
          Junior Member
          • Mar 2012
          • 91

          #5
          unforunately i don't know anything about php - just answered your first question because it was not really anything to do with php

          I can try and help with the concept, if that helps:
          the response you receive should be:


          List<MarketCatalogue>
          marketID
          other stuff
          List <RunnerCatalog>
          runnerName
          other stuff
          your loop which does work seems to be the correct method for looping through the $jsonResponse (which is List<MarketCatalogue>) and pulling marketID out.

          your second loop fails when you are running it on $jsonResponse (which is List<MarketCatalogue>) because .runner is not in MarketCatalogue. It seems it works when running it on $jsonResponse[0]->result[0] because this is getting you to List <RunnerCatalog>. I think the 'result' is named as such by your code.

          We need to do a nested loop through each market, then each runner.

          can you get this to work? (it's intended to be a loop which passes the whole MarketCatalogue into $market, as opposed to just the marketID)

          PHP Code:
          foreach ($AllHorseRacingMarket as $marketCatalogue) {
          echo 
          "MarketId: " $marketCatalogue->marketId  "\n";

          if this works the you just need to write another loop within this loop which looks through $marketCatalogue->result looking for runnerName
          Last edited by Franklin1; 23-04-2015, 01:27 PM. Reason: more info

          Comment

          • Ghostbusters 2
            Junior Member
            • Apr 2015
            • 16

            #6
            hi,
            thanks for the help!
            you're right about the nested loops, however, the first problem to solve was in the first function. I had to change the return line to
            Code:
            return $jsonResponse[0]->result;
            for the code to know that the response should be an array.
            the first function now sets $AllHorseRacingMarket to the value/array returned.
            After this, the nested loops work. I did the following for it to output race, followed by the runners in each race...

            Code:
            function printMarketIdAndRunners($AllHorseRacingMarket)
            {
            foreach ($AllHorseRacingMarket as $HorseRace){
            	echo "MarketId: " . $HorseRace->marketId . "Name: " . $HorseRace->marketName . "\n";
            	foreach($HorseRace->runners as $runner) {
                         echo "SelectionId: " . $runner->selectionId . " RunnerName: " . $runner->runnerName . "\n";
                    }
                }
            }
            hopefully this may help someone else.

            Comment

            • Franklin1
              Junior Member
              • Mar 2012
              • 91

              #7
              Excellent, well done

              Comment

              Working...
              X