Forums

We want to share an important update with our Betfair Community users.

Over the coming months, the Betfair Community platform will be winding down. The final active day for the platform will be December 21st. From December 22nd, users will no longer be able to access the platform.

Your discussions, insights, engagement, and, most importantly, feedback have helped shape the platform and guided innovation. Your feedback continues to be important to us, and we will continue to listen via our dedicated feedback channels, as well as through product testing and innovations.

To share your feedback and experience, visit: https://support.betfair.com/app/home

General Betting

There is currently 1 person viewing this thread.
scrooge_mcduck
05 Nov 10 00:17
Joined:
Date Joined: 24 Apr 08
| Topic/replies: 899 | Blogger: scrooge_mcduck's blog
I've finally decided to learn how to use the betfair APi using php and all was going quite well until I tried using the getMUbets function to return a listof markets I have bets on. I just can't seem to get it work! :(

I'd really appreciate any pointers on where I'm going wrong please. Here is my code:

function GetBets ($session){
    global $betfairlibrary;
     
    $response = $betfairlibrary->betfair_exchange_api-> betfair_get_MUbets_lite ($session); 
    return $response;
}

    $existing_bets = GetBets($session);
     
    foreach ($existing_bets as $existing_bet ){
      foreach($existing_bet->Result->betLites as $e) {
        print"Existing bets ".$e->marketId." \n ";
      }
    }

Post your reply

Text Format: Table: Smilies:
Forum does not support HTML
Insert Photo
Cancel
sort by:
Show
per page
Replies: 19
By:
FINE AS FROG HAIR
When: 05 Nov 10 00:35
Cue Escapee.
By:
scrooge_mcduck
When: 05 Nov 10 00:45
Ah, he's the man to help me is he?!

I'm struggling with looping through the arrays returned but as far as I can see this is set up the same way the placebets function is and this works. I di have parameters passed in but it looks from the code that these are automatically set if not specified in this function. Really appreciate any help from those in te know on tis as I've been trying for days now trying to get this to work! :(
By:
Escapee
When: 05 Nov 10 01:53
Well I've never seen PHP before let alone understand it's syntax so I don't think I'm the person you want really.... Cue Fred! ( as FAFH puts it )


So bearing in mind I no nothing about PHP..... I think there are a number of thing wrong with your code.

1) Header ?
you do not appear to have assigned an api header to $session, ( you probably did this outside the code shown )

2) The betfair_get_MUbets_lite() call requires 5 mandatory parameters set before it returns any data, namely:
a) betStatus, try "MU" for matched and unmatched bets
b) orderBy, try BET_ID but there are others
c) recordCount, try 100
d) sortOrder, try DESC or ASC
e) startRecord, try 0

You don't appear to be setting these and that is the main cause of your problem.


3) Your loop to extract and print the data seems incorrect in that it is refering to structures not returned by betfair_get_MUbets_lite
This is where you really need Fred! for the specifics as the naming conventions for PHP are different to other languages ( I know that much about PHP ) but I'll outline a guesstimate of what I think it should be you maybe able to work it out yourself.

$existing_bets = GetBets($session);
/* test header->errorCode here */
foreach ($existing_bets->betLites as $betLite )
{

    print"MUBetLite BetId  ".$betLite->betId." \n ";

}

4) You really should be testing and checking the header->errorCode after every api call to confirm the call succeeded or not.




Hope this helps, but if not then you'll have to wait for a knowledgeable PHP bod to come along.
By:
scrooge_mcduck
When: 05 Nov 10 02:49
Thanks for taking the time to look at this Escapee, really appreciate it.

The session variable is set outside this code and is being passed through ok for my other functions so I don't think that's the problem.

I did set all the mandatory params but when I checked the function declaration it looked like these were set by default but I've added these back in now. I think it is the looping through the structures that is causing a problem. Maybe I don't need the 'result' bit but the other working functions all seem to have this in their output. I definitely need to read up a bit more on these structures but they're proving pretty tough to understand for a novice like me!

Thanks again for your suggestions, The code is still not working  but has now been updated to the following in case anyone else thinks they may be able to help:


function GetBets ($session){
    global $betfairlibrary;
   
        $betparams =  array(
        array(     
                       'betStatus' => 'MU',
                    'orderBy' => 'BET_ID',
                    'recordCount' => 100,
                    'sortOrder' => 'DESC',
                    'startRecord' => 0,

                    )
                );
   
    return $betfairlibrary->betfair_exchange_api-> betfair_get_MUbets_lite ($session,$betparams);


  $existing_bets = GetBets($session);

  foreach ($existing_bets->betLites as $betLite )
  {
    print"MUBetLite BetId  ".$betLite->betId." \n ";
  }

I am testing this over a web page andknow little about debugging either so if anyone has any tips about how I can best do this too taht would be great!

Cheers
By:
FINE AS FROG HAIR
When: 05 Nov 10 03:09
Mr mc duck
Escapee is no scrooge when it comes to giving free, voluntary advice on coding problems.
By:
Escapee
When: 05 Nov 10 03:47
This bit can't be right surely ?

       $betparams =  array(
        array(     
                       'betStatus' => 'MU',
                    'orderBy' => 'BET_ID',
                    'recordCount' => 100,
                    'sortOrder' => 'DESC',
                    'startRecord' => 0,

                    )
                );



I've seen some mad languages and syntax in my time but if PHP were like this then I can't see how it would've been let out of the mental hospital.

I think your best bet is to go to the PHP section of the developers forum and trawl that for some examples.



You mention that you had placebets working, if you post all the parts for that where you assign the header, session token, bet to be placed, call to placebet and how you deals with its response then I might be able to extrapolate a solution from the working bit(s).


or wait and hope someone appears tommorow who knows PHP & the api calls
By:
Escapee
When: 05 Nov 10 04:36
try This......
Place this code after bit where you log on



global $betfairlibrary;  /* Maybe you all ready have betfairlibrary declared previously ? */



$Mybets =  $betfairlibrary->betfair_exchange_api->betfair_get_MUbets_lite($session, '' );

foreach ($Mybets->betLites as $betLite )
{

    print"MUBetLite BetId  ".$betLite->betId." \n ";

}


This should give you the first 5 of your existing matched or unmatched bets.


let me know if I've cracked PHP
By:
Escapee
When: 05 Nov 10 04:38
didn't like this line when I posted it


$Mybets = $betfairlibrary->
betfair_exchange_api->
betfair_get_MUbets_lite($session, '' );



Join it up to one line in your code
By:
Escapee
When: 05 Nov 10 04:39
($session, '' ); this is two single quotes
By:
FINE AS FROG HAIR
When: 05 Nov 10 04:46
Give up escapee, you're out of your depth.
Please, please believe me when I say I'm just joking.
By:
Escapee
When: 05 Nov 10 05:10
You're right though FAFH, I know faq all about PHP and well out of my depth.

I had nothing to do during this current session of insomnia so I thought I'd give it a spin to take my mind off other things.

It appears mcDuck has gone to bed, so I'll have to wait to find out if I've managed to shelock my way into understanding and remedying the problem.

aah well...
By:
FINE AS FROG HAIR
When: 05 Nov 10 06:08
Escapee when you come back on after your most recent fight to try to get some decent sleep, please could you answer the following.
As you know I'm no coder ( in fact I'm essentially computer illiterate) but when I read a book about say the Facebook founder or see the film just made, I ask myself how briliant are these types of people at writing code ?.
Are they off the wall creative, really uniquey clever individuals, or are they just in the right place at the right time with the right idea.
I can't judge any of this for myself, as the world they are involved is totally alien to me.
But to you? I would expect not.
By:
scrooge_mcduck
When: 05 Nov 10 10:49
Solved it!You're a legend Escapee, thanks very much!

Your call to betfairlibrary worked and although I still didn't have the structure correct (still needed the result arrray and an extra pointer to MUBetLite, I was able to dump out the whole array and see how it was stuctured. Here is the working code now...

    $Mybets = $betfairlibrary->betfair_exchange_api-> betfair_get_MUbets_lite($session,'');

    print_r($Mybets);

    foreach ($Mybets->Result->betLites->MUBetLite as $betLite)
    {
        print" session ".$session."\n ";
        print"Bet: ".$betLite->marketId;
    }
By:
scrooge_mcduck
When: 05 Nov 10 10:50
Very pleased with this. I urge anyone to give the API a try, even if you don't have much coding experince as it's great fun!

We can all get some more sleep now :)
By:
Zola's Back Heel
When: 05 Nov 10 11:55
scrooge - if you are serious about getting into the API it would be worth your while investigating java.
Download the netbeans dev environment and the java examples off the bdp. google "java betfair examples" too.

if you can get your head around php, then java should not too much more effort. and you will get A LOT MORE out of it.
By:
scrooge_mcduck
When: 05 Nov 10 14:35
Thanks for the advice Zola, I reckon that'll be my next step.

Not done any Java since my uni days but I'm sure I can master it!
By:
Zola's Back Heel
When: 05 Nov 10 15:02
well if you've done java before, i wouldn't slum it with php.
get cracking on your own desktop app with client-servlet arch!
By:
Escapee
When: 06 Nov 10 03:26
mcDuck, wha hey..... Bingo. [:)]


Fafh, I just managed to lose a long and wordy post on the subject you raised Sad, At the point of finishing it, betfair forum crapped out and it disappeared.... I don't think I have the heart at the moment to do it all again, another time and thread maybe. Interesting topic though and I'd love to know more about your own personal expreiences and journey from employee to professor pat pending ( as it were ).
By:
Fred!
When: 06 Nov 10 04:08
Sorry Escapee, I missed my cue. You did a fine job :)

Yes indeed scrooge, it's fun, mucking around with the API can be more fun than gambling.
sort by:
Show
per page

Post your reply

Text Format: Table: Smilies:
Forum does not support HTML
Insert Photo
Cancel
‹ back to topics
www.betfair.com