Announcement

Collapse
No announcement yet.

Retrieving the Price for a Horse Error - Undefined property: stdClass::$ex

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieving the Price for a Horse Error - Undefined property: stdClass::$ex

    Hello there, hope everyone is well.

    I am after a bit of advice if possible. I am in the process of learning the API-NG platform, using PHP as my language of choice. Using the sample code as a basis I am trying to request the price for the favourite in a horse race. However, every time I request it I am greeted with an 'Undefined property: stdClass::$ex, error, followed by a 'Trying to get property 'availableToBack' of non-object' error, and then finally with a 'Trying to get property 'price' of non-object'.

    Specifically the line of code which is causing the error is as follows:

    PHP Code:
    echo "\n\n8. Place a bet ....\n";
    $betResult placeBet($APP_KEY$SESSION_TOKEN$nextHorseRacingMarket->marketId$nextHorseRacingMarket->runners[0]->selectionId$betAmount$nextHorseRacingMarket->runners[0]->ex->availableToBack->price); 
    PHP Code:
    function placeBet($appKey$sessionToken$marketId$selectionId$betAmount$betPrice)
    {

    $params '{"marketId":"' $marketId '",
    "instructions":
    [{"selectionId":"' 
    $selectionId '",
    "handicap":"0",
    "side":"BACK",
    "orderType":
    "LIMIT",
    "limitOrder":{"size":"' 
    $betAmount '",
    "price":"' 
    $betPrice '",
    "persistenceType":"LAPSE"}
    }], "customerRef":"fsdf"}'
    ;

    $jsonResponse sportsApingRequest($appKey$sessionToken'placeOrders'$params);

    return 
    $jsonResponse[0]->result;


    My '$betAmount' is set by myself earlier in the code, and I am attempting to get the price of the favourite into '$betPrice' by delving deep into the MarketBookList method using '$nextHorseRacingMarket->runners[0]->ex->availableToBack->price'.

    I assumed this would populate my variable with the price I was looking for, but sadly it keeps throwing an error.

    Any advice on how I can either fix the error or retrieve the price would be much appreciated (many an hour wasted trying to troubleshoot, and my weary eyes can't seem to see it. I thank you in advance for any assistance.

    For reference, please see below for my full code, which again is just a slightly modified version of the PHP sample code.

    PHP Code:
    $APP_KEY $argv[1];
    $SESSION_TOKEN $argv[2];

    function 
    getAllEventTypes($appKey$sessionToken)
    {

    $jsonResponse sportsApingRequest($appKey$sessionToken'listEventTypes''{"filter":{}}');

    return 
    $jsonResponse[0]->result;

    }

    function 
    extractHorseRacingEventTypeId($allEventTypes)
    {
    foreach (
    $allEventTypes as $eventType) {
    if (
    $eventType->eventType->name == 'Horse Racing') {
    return 
    $eventType->eventType->id;
    }
    }

    }

    function 
    getNextUkHorseRacingMarket($appKey$sessionToken$horseRacingEventTypeId)
    {

    $params '{"filter":{"eventTypeIds":["' $horseRacingEventTypeId '"],
    "marketCountries":["GB"],
    "marketTypeCodes":["WIN"],
    "marketStartTime":{"from":"' 
    date('c') . '"}},
    "sort":"FIRST_TO_START",
    "maxResults":"1",
    "marketProjection":["RUNNER_DESCRIPTION"]}'
    ;

    $jsonResponse sportsApingRequest($appKey$sessionToken'listMarketCatalogue'$params);

    return 
    $jsonResponse[0]->result[0];
    }

    function 
    printMarketIdAndRunners($nextHorseRacingMarket)
    {

    echo 
    "MarketId: " $nextHorseRacingMarket->marketId "\n";
    echo 
    "MarketName: " $nextHorseRacingMarket->marketName "\n\n";

    foreach (
    $nextHorseRacingMarket->runners as $runner) {
    echo 
    "SelectionId: " $runner->selectionId " RunnerName: " $runner->runnerName "\n";
    }

    }


    function 
    getMarketBook($appKey$sessionToken$marketId)
    {
    $params '{"marketIds":["' $marketId '"], "priceProjection":{"priceData":["EX_BEST_OFFERS"]}}';

    $jsonResponse sportsApingRequest($appKey$sessionToken'listMarketBook'$params);

    return 
    $jsonResponse[0]->result[0];
    }


    function 
    printMarketIdRunnersAndPrices($nextHorseRacingMark et$marketBook)
    {

    function 
    printAvailablePrices($selectionId$marketBook)
    {

    // Get selection
    foreach ($marketBook->runners as $runner)
    if (
    $runner->selectionId == $selectionId) break;

    echo 
    "\nAvailable to Back: \n";
    foreach (
    $runner->ex->availableToBack as $availableToBack)
    echo 
    $availableToBack->size "@" $availableToBack->price " | ";

    }


    echo 
    "MarketId: " $nextHorseRacingMarket->marketId "\n";
    echo 
    "MarketName: " $nextHorseRacingMarket->marketName;

    foreach (
    $nextHorseRacingMarket->runners as $runner) {
    echo 
    "\n\n\n=========================================== ====================================\n";

    echo 
    "SelectionId: " $runner->selectionId " RunnerName: " $runner->runnerName "\n";
    echo 
    printAvailablePrices($runner->selectionId$marketBook);
    }
    }

    function 
    placeBet($appKey$sessionToken$marketId$selectionId$betAmount$betPrice)
    {

    $params '{"marketId":"' $marketId '",
    "instructions":
    [{"selectionId":"' 
    $selectionId '",
    "handicap":"0",
    "side":"BACK",
    "orderType":
    "LIMIT",
    "limitOrder":{"size":"' 
    $betAmount '",
    "price":"' 
    $betPrice '",
    "persistenceType":"LAPSE"}
    }], "customerRef":"fsdf"}'
    ;

    $jsonResponse sportsApingRequest($appKey$sessionToken'placeOrders'$params);

    return 
    $jsonResponse[0]->result;



  • #2
    Eeeek! A bit of a test for my Haven't-Done-PHP-In-Years brain...

    I can't see how/where you work out which horse is the favourite.

    It may not be relevant, but there may be no available-to-back amounts and odds for some horses, and I can't see where you deal with that.
    Last edited by jabe; 04-04-2021, 11:37 PM.

    Comment


    • #3
      Just had another look at this. When your PlaceBet function is called, $betPrice should be passed to the function, but there is nowhere in your code where anything is put into that variable. I assume it's meant to be the best available to back odds for the favourite.

      Comment


      • #4
        I’ve attended two of your threads, and I am impressed with the knowledge shared by your team. You share some practical knowledge they follow, which is very helpful. But you should know more about software development. I recommend consult with https://mlsdev.com
        Last edited by Mirco; 12-04-2021, 04:14 PM.

        Comment


        • #5
          I will show this piece of code to my Computools team - I think they will find a solution, because I myself can not suggest anything unfortunately

          Comment

          Working...
          X