Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Logun
    Junior Member
    • Feb 2009
    • 5

    #211
    marketId

    Hi Mumbles,

    First of all thanks for an excellent tutorial in programming for the Betfair API. I got to tell you i have no programming experience yet i was able through your instructions create a very usable bot and i've increased my programming ability no end.

    There is one thing in my programming which i haven't been able to do myself yet. If this is a simple step then i apologise, but if it's more involved i would appreciate a few pointers.

    What i do is after login to the api i use the get Todays Card call to pull a list of the Greyhound or Horse market into a listbox. Currently i have to pick a market then write down the marketId and type it in manually. What i want to do is to double click on a markket in the list, extract the marketId into a temporary container and the input it into the .marketId line automaticaly rather than manually. See below.

    Private Sub lbMarkets_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbMarkets.DoubleClick
    Beep()
    'Print("*** Complete Market Prices ****")
    Dim oCMPCreq As New BFUK.GetCompleteMarketPricesCompressedReq
    Dim marketId As Integer = Val(TempMarketId)
    With oCMPCreq
    Print(.marketId)
    .header = oHeaderUK()
    .marketId = TempMarketId
    '.marketId = 100814234 'an active market ID
    End With
    StateCount += 1
    BetFairUK.getCompleteMarketPricesCompressedAsync(o CMPCreq, StateCount) 'Call the AP
    End Sub

    I'm sure this is simple and it's only my programming knowledge that's making seem impossible. Any pointers would be appreciated.

    Thanks
    Tony

    Comment

    • Mumbles0
      Junior Member
      • Jan 2009
      • 240

      #212
      Reply to Drifter (Re: getMUBets)

      It’s true that if you don’t have any bets on the market specified in the request, the .bets array in the response is not instantiated (i.e. is Nothing). This will generate a run-time exception if you attempt to access this array.

      However, It’s easy to test for this condition and avoid the problem. In this case .errorCode in the response object returns NO_RESULTS. The example in Step 20 does not have a problem with this because we only look at the.bets array if .errorCode has the OK state.

      If you have a list of marketIds for which you may have bets on, you could try a scheme something like this (if you’ll excuse the VB):

      Code:
       [I]'Call getMUBets for each market that may have bets on.[/I]
      
      With e.Result
        Select Case .errorCode
          Case BFUK.GetMUBetsErrorEnum.OK
      
            [I]'Build list of bets on this market[/I]
      
          Case BFUK.GetMUBetsErrorEnum.NO_RESULTS
      
           [I] 'No bets - skip this market[/I]
      
          Case Else
            Print(.errorCode.ToString)    'If problem
        End Select
      End With
      Also, this is interesting:

      If you call getMUBets with .marketID = 0 (and also without the .betIds array), you return all bets on all markets, i.e. the big picture. You should be able to do something with this on a restart. (I don’t think this behaviour is mentioned in the API Guide.)

      M0

      Comment

      • Drifter
        Junior Member
        • Mar 2009
        • 30

        #213
        I saw that possibility, but the problem is that it throws a compile time error - I don't even get the luxury of a run-time error. If I check for a valid reply (= OK, or/& record count > 0), and then try to do something like:

        int selectID = extant_bets_Response.bets.selectionId;

        which, from the API I should be able to do, to access the array of 0 or more MUBet (p.87). What happens is I get a compile error in visual studio:

        "'System.Array' does not contain a definition for 'selectionId' and no extension method 'selectionId' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)"


        Intellisense offers no way for me to access the (published) content of the MUBet array. It may be the case that were I to have a bet on an existing market, that the bet would be found, the array would be istantiated, and intellisense would find the correct object. It might have been a work around if I could create a bet just to achieve a compile, but VS2008 won't allow that because of the syntax checking on the API. The API does offer '0 or more bets', allegedly.

        Unless I'm doing something wrong, which is possible, but I don't see it.



        if I did call getMUBets with .marketID = 0, how would I identify my bets? Could I store bet ID information in a file perhaps and scan for those bet ID's? Would that work? Seems I could be pulling *a lot* of data, perhaps to prove nothing happened (though I will look at it!). It also strikes me that that could be a security issue, letting one account see bet ID's of all other accounts.
        Last edited by Drifter; 21-09-2009, 01:42 PM.

        Comment

        • Mumbles0
          Junior Member
          • Jan 2009
          • 240

          #214
          Reply to Tony Logun (re: ListBox for marketIds)

          In this tutorial we haven't looked much at the user interface, (except for Step 15 where we used the TreeView control). I’ve left this up to you. I’m sure that many readers have discovered that the ListBox is a handy control to hold a set of markets.

          I am presuming you are getting “Today’s Card” as shown in the Step 18 example. Instead of printing the markets you can populate a ListBox using the .Items.Add method like this:

          Code:
          For Each Race In TodaysCard   'Load the ListBox with Today’s Card
            With (Race)
              Names = .menuPath.Split("\")
              lbMarkets.Items.Add(.eventDate.TimeOfDay.ToString & " " & .marketId & " " & Names(3) & " - " & .marketName)
            End With
          Next
          Here lbMarkets is the ListBox. Note that there must be only a single space between .TimeOfDay and .marketId

          When you double click on a item in the ListBox you raise the DoubleClick event. Add some extra code to your event handler:

          Code:
          Private Sub lbMarkets_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbMarkets.DoubleClick
            Dim s As String, Part As String(), marketId As Integer
          
            s = lbMarkets.SelectedItem    'The selected item
            Part = s.Split(" ")           'Get the parts of the item separated by spaces
            marketId = Val(Part(1))       'The marketId is the second part
            Print("marketId = " & marketId)
            Beep()
          
            'Your existing code (I've cleaned it up a bit):
          
            Dim oCMPCreq As New BFUK.GetCompleteMarketPricesCompressedReq
            With oCMPCreq
              .header = oHeaderUK()
              .marketId = marketId
            End With
            StateCount += 1
            BetFairUK.getCompleteMarketPricesCompressedAsync(oCMPCreq, StateCount) 'Call the AP
          
          End Sub
          The .selectedItem property of the ListBox contains the item that has been clicked. We now split this into parts wherever a space occurs in the string. Part(0) is the time, Part(1) is the marketId, Part(2) is the venue, etc. Part(1) is what we want.

          What I’ve shown here is not the only way to go about this. Using a ListBox is a good subject for a future step. I will think about this.

          In a practical application you shouldn’t have to know what your marketIds, selectionIds, etc. are. A good program will take care of these for you “behind the scenes”.
          Last edited by Mumbles0; 22-09-2009, 09:59 PM.

          Comment

          • Mumbles0
            Junior Member
            • Jan 2009
            • 240

            #215
            Drifter .......

            Translating your line into VB:
            Dim selectID As Integer = extant_bets_Response.bets.selectionId
            (where extant_bets_Response is of type BFUK.GetMUBetsResp), I get a compile error which looks a bit similar:
            'selectionId' is not a member of 'System.Array'.
            This is because .selectionId is a property of each element of .bets (which has type BFUK.MUBet), not a property of .bets itself (which is of type System.Array. To fix this simply use an appropriate array index:
            Dim selectID As Integer = extant_bets_Response.bets(i).selectionId




            Also:

            For .marketId = 0, getMUBets only returns your bets across all markets

            Comment

            • Tony Logun
              Junior Member
              • Feb 2009
              • 5

              #216
              Mumble,

              Thanks , i was thinking about using the .selectedItem to pull out the information, your code has given me a lot of information and things to think about. One of the hardest things for me is connecting the code with the user interface but this is what makes it so interesting.

              Just to let users know, the marketId is part (2)

              Tony
              Last edited by Tony Logun; 21-09-2009, 03:49 PM.

              Comment

              • Drifter
                Junior Member
                • Mar 2009
                • 30

                #217
                The man is a genius, I swear!

                Thanks Mumbles - I stuck an array index in there, and everything came up like roses. No idea how long I could have stared at that without seeing it!

                Comment

                • fly00100
                  Junior Member
                  • Jul 2009
                  • 2

                  #218
                  field with name of team etc.

                  Hello everyone, I have a small problem that I can not answer for lack of time, I wonder what is the API field that returns the contents (names -> example Chelsie ... arsenal ... draw ... 1 -- 0 2-0 etc.). first-team and guests and draw for football and the various fields for different markets.

                  Excuse my English :-)
                  regards

                  Comment

                  • Vreljanski
                    Junior Member
                    • May 2009
                    • 16

                    #219
                    Hi again,

                    it seems that service reference has been changed as I stated a new project and now the calls from the begining of the tutorial report me an error

                    Dim BetfairGL As New BFGlobal.BFGlobalService
                    Dim BetFairUK As New BFUK.BFExchangeService

                    both calls tell me that new on interface cant be used? now in old projects everything is still ok so I am geting confused.

                    So I tried lot of workarounds and neither one helped. There is BFGlobalServiceClient and BFExchangeServiceClient Classes. but when i use it on get all markets even tho everything its ok according to object browser i get weird errors. Now I tried to use MarketsIn and MarketsOut thingie... but no luck...

                    Simply same code in old app(on old unapdated web reference) is working and in new app with fresh added reference wont work - gives me error when i call all markets.

                    So in old apps code works in new one same code wont get me all market list like something is changed in new web reference.

                    please help.
                    Last edited by Vreljanski; 30-09-2009, 04:25 PM.

                    Comment

                    • Mumbles0
                      Junior Member
                      • Jan 2009
                      • 240

                      #220
                      Reply to Vreljanski (re: API reference)

                      It looks like you have added a service reference instead of a web reference. See this post.

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #221
                        Reply to fly00100 (re: event names)

                        The getAllMarkets API call returns the parameters .marketName which is the name of the market, and .menuPath which gives more description of the market

                        Example:

                        .menuPath = "\Soccer\English Soccer\Barclays Premier League\Fixtures 04 October \Arsenal v Blackburn"

                        .marketName = "Over/Under 1.5 Goals"


                        I’m not sure this answers your question, but it may be useful.

                        Comment

                        • fly00100
                          Junior Member
                          • Jul 2009
                          • 2

                          #222
                          Originally posted by Mumbles0 View Post
                          The getAllMarkets API call returns the parameters .marketName which is the name of the market, and .menuPath which gives more description of the market

                          Example:

                          .menuPath = "\Soccer\English Soccer\Barclays Premier League\Fixtures 04 October \Arsenal v Blackburn"

                          .marketName = "Over/Under 1.5 Goals"


                          I’m not sure this answers your question, but it may be useful.
                          yes this was my quesion , thanks all , sorry for my english, bye

                          Comment

                          • Vreljanski
                            Junior Member
                            • May 2009
                            • 16

                            #223
                            ah yes I did used add service reference... well it gets late working hours near end so... noobity appears.

                            Anyway today I worked with getMarketPricesCompressed market prices... and it should return the same data as getMarketPrices but only its packed in a string... now in the tutorial I noticed you unpacked it but it seems you havent unpacked all the data from the string... as there is also back and lay prices data according to the api documentation.

                            Am I wrong or...? and if so... can u please show how to unpack back and lay prices data as it seems that that way... i will speed things up dramatically.

                            thanks

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #224
                              Reply to Vreljanski (re: getMarketPricesCompressed)

                              Unpacking the string returned by getMarketPricesCompressed is described in Step 14.

                              When this string is unpacked using the class UnpackMarketPricesCompressed, the parameters returned are identical to those returned by getMarketPrices, including the arrays .bestPricesToBack and .bestPricesToLay.

                              In the code for class UnpackMarketPricesCompressed you will see that Private Function Prices unpacks the prices.

                              Comment

                              • supunsilva.
                                Junior Member
                                • Aug 2009
                                • 32

                                #225
                                Before race time count and inplay time count

                                Hi Mumbles.........

                                I have three problems...

                                1.
                                How can I retrieve Race before time count and Inplay time count when race starts.

                                2.
                                When I press the Todays Card, It will display all events with one hour (-)
                                Ex:
                                100853281 14:25:00 Tipp (This should 15:25:00 Tipp)

                                3.
                                How can I update unmatched bet? (change bet Odd or Stake)

                                Please help me to solve these issues...

                                Thank you,
                                Regards,
                                Supun Silva

                                Comment

                                Working...
                                X