Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gunhero
    Junior Member
    • Aug 2010
    • 6

    #406
    hi

    I have the same problem
    if I use the hints of VB2010 the variable completeMarketPrices doesn't exist :/

    thanks for your help

    gunhero

    Comment

    • Mumbles0
      Junior Member
      • Jan 2009
      • 240

      #407
      whymetry, gunhero,

      I think you are using the wrong event handler sub. Your code should be in
      Private Sub BetFairUK_getCompleteMarketPricesCompressedComplet ed

      But it look like you are using:
      Private Sub BetFairUK_getMarketPricesCompressedCompleted.

      Comment

      • gvigliani
        Junior Member
        • Jul 2010
        • 17

        #408
        Originally posted by Mumbles0 View Post
        gvigliani,

        You can sort the AllMarkets.marketData array in order of .eventDate (which is start time) with this statement:

        Array.Sort(AllMarkets.marketData, Function(x, y) Date.Compare(x.eventDate, y.eventDate))
        Thank you ,
        Thank you
        Thank you
        Thank you
        Thank you
        Thank you

        Comment

        • gvigliani
          Junior Member
          • Jul 2010
          • 17

          #409
          Search Engine for Soccer (for the moment)

          Hello everyone,
          I read somewhere on the forum, who felt the need 'of a search engine events. I have tried to solve the problem this way:
          1) I created a combo box and I added an event Collections:

          Football | Soccer | Final Result | Match Odds
          Football | Soccer | End 1st Time | Time Half
          Football | Soccer | End 1-Time / End Game | Half Time / Full Time
          Football | Soccer | Goal 1 Time | Half Time Scores
          Football | Soccer | Total Goals | Total Goals
          Football | Soccer | Minute Goal 1 | First Goal Odds
          Football | Soccer | Draw - No bets | Draw No Bet
          Football | Soccer | More / less than 1.5 goals | Over / Under 1.5 Goals
          Football | Soccer | Over / under 2.5 goals | Over / Under 2.5 Goals
          Football | Soccer | More / less than 3.5 goals | Over / Under 3.5 Goals
          Football | Soccer | More / under 4.5 goals | Over / Under 4.5 Goals
          Football | Soccer | More / under 5.5 goals | Over / Under 5.5 Goals
          Football | Soccer | More / less than 6.5 goals | Over / Under 6.5 Goals
          Football | Soccer | Score | Correct Score
          Football | Soccer | End Result of 1 Time | Half Time
          Football | Soccer | Mark both? | Both Teams to Score?
          Football | Soccer | Hat-tricks Score | Triplet
          Football | Soccer | Odd or Even | Odd or Even

          each string is divided by "|" and I entered:
          Calcio (IT) |
          Soccer (En)
          MarketName (IT)
          MarketName (EN)

          obviously if you do not need the Italian version you can avoid modifying the code to put it.

          code for search:

          Code:
          ' Sub for call  (Combo Box) 
          Private Sub freeSearch_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles freeSearch.SelectedValueChanged
                  tvMarkets.Nodes.Clear()
                  Call carica_mercati_free()
              End Sub
          
          
          ' Sub for Api Called
            Private Sub carica_mercati_free()
                  PrintRes("*** Markets ***")
                  Dim oMarketsReq As New BFUK.GetAllMarketsReq
                  oMarketsReq.header = oHeaderUK()
                  oMarketsReq.fromDate = Today
                  oMarketsReq.toDate = Today.AddDays(CDbl(DayinGame.Text)) ' 0=oggi 1 = domani n=numero di giorni
                  With BetFairUK.getAllMarkets(oMarketsReq)  'Call the API
                      CheckHeader(.header)
                      PrintRes("ErrorCode = " & .errorCode.ToString)
                      If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                          PopulateTreeViewfree(New UnpackAllMarkets(.marketData), tvMarkets)
                      End If
                  End With
              End Sub
          
          
          ' Search Engine
          Friend Sub PopulateTreeViewfree(ByVal AllMarkets As UnpackAllMarkets, ByVal TreeView As TreeView)
                  Dim Ids, Names As String(), Nodes As TreeNodeCollection, M_name() As String, M_disp As String
                  Dim prova As String
                  Dim NumMerc As Integer = 0
          
                  With AllMarkets
                      Array.Sort(AllMarkets.marketData, Function(x, y) Date.Compare(x.eventDate, y.eventDate))  ' sort for event date
                      For i = 0 To .marketData.Length - 1          'For each market
                          With .marketData(i)
                              M_name = Split(freeSearch.Text, "|")
                              Ids = .eventHeirachy.Split("/")        'Array of Ids
                              prova = Replace(.menuPath, " ", " ")
                              prova = Replace(prova, "/", "\")
                              Names = prova.Split("\")       'Array of names
                              M_disp = .marketName
                              If InStr(UCase(prova), UCase(M_name(0))) = 0 And InStr(UCase(prova), UCase(M_name(1))) = 0 Then GoTo incrementa
                              If UCase(M_disp) <> UCase(M_name(2)) And UCase(M_disp) <> UCase(M_name(3)) Then GoTo incrementa
                              Nodes = TreeView.Nodes          'Initial collection of child nodes
                              NumMerc += 1 : N_Mark.Text = NumMerc.ToString
                              Dim Node As New TreeNode       'Add a new node if it doesn't exist
                              Node.Text = Names(UBound(Names)) & "/" & M_name(3)
                              Node.Name = Ids(UBound(Ids))  'This is the key
                              Node.Tag = Format(.eventDate.AddHours(2), "HH:mm")
                              Node.Text = Node.Tag & "-" & Names(UBound(Names)) & "/" & M_name(3)
                              Nodes.Add(Node)
                          End With
          incrementa:
                      Next i
                  End With
              End Sub
          Thank you Mumble0 for your teaching

          gvigliani
          Last edited by gvigliani; 25-08-2010, 02:56 PM.

          Comment

          • whymetry
            Junior Member
            • Aug 2010
            • 2

            #410
            Originally posted by Mumbles0 View Post
            whymetry, gunhero,

            I think you are using the wrong event handler sub. Your code should be in
            Private Sub BetFairUK_getCompleteMarketPricesCompressedComplet ed

            But it look like you are using:
            Private Sub BetFairUK_getMarketPricesCompressedCompleted.
            Thank you. Now working

            Comment

            • Oldb
              Junior Member
              • Feb 2009
              • 6

              #411
              Exceed Throttle

              I have been using this program to retrieve odds for a year now, and really appreciate the code... its a life saver..

              I have only one lingering item....


              I am calling for odds every 10 seconds , but get an exceed throttle message., on occassions.

              I am not 100% sure of the limitation of the free api. I thought i could do 60 calls per minute.?????

              I have a timer running calling
              ShowMprices(BetFairAU.getMarketPrices(MpricesReq)) 'Get market prices
              every 10 seconds.....

              This routine calls
              GetRunners() 'Get the actual runner numbers and put into ActualRunners()

              With .marketPrices
              With .marketPrices

              Really appreciate if someone could explain how this throttle limit would apply when using this vb2008 routines..

              Regards Oldb................

              Comment

              • granted
                Junior Member
                • Jun 2009
                • 14

                #412
                array sorting problem

                i keep getting an array sort error and i don't know why...anyone have any ideas..

                i tried array.sort(myarray(i))

                i tried array.sort(myarray)

                and i always get the error

                overload resolution failed...

                what am i not doing right?

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #413
                  What's in myarray ?

                  Comment

                  • MrChameleon
                    Junior Member
                    • Apr 2009
                    • 7

                    #414
                    I'm a C# programmer, not VB.NET, but try this ...

                    myArray.Sort()

                    given ...

                    List<MyClass> myArray = new List<MyClass.()
                    myArray.Add(myObject);
                    etc.

                    Note also that you may define the the sort criterion by implementing IComparable<MyClass> on the class MyClass.

                    Not sure this will help you, but it can't harm

                    Comment

                    • Mumbles0
                      Junior Member
                      • Jan 2009
                      • 240

                      #415
                      Reply to Oldb (re: getMarketPrices)

                      You are calling getMarketPrices. This has a limit of only 10 calls/minute on the free API. It is better to call getMarketPricesCompressed because this has a higher limit of 60 calls/minute.

                      If you are using code similar to Step 7 it is easy to change this so that getMarketPricesCompressed is called instead of getMarketPrices:

                      Code:
                      [COLOR="Gray"]ShowMprices(BetFairAU.[COLOR="Black"]getMarketPricesCompressed[/COLOR](MpricesReq)) 'Get market prices
                      ......[/COLOR]
                      Code:
                      [COLOR="Gray"]Function MpricesReq() As BFAU.[COLOR="Black"]GetMarketPricesCompressedReq[/COLOR]
                        Dim oMPReq As New BFAU.[COLOR="Black"]GetMarketPricesCompressedReq[/COLOR]
                        With oMPReq
                          .header = oHeaderAU()
                          .marketId = [i]an active market ID[/i]
                        End With
                        Return oMPReq
                      End Function
                      
                      Sub ShowMprices(ByVal MpriceResp As BFAU.[COLOR="Black"]GetMarketPricesCompressedResp[/COLOR])
                        Dim Lay, Back As String
                        With MpriceResp
                          CheckHeader(.header)
                          Print("ErrorCode = " & .errorCode.ToString)
                          If .errorCode = BFAU.GetMarketPricesErrorEnum.OK Then
                            With [COLOR="Black"]New UnpackMarketPricesCompressed(.marketPrices)[/COLOR]
                              Print("MarketID = " & .marketId)
                              For i = 0 To .runnerPrices.Length - 1
                                With .runnerPrices(i)
                      
                                .................
                                .................
                      
                                End With
                              Next
                            End With
                          End If
                        End With
                      End Sub[/COLOR]
                      The class UnpackMarketPricesCompressed is given in Step 14

                      I don’t quite understand what your problem is with your GetRunners sub. If this calls getMarket, bear in mind that the free API limit is only 5 calls/minute.

                      Comment

                      • granted
                        Junior Member
                        • Jun 2009
                        • 14

                        #416
                        i trimmed those annoying numbers at the front of the aust. names using trim....
                        and then i did the following:

                        Dim NewString As String = MyString.TrimStart(MyChar)

                        newstring is the names without the numbers....

                        then i tried array.sort(newstring)

                        thats when everything goes pear-shaped

                        Comment

                        • Mumbles0
                          Junior Member
                          • Jan 2009
                          • 240

                          #417
                          So NewString is a string, presumably containing a horse's name (e.g. "Sterling Prince").

                          It is quite meaningless to call Array.Sort to sort this single string. What are you trying to achieve?

                          It would work if the parameter was an array of strings, but you haven't got this.

                          Comment

                          • granted
                            Junior Member
                            • Jun 2009
                            • 14

                            #418
                            i trimmed the numbers from oMarketResp.market.runners(i).name and then wanted them sorted by name.....

                            they list out in order of their numbers even though i removed them but now i wanted to sort them alphabetically

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #419
                              I'm guessing that you should be placing your trimmed runners names into an array (to be sorted into alphabetical order) but perhaps don't know how to go about this.

                              Post some of your code so we can see what's happening.

                              Comment

                              • Oldb
                                Junior Member
                                • Feb 2009
                                • 6

                                #420
                                Throttle Exceeded

                                Mumbles0

                                I probably did not do enough research to identify the throttle problem, sorry.

                                Will now alter my code accordingly.

                                I should have used the compressed function in the 1st place..!!!!!

                                Thanks again for all the free advice, much appreciated.

                                Regards Oldb

                                Comment

                                Working...
                                X