Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NFLMAN
    Junior Member
    • Jun 2010
    • 17

    #646
    This is fun. My bot is now placing bets for me :-)

    One thing I need to be able to do is stop it from placing a second bet on the same selectionID when the bot loops back round. What's the best way to do this? I am looking at calling GetBetHistory and putting some logic in there against the returned selectionID's but if there's an easier way I'm all ears....

    Comment

    • beans
      Junior Member
      • Jun 2009
      • 6

      #647
      Thanks for the replies. I had used WithEvents and got async calls working fine in one class, I just wasn't sure if I could use the service object in more than one class or if I would run into problems.

      I found my applications became restricted when placing all the calls in one class as I couldn't deal with different responses how I wanted and everything was too generic. Therefore I have gone down the route of using a 'Session' class that handles the key and provides API headers, then another class to 'allocate' the data to custom objects. Then I have some worker classes that handle all the program logic. These worker class make all the calls so I needed each one to have it's own API object. I will probably run into problems with this method further down the line and end up changing the whole structure of my application .... But that wouldn't be the first time!

      Comment

      • mbrylski
        Junior Member
        • Jul 2010
        • 5

        #648
        Hi All


        Mumbles0 I found a bug in the procedure from Step 14. Generally it working very good except when market for back or lay is empty. When I tray use .bestPricesToBack(0).price Or .bestPricesTolay(0).price I receive the message “Index out of range”.

        Can you correct this??


        Maybe it is not a bug it is problem with function which display result. How can I check the range of bestPricesToBack or bestPricesTolay. I know the maximum is three, can I check the current range.
        Last edited by mbrylski; 27-06-2011, 09:02 PM.

        Comment

        • BigSprout
          Junior Member
          • Feb 2011
          • 60

          #649
          mbrylski,

          at times there is no prices for the Back or Lay and this is the reason you are getting this error, try something like this to test that there is a price first:

          Code:
                                              dgvField("FdBk", Rw).Value = If(.bestPricesToBack.Length > 0, Format(.bestPricesToBack(0).price, "   0.00"), "")    'Update best Back price
                                              dgvField("FdLay", Rw).Value = If(.bestPricesToLay.Length > 0, Format(.bestPricesToLay(0).price, "   0.00"), "")     'Update best Lay price
          or

          Code:
                                              If .bestPricesToBack.Length > 0 Then
                                                  Field(Fd).Fld(Rw).ftBck = .bestPricesToBack(0).price                  'Update best Back price
                                                  Field(Fd).Fld(Rw).ftbAmt = .bestPricesToBack(0).amountAvailable
                                              End If
          
          
                                              If .bestPricesToLay.Length > 0 Then
                                                  Field(Fd).Fld(Rw).ftLay = .bestPricesToLay(0).price                   'Update best Lay price
                                                  Field(Fd).Fld(Rw).ftlAmt = .bestPricesToLay(0).amountAvailable
                                              End If

          Edit:
          replace "dgvField("FdBk", Rw).Value" and "Field(Fd).Fld(Rw).ftBck" for your own variables
          Last edited by BigSprout; 28-06-2011, 02:39 AM.

          Comment

          • mbrylski
            Junior Member
            • Jul 2010
            • 5

            #650
            BigSprout thank you for your answer now everything is working properly. I have one more question. How can I check current score of the game. Most interests me soccer

            Comment

            • rphi6876
              Junior Member
              • Nov 2009
              • 7

              #651
              Slow Bet Placement

              Hi,

              My bot has the ability to place bets under $5 by sending in a lay (back) at 1.01 (1000) then updating the bet to the approriate size which creates a new bet then updating the newly created bet to the desired price. The orignal bet at 1.01 or 1000 is then cancelled. All of these steps are done asyncronously. This works fine and takes a bit over 1 second to complete. However I also have a timer that fires every second resulting in a call to getMUBetsAsync, getMarketTradedVolumeCompressedAsync, getCompleteMarketPricesCompressedAsync and getMarketPricesCompressedAsync. When this timer is running placing an undersized bet now takes roughly ten seconds (this is an average of over 200 bets placed and not an anomoly). I am thinking that when placeBetsCompleted and updateBetsCompleted get a result from betfair the thread they are on has a low priority? But dont really have any idea. Any suggestions if there is a way to make handling these completed calls high priority or perhaps another possible explanation for this problem.
              As a side not this is not a result of a slow internet connection as using software made by others this problem does not occur.
              Cheers

              Comment

              • antonello273
                Junior Member
                • Feb 2010
                • 12

                #652
                balance betfair

                Good day to all, you can say to me as I can visualize the balance of my account betfair? , I have tried but it exits to me alone

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #653
                  antonello273,

                  GetAccountFunds returns your account balance in the .availBalance parameter of the response.

                  Comment

                  • antonello273
                    Junior Member
                    • Feb 2010
                    • 12

                    #654
                    thank you so much

                    Comment

                    • antonello273
                      Junior Member
                      • Feb 2010
                      • 12

                      #655
                      I have tried to write this code, but the result is error NO_SESSION

                      Dim oSaldoReq As New bfuk.GetAccountFundsReq
                      Dim oSaldoResp As bfuk.GetAccountFundsResp

                      oSaldoResp = BetFairUK.getAccountFunds(oSaldoReq)

                      With oSaldoResp
                      CheckHeader(.header)
                      Print("Il Saldo disponibile è = " & .availBalance)
                      End With


                      Can you help me to solve the problem?
                      Last edited by antonello273; 30-06-2011, 10:13 AM.

                      Comment

                      • BigSprout
                        Junior Member
                        • Feb 2011
                        • 60

                        #656
                        Antonello,
                        I think you have omitted a line of coding to fill in the header, without this you are not sending your Session Token and thus will get a "NO_SESSION" error:

                        Code:
                        Dim oSaldoReq As New bfuk.GetAccountFundsReq
                        Dim oSaldoResp As bfuk.GetAccountFundsResp
                        
                        [B]oSaldoReq.header = oHeaderUK()
                        [/B]
                        oSaldoResp = BetFairUK.getAccountFunds(oSaldoReq)
                        
                        With oSaldoResp
                        CheckHeader(.header)
                        Print("Il Saldo disponibile è = " & .availBalance)
                        End With

                        Comment

                        • antonello273
                          Junior Member
                          • Feb 2010
                          • 12

                          #657
                          Thanks i tried and it works.



                          P.S. excellent forum and help me a lot

                          Comment

                          • antonello273
                            Junior Member
                            • Feb 2010
                            • 12

                            #658
                            European countries

                            I need another aid you tell me how do i download the markets for the european countries?

                            Comment

                            • BigSprout
                              Junior Member
                              • Feb 2011
                              • 60

                              #659
                              Antonello,

                              Step 5 in this tutorial covers the call to "GetAllMarkets" - in the API6 documentation it states that ISO3 country codes are used.

                              Here is a site that lists Countries and their ISO3 codes:

                              http://www.fao.org/countryprofiles/iso3list.asp

                              cheers

                              Comment

                              • antonello273
                                Junior Member
                                • Feb 2010
                                • 12

                                #660
                                Thanks i solved not by putting the codes, but taking all the markets available.

                                However, i have noticed that i am not returns no football match, you place the code that i wrote.

                                PHP Code:
                                 Print("*** Markets ***")
                                            
                                Dim oMarketsReq As New bfuk.GetAllMarketsReq
                                            Dim oMarketsResp 
                                As bfuk.GetAllMarketsResp
                                            With oMarketsReq
                                                
                                .header oHeaderUK()
                                                
                                ReDim .eventTypeIds(0) : .eventTypeIds(0) = Val(IdEvento.Text)  'For horse racing
                                                ' 
                                ReDim .countries(1) : .countries(0) = "GBR" : .countries(1) = "ZAF"
                                                
                                .fromDate Now
                                                
                                .toDate Now.AddDays(1)
                                            
                                End With
                                            oMarketsResp 
                                BetFairUK.getAllMarkets(oMarketsReq)  'Call the UK API
                                            With oMarketsResp
                                                CheckHeader(.header)
                                                Print("ErrorCode = " & .errorCode.ToString)
                                                If .errorCode = bfuk.GetAllMarketsErrorEnum.OK Then
                                                    Dim AllMarkets As New UnpackAllMarkets(.marketData)   '
                                Create an object and unpack the string
                                                    Dim Names 
                                As String(), TodaysCard As New List(Of MarketDataType)

                                                    
                                With AllMarkets
                                                        
                                For 0 To .marketData.Length 1
                                                            Names 
                                = .marketData(i).menuPath.Split("\")   'This is the filter
                                                            If Names.Length = 4 AndAlso Not Names(3).StartsWith("
                                Daily") Then

                                                                TodaysCard.Add(.marketData(i))    'Add win markets only
                                                            End If

                                                            With .marketData(i)

                                                            End With
                                                        Next
                                                    End With
                                                    TodaysCard.Sort(New CompareMarketTimes)   'Sort according to market times 
                                                    For Each Race In TodaysCard    'Print the card
                                                        With Race
                                                            Names = .menuPath.Split("
                                \")
                                                            'ListBox2.Items.Add(.marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath)
                                                            ListBox2.Items.Add(.marketId & " " & .eventDate.ToLocalTime.TimeOfDay.ToString & " " & Names(3) & " 
                                " & .marketName)

                                                            'Print(.eventDate.ToLocalTime.TimeOfDay.ToString & " " & .marketId & " " & Names(3) & " 
                                " & .marketName)
                                                        End With
                                                    Next


                                                End If
                                            End With 

                                Comment

                                Working...
                                X