Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vossie
    BDP Team
    • Sep 2008
    • 40

    #151
    Originally posted by Vreljanski View Post
    Quote:
    WE DO HAVE FULL API CONNECTED TO ONE ACCOUNT... HOW ON EARTH I SET THAT IN CODE AS WELL.
    I don’t understand this ???



    What I ment is we have one betfair account and that one has read only personal api connected to it... (I know cancel bets is not available)

    I plan to update that account to personal transactional api.

    So when i code, loging in using that account only wont work for me to have my api enabled... I have to provide product id or some other id for the code so it knows i am using some sort of registered api... right?

    How do I make that happen... what i put where... etc...

    I hope its now a bit more clear.

    thanks.
    Hi Vreljanski,

    Yes you can simply email BDP and we will process your request as required, you do know that each paying API subscription can have up to 5 sub-accounts associated with it. Simply go to https://console.bdp.betfair.com and login with the transactional account. Click on "API Subscriptions" -> "Personal Transactional" -> "Sub-accounts" and add the additional betfair accounts. Sub-accounts login with ProductId = 0, and a VendorSoftwareId that is provided through the My API Console.

    To answer your question simply change the productId and vendorSoftwareId values in your login routine.
    Last edited by vossie; 12-06-2009, 03:53 PM. Reason: Changed menu path description
    "Why don't you just fix your little problem and light this candle?" - Alan B. Shepard, Jr

    Comment

    • Vreljanski
      Junior Member
      • May 2009
      • 16

      #152
      Reply to Mumbles on Cancel Bets...

      Everything sorted for me... now I can use all calls... But...

      CancelBets class is not clear to me as it has:

      CancelBets
      CancelBetsReq
      CancelBetsResp

      and i do not know how to make good code...

      Dim Req As New BFUK.CancelBetsReq
      With Req
      .header = oHeaderUK()
      ReDim .bets(0)
      .bets(0).betId = bid
      End With

      Dim Resp As new BFUK.CancelBetsResp = BetFairUK.CancelBetsResp(req)


      (where bid = my bet id)


      this one dont work... please help out on this. So far we had req and resp object but here we have like 3 objects... so interfear is not clear to me.

      Comment

      • javizarza
        Junior Member
        • Jun 2009
        • 2

        #153
        Hi, I'm stuck with the same problem with CancelBets.

        Currently I'm waiting to test if using transactionId (from getMUbets) could work properly. Using betId doesn't work for me.

        I'll let you know if it works for me

        ----

        Edit: transactionId doesn't fit neither .betId field for the CancelBets. Any ideas/sample around?

        Regards
        Last edited by javizarza; 17-06-2009, 08:06 PM.

        Comment

        • Mumbles0
          Junior Member
          • Jan 2009
          • 240

          #154
          Reply to Vreljanski & javizarza (re: cancelBets)

          Setting up the request object for cancelBets is a bit tricky. The .bets property, which holds your betId(s), is not an array of type Long - it is an array of objects of type BFUK.CancelBets which have a single property .betId which is of type Long. So it is necessary to create a new BFUK.CancelBets object in the .bets(0) array element with an extra statement as shown here:

          Code:
          Dim Req As New BFUK.CancelBetsReq
          With Req
            .header = oHeaderUK()
            ReDim .bets(0)
            .bets(0) = New BFUK.CancelBets       '<<< add this
            .bets(0).betId = bid
          End With
          bid is the betId of the bet to be cancelled (returned from placeBets).

          Do not confuse the BFUK.CancelBets class with the service object method BetfairUK.cancelBets. They are different things even though they have the same name.

          To call the API to cancel the bet we can write:

          Code:
          Dim Resp As BFUK.CancelBetsResp   'Define a variable to hold the response
          Resp = BetfairUK.cancelBets(Req)  'Assign the reponse to this variable
          The first line defines a variable named Resp which can hold an object of type BFUK.CancelBetsResp. Initially this variable is empty - it contains Nothing. The second line invokes the .cancelBets method of the BetfairUK service object which calls the API and returns an object of type BFUK.CancelBetsResp. This object is then assigned to the Resp variable.

          These two statements can be combined into this single statement:

          Code:
           Dim Resp As BFUK.CancelBetsResp = BetfairUK.cancelBets(Req)
          Here we don’t use the New keyword. (It is often difficult to know when to use, or not to use, the New keyword.)

          __________________________________________________ _____________

          Note:

          Having written this I realize that a minor improvement could be made to the steps earlier in the tutorial. Although it works just as well, it is not necessary to create a response object with the New keyword as shown in the steps. All we need is a variable to hold the response object. As things stand now, we unnecessarily create an uninitialized response object, only to replace it with the response object returned fron the API. For example, in step 4 where we call getActiveEventTypes we have:

          Dim oEventsResp As New BFGlobal.GetEventTypesResp 'Create a response object

          This would be slightly more efficient is we deleted the New keyword and wrote:
          Dim oEventsResp As BFGlobal.GetEventTypesResp 'Define a variable to hold the response object

          It's never too late, so I will go back and revise the steps in order to incorporate this.

          Comment

          • javizarza
            Junior Member
            • Jun 2009
            • 2

            #155
            Hey, thanks Mumbles!!!

            VB.net debugger told about the uninitialized object, but I thought some variable I was sending was not properly send and that caused the fault.

            I'll try the way you did and let you know.

            Regards

            Comment

            • Vadim
              Junior Member
              • Mar 2009
              • 12

              #156
              Games Betfair API

              Mumbles0, but how about a tutorial Games Betfair API?

              Comment

              • lyunchev
                Junior Member
                • Apr 2009
                • 1

                #157
                First one BIG THANK YOU for Mumbles0 !

                And second, can anyone give me a idea, how I can get all "Soccer Full Time In-Play" Markets for today ?

                I have one but is not so good I can get All Soccer Markets and check is it turningInPlay = True and so and so ....

                Regards

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #158
                  Reply to Vadim (Re: Games API)

                  I don't know much about the Games API. For now I'll stick to horse racing...

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #159
                    Reply to lyunchev (Re: In-play markets)

                    The way you have suggested is probably the best way. Call getAllMarkets then filter out only the markets with .turningInPlay = True, as shown in this example. You can specify countries of interest if you wish.

                    Code:
                    Private Sub bInPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bInPlay.Click
                      Print("*** InPlay Soccer Markets ***")
                      Dim oMarketsReq As New BFUK.GetAllMarketsReq
                      With oMarketsReq
                        .header = oHeaderUK()
                        ReDim .eventTypeIds(0) : .eventTypeIds(0) = 1   'For soccer
                        .fromDate = Today
                        .toDate = Today.AddDays(1)   'Specifies today only (local time)
                      End With
                      With BetfairUK.getAllMarkets(oMarketsReq)    'Call the API
                        CheckHeader(.header)
                        Print("ErrorCode = " & .errorCode.ToString)
                        If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                          Dim AllMarkets As New UnpackAllMarkets(.marketData)  'Unpack .marketData
                          With AllMarkets
                            For i = 0 To .marketData.Length - 1
                              With .marketData(i)
                                If .turningInPlay Then   'This market will become InPlay
                                  Print(.menuPath & " - " & .marketName)
                                End If
                              End With
                            Next
                          End With
                        End If
                      End With
                    End Sub
                    To get “Full-time” markets you will also have to examine the .marketName parameter looking for words that will identify it as a “Full-time” market.

                    Comment

                    • tokiya28
                      Junior Member
                      • Jun 2009
                      • 2

                      #160
                      Step 6

                      I have this in my code

                      With oMarketsReq
                      .header = oHeaderUK()
                      ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7 'For Soccer Fixtures use 14
                      .fromDate = Today
                      .toDate = Today.AddDays(1)
                      End With
                      oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)

                      When i get the o marketsreq it is null.

                      How can i also get the market values?

                      Regards

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #161
                        Reply to tokiya28 (re: getAllMarkets)

                        Your code looks OK.

                        For .eventTypeIds(0) = 7 (Horse Racing) you should get many markets. Note that the number of markets returned reduces as the day progresses because only open markets (i.e. active or suspended) are returned.

                        For .eventTypeIds(0) = 14 (Soccer - Fixtures), getAllEvents does not return anything.

                        If you want soccer fixtures markets you can either:

                        Call getAllMarkets with .eventTypeIds(0) = 1 (Soccer) and filter the results. (Look for the substring “Fixtures” in the .menuPath parameter.)

                        or:

                        Call getEvents with .eventParentId = 14 and filter the results for the current day.

                        Comment

                        • Vreljanski
                          Junior Member
                          • May 2009
                          • 16

                          #162
                          Again big thanks for all the help so far. I managed to make a horse racing bot and its working for 1.5 months now. It has some minor flaws and errors i fix but in general without Mumbles help I wouldne be able to do it.

                          Now I wanted to offer one piece of code that will help extract only HORSE WIN MARKETS. and I have a question.

                          Code:
                           Dim oMarketsReq As New BFUK.GetAllMarketsReq
                                  Dim oMarketsResp As New BFUK.GetAllMarketsResp
                                  With oMarketsReq
                                      .header = oHeaderUK()
                                      ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7 
                                      ReDim .countries(0) : .countries(0) = "GBR" 
                                      .fromDate = Today
                                      .toDate = Today.AddDays(1)
                                  End With
                                  oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq) 
                                  With oMarketsResp
                          
                                      CheckHeader(.header)
                          
                                      If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                                          Dim AllMarkets As New UnpackAllMarkets(.marketData)  
                                          With AllMarkets
                                              
                                              For i = 0 To .marketData.Length - 1
                          
                                                  With .marketData(i)
                          
                                                      Dim a As Boolean
                                                      a = Char.IsDigit(.marketName)
                          
                                                      If LetterCount(.menuPath, "\") = 3 And .marketName <> "To Be Placed" And .noOfWinners = 1 And a = True Then
                          
                                                        MARKET = .marketid
                                                      End If
                                                  End With
                                              Next
                                          End With
                                      End If
                                  End With

                          This one should extract Win only markets from total sum of horse racing markets.

                          My question is following:

                          I let my bot run all day and night b ut at some point I get following error on this piece of code:

                          oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
                          ERROR: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.


                          Now I have some ideas how to handle this I was wondering if someone could explain me why is this happening so I understand the API and everything better.

                          Thanks
                          Last edited by Vreljanski; 29-06-2009, 11:28 AM.

                          Comment

                          • Vreljanski
                            Junior Member
                            • May 2009
                            • 16

                            #163
                            I solved this. The reason for this error is that underlaying connection is closed. What happens is that server closes the connection for some reason... so i included the catch exception and do relog... this works good so far.

                            Cheers

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #164
                              Reply to Vreljanski (Re: error)

                              I’ve seen this error myself but I’m not sure what causes it. It may possibly be something in .NET, Betfair’s sever, a firewall or the Internet. It is a nuisance but you must expect the occasional “hiccup”. It is good policy to catch these communication errors and retry the call, as you appear to have done.

                              Perhaps someone else might shed some light on this error...

                              Comment

                              • Oberroden
                                Junior Member
                                • Jul 2009
                                • 1

                                #165
                                Could it be due to a short interruption in the Internet Connection? My ISP closes my internet connection every 24 hours and the DSL Router logs in again automatically. In practice, the interruption is only a few seconds but a number of my applications notice it.

                                I generally arrange that this interruption happens at about 2am but I haven't yet found a way to prevent it.

                                Comment

                                Working...
                                X