Cant get CancelBets API call to work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • geoffw123
    Senior Member
    • Mar 2014
    • 250

    #1

    Cant get CancelBets API call to work

    Hi

    Newbie here with the Betfair API and C# to an extent too. I am trying to add some new functionality to the C# example from this forum. I got a call such as API getBet to work OK and return the details of a single bet. However, I cant get the cancelBets call to work, it always returns TAKEN_OR_LAPSED for each of the individual bets in the array(I am just trying to cancel 1 bet in array index 0). I create an unmatched bet via either Cymatic or the website and then get the bet ID from Cymatic of the bet I am trying to cancel. (For now just hard coded that ID into my code)

    I think I have set the request up correctly and populated the array, but I must be missing something obvious. here is my code snippets.

    Code:
          public bool myCancelBets(ref CancelBetsResp response, CancelBets[] bets)
          {
             bool bRetCode;
             const string serviceName = "cancelBets";
    
             var request = new CancelBetsReq();
             request.bets = bets;
    
             request.header = _exchReqHdr;
    
             response = _bfExchange.cancelBets(request);
    
             bRetCode = CheckResponse(serviceName,
                                         Convert.ToString(response.header.errorCode),
                                         Convert.ToString(response.errorCode),
                                         response.header.sessionToken);
    
             if (bRetCode == false)
                return false;
    
             return true;
          }
    Then tested with
    Code:
       private void button1_Click(object sender, EventArgs e)
       {
          CancelBets[] bets =  new CancelBets[40];
    
          CancelBetsResp Response = new CancelBetsResp();
    
          for (int i=0; i < bets.Length ; i++ )
          {
             bets[i] = new CancelBets();
          }
    
          bets[0].betId = 37198397685;
    
          MyBetfair.myCancelBets(ref Response, bets);
       }
    Can anyone spot what I am doing wrong ?

    Thanks for any help

    Regards Geoff
  • betdynamics
    Junior Member
    • Sep 2010
    • 534

    #2
    I think you may need to specify the marketId if you are trying to cancel a specific bet.

    Comment

    • geoffw123
      Senior Member
      • Mar 2014
      • 250

      #3
      Originally posted by betdynamics View Post
      I think you may need to specify the marketId if you are trying to cancel a specific bet.
      Hi

      Thanks for the reply, I have checked the API docs, unless I am missing it I don't think it needs the market ID, I cant find a market ID field anywhere in the request ? Could you be more specific please ?

      Also the errorCode property in the response I get says "OK". Its only the specific bet array slot that has the "TAKEN_OR_LAPSED" error.

      I am guessing its more to do with the way I have set up my request bets array. Is there a way to specify that I am only using one bet entry in the array. At the moment I have a 40 element array where the last 39 have a 0 betID reference.

      Any other ideas ?

      Geoff

      Comment

      • betdynamics
        Junior Member
        • Sep 2010
        • 534

        #4
        Sorry - didn't realise you are using the old API.

        Why not just declare the array as:

        Code:
        CancelBets[] bets =  new CancelBets[1];
        Last edited by betdynamics; 10-05-2014, 08:24 PM.

        Comment

        • geoffw123
          Senior Member
          • Mar 2014
          • 250

          #5
          Hi

          Solved !! Thanks for the clue, that was the problem, I had wrongly assumed as the API docs mentioned an array of 40 bets you had to create and pass an array of size 40 regardless.

          That breaks it, for it to work the array must be sized to the number of bets you wish to cancel. Soon as I did that it worked fine.

          Thanks again for the help

          Geoff

          Comment

          Working...
          X