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:
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.
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;
}
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;
}


Comment