Using VB2008 to acccess the Betfair API: A tutorial

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

    #541
    Thanks Mumbles0,

    it seems that it will do the job i want...

    Cheers



    John

    Comment

    • Dingo Bongo
      Junior Member
      • Jul 2009
      • 6

      #542
      Well done sir!!!!

      First and foremost, a big thanks to Mumbles for this thread. It has been a godsend to a VB noob like me. I have followed all of the steps and as a result I now have the outline of a useful application.

      I am going back over the code in more detail now so that I can learn how to carry things forward on my own, in my own direction. To this end I have done a couple of things which may be of use to other users and the noobs that will no doubt follow in my footsteps.

      1) I have copypasted all the posts in this thread in to a Word document. I have two versions of this document now. One is Mumbles lessons ONLY. The other, which isnt quite finished yet, has all the posts BUT has been edited so that posts have been sorted into categories which makes it much easier to follow. I will also be putting these into a Notepad++ format when I have finished the edit.

      2) In the course of going back over the code I am adding in a more detailed set of comments which often include Mumbles posts/extracts as a precis if deemed suitable. Basically they comment on each step of the code so that noobs can see what is going on incrementally.

      I have a bit of time off work just now so Im going to be able to get this finished in the course of the next few days and I'll post up some files with the completed docs in.

      Once again, many thanks for your instruction Mumbles. Big up yourself!!!

      Comment

      • calypsored
        Junior Member
        • Dec 2009
        • 5

        #543
        Mumbles and others, great thread - an enormous help someone new to api programming like me.

        I am trying to create a generic class project to hold all the various api calls so that i don't have to replicate the same code for differing front ends.

        I am stumped by one thing and have tried every which way that I can come up with and would appreciate any help you are able to give..

        Way back in Step 7, trying to call the sub (I've actually turned it into a function but don't see why that would cause a problem) from my form I can't work out a way to get the ByVal parameter passed. I've made the reference to BFUK global, which isn't ideal I know, in an attempt to work around this to no avail...

        This is my code:

        In my class project:

        Public Function ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp) As String

        Dim Lay, Back, sMsg As String
        With MpriceResp
        CheckHeader(.header)
        sMsg &= ("ErrorCode = " & .errorCode.ToString) & vbCrLf
        If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
        With .marketPrices
        sMsg &= ("MarketID = " & .marketId) & vbCrLf
        For i As Integer = 0 To .runnerPrices.Length - 1
        With .runnerPrices(i)
        sMsg &= ("Runner " & i + 1 & " LPM = " & .lastPriceMatched) & vbCrLf
        Back = ""
        For j As Integer = 0 To .bestPricesToBack.Length - 1
        With .bestPricesToBack(j)
        Back = Back & " " & .price & "/" & Int(.amountAvailable)
        End With
        Next
        Lay = ""
        For j As Integer = 0 To .bestPricesToLay.Length - 1
        With .bestPricesToLay(j)
        Lay = Lay & " " & .price & "/" & Int(.amountAvailable)
        End With
        Next
        sMsg &= ("Back = " & Back & " Lay = " & Lay) & vbCrLf
        End With
        Next
        End With
        End If
        End With
        Return sMsg
        End Function

        And the calling procedure from my form (the class project is referenced as "BFIF":

        Private Sub bPrices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bPrices.Click
        Dim sMsg As String = bfIF.ShowMprices(bfIF.BetFairUK.getMarketPricesres p)
        Print(sMsg)
        End Sub

        The message I'm getting is this: ' bfIF.BetfairUK.getMarketPricesResp is not a member of BFInterface.BFUK.ExchangeService '

        I'm sure the solution is simple but I cannot figure it out! Any help much appreciated.

        Thanks

        Comment

        • Grantay.
          Junior Member
          • Jan 2010
          • 53

          #544
          calypsored, you have a few things going askew...

          1) your ShowMprices function is set to return a string, it acutally returns and object

          2) your call to ShowMPrices does not specify the marketid of interest

          so instead of:

          Code:
          Dim sMsg As String = bfIF.ShowMprices(bfIF.BetFairUK.getMarketPricesresp)
          
          try
          
          Dim dMsg = ShowMprices(BetFairUK.getMarketPrices(MpricesReq(1235456)))
          
          or whateveryour marketid of interest is.
          Grantay

          Comment

          • Mumbles0
            Junior Member
            • Jan 2009
            • 240

            #545
            Calypsored,

            It look like you are still a bit confused by classes, objects, methods, etc. and passing arguments to procedures (i.e. subs and functions).

            In step 7 Sub ShowMprices simply "prints" the properties of the GetMarketPricesResp object passed to it as a parameter. You have modified this sub by making it a function method of your BFInterface class which returns a string. That’s OK but, because the parameter remains the same, it should be called similar to the Step 7 example.

            You have declared the function method like this:

            Public Function ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp) As String
            The argument used in the call must evaluate to an object of type BFUK.GetMarketPricesResp. You could call this as in Step 7:

            Dim sMsg As String = BFIF.ShowMprices(BetFairUK.getMarketPrices(Mprices Req))
            where MpricesReq is the function which returns the request object given in Step 7.

            To make this clearer I will expand this out:

            Code:
              Dim PricesResp As BFUK.GetMarketPricesResp          'Declare a variable to hold an object of type BFUK.GetMarketPricesResp
              PricesResp = BetFairUK.getMarketPrices(MpricesReq)  'Call the API to get the response object
              Dim sMsg As String = BFIF.ShowMprices(PricesResp)   'Call ShowMprices with the response object as the argument
            Note that PricesResp is an object of type BFUK.GetMarketPricesResp. This satisfies the calling requirement.

            You have mentioned that you are trying to make a class (presumably BFInterface) containing the various API calls. This is a good idea, but using ShowMprices isn’t the way to go. Each method of the class should contain code to call the API. ShowMprices does not do this.

            Comment

            • beans
              Junior Member
              • Jun 2009
              • 6

              #546
              Re: Step 10. Calling getCompleteMarketPricesCompressed.

              In Step 10. Calling getCompleteMarketPricesCompressed, has the API changed since you wrote this or am I miss understanding something?

              You have the following in the upack class:
              .asianLineId = Field(7)
              .farBSP = Val(Field(8))
              .nearBSP = Val(Field(9))
              .actualBSP = Val(Field(10))

              However I kept finding the BSP was 0. After looking at the API documentation there is (or no longer) appears to be a feild for asianLineID. Is this correct?
              If so, is the reason my BSP is always zero because I nead to drop the feild numbers down one, ie .actualBSP = val(Field(9)).

              Or could I have made a mistake somewhere else that would cause BSP = 0 all the time (I am working with BSP markets)?

              EDIT: DOH! I had these fields mixed up between COMPLETEpricesCompressed and the normal PricesCompressed. As per your Step 14. Calling getMarketPricesCompressed, there is no .asianLineID in the normal pricesCompressed. I had somehow pasted the same field numbers in both unpack procedures.

              Silly mistake and sorry for the bother!
              Last edited by beans; 03-02-2011, 04:02 PM.

              Comment

              • calypsored
                Junior Member
                • Dec 2009
                • 5

                #547
                Thanks Mumbles, a 'bit confused' is probably a massive understatement!

                What I don't understand is why you felt the the need to separate the request and the response into separate procedures in that particular step? In all previous procedures you call them in the same routine... I think that's what threw me..

                Comment

                • monkeymagix
                  Junior Member
                  • Jul 2010
                  • 105

                  #548
                  Accumulator Bets and LAPSED Status Codes

                  Hi Mumbles

                  As you seem to be the most knowledgeable person I have met on this board so far and I didn't want to cross post I was wondering if you check out this thread I started on handling races where the time between two legs in an accumulator are only 10 minutes apart and Betfair only settles the first leg once the 2nd one has started.

                  The thread is located here >> http://forum.bdp.betfair.com/showthr...=4526#post4526

                  I would be interested to hear your thoughts on the matter.

                  Also I don't suppose anyone has had any ideas to why one of my bets was marked as L = LAPSED before the race had occurred (see previous post)

                  I thought you could only get a LAPSED bet if the bet wasn't matched by the time of the race but I got this code hours before.

                  The selection wasn't VOIDED (still ran in the race) so I am confused to why I got a LAPSED status code.

                  Anyway keep up the good work

                  Thanks

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #549
                    Monkeymagix,

                    Thanks for the stroke, but I’m afraid that my knowledge, as far as this forum is concerned, extends mainly to VB programming. I’m sure there are many readers and contributors who know a lot more about unexpected/undesirable behaviours of the Exchange than I do.

                    I don’t know how to make Betfair settle bets any faster than they do.

                    What you need is a prompt results service. Betfair offer a results service, but I have not evaluated it.

                    I don’t know why your bet lapsed before the event started.

                    Also, I don't know the probability of a wiiner being subsequently disqualified.

                    Comment

                    • monkeymagix
                      Junior Member
                      • Jul 2010
                      • 105

                      #550
                      In Play

                      LOL Cheers for the stroke? I take it your a Brit and you mean what I think you mean

                      I am looking into some results API's and I already use another BOT that gets results from certain betting sites but they are only running once every 20 mins at the moment due to the overhead of scraping and de-constructing their poorly and often changing HTML. So I will look into that a bit more to see if I can get results a bit quicker.

                      My bot is basically using data from lots of disparate systems at the moment and it's going to involve a major consolidation process to get it all tied up. I have found myself a nice little profitable system but it relies on being able to place accumulators so until I can make enough money to give up the day job the shoe string will remain at the core of the system.

                      On the topice of determining whether a market has turned in play

                      What do you suggest is the best way for determining from the API alone whether or not a race has actually started.

                      I don't want to place any inplay bets at all but I need to be 100% sure that a race has started or not.

                      From reading up it seems that using the BetDelay property in the compressed market data is not very accurate due to the fact that they cache the data. Therefore I could get a bet delay of 0 and presume the market hadn't started yet but in fact it had and the data was out of date.

                      Do you have any suggestion?

                      Comment

                      • MarkL
                        Junior Member
                        • Oct 2008
                        • 29

                        #551
                        Originally posted by monkeymagix View Post
                        On the topice of determining whether a market has turned in play

                        What do you suggest is the best way for determining from the API alone whether or not a race has actually started.

                        I don't want to place any inplay bets at all but I need to be 100% sure that a race has started or not.

                        From reading up it seems that using the BetDelay property in the compressed market data is not very accurate due to the fact that they cache the data. Therefore I could get a bet delay of 0 and presume the market hadn't started yet but in fact it had and the data was out of date.
                        Checking the BetDelay in the getMarketPricesCompressed response is the best way. The data won't be out of data. The API does cache, but changes in the exchange are pushed to the API servers when they occur.

                        http://bdp.betfair.com/index.php?opt...180&Itemid=108

                        Comment

                        • monkeymagix
                          Junior Member
                          • Jul 2010
                          • 105

                          #552
                          getMarketPrices or getMarketPricesCompressed

                          Cheers Mark

                          I had read somewhere (I think on this forum) that some people had experienced issues with the delay value and had placed bets thinking the market had not turned in play yet only to find out that it was actually in play. Currently I do not want to be placing bets in markets that have started so I am looking for a 100% guaranteed way of knowing when the market has turned in play.

                          Also I am currently using getMarketPrices as apposed to getMarketPricesCompressed.

                          Is there any specific reason why people tend to use the compressed version over the uncompressed version?

                          Obviously the size of the data passed back and forth is smaller with the compressed version but then the downside is the time spent processing the data to make it usable.

                          Do you have any thoughts on this?

                          Comment

                          • MarkL
                            Junior Member
                            • Oct 2008
                            • 29

                            #553
                            Well, it's the internet, so if you're placing bets very close to the off and you to see a betDelay of zero in the marketPrices response and send a bet request, network delays might mean that your bet request actually arrives after the market has turned in-play.

                            If you're not trying to be right up to the last second before the market turns in-play though, you shouldn't have a problem.

                            Yes, the advantage of getMarketPricesCompressed is that it takes a lot less bandwidth than the non-compressed version. Also, it's slightly let load on our end to generate the response.

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #554
                              Also, another good reason to use getMarketPricesCompressed is because it can be called 60 times/min on the free API (only 10/min for getMarketPrices).

                              Any computer not more than 10 years old should have no problem unpacking the compressed data. Tutorial Step 14 gives a fairly efficient algorithm for this.

                              Comment

                              • calypsored
                                Junior Member
                                • Dec 2009
                                • 5

                                #555
                                Another little brick wall....

                                Hi guys, I've finally sorted out my little application to pull current odds in the Correct Score football market across the API, but once again find myself stumped....

                                When a goal is scored some scorelines obviously become impossible and usually you find there is money available on the lay side but not on the back side. My program is falling over when it encounters what is presumably a null entry in the 'marketprices' routine...(index out of range is the exception message)

                                I've tried trapping this with various if .. then's but can't get a workaround - can anyone help me please?

                                Thanks, Dave
                                Last edited by calypsored; 14-02-2011, 12:06 AM.

                                Comment

                                Working...
                                X