Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mumbles0
    Junior Member
    • Jan 2009
    • 240

    #196
    Free API is fine.

    But you can only call getMarketPricesCompressedAsync not more than 60 times per minute.

    This means that your refresh timer interval should not be less than 1000 (milliseconds). I think this is what causes yor problem.
    Last edited by Mumbles0; 16-09-2009, 07:55 AM.

    Comment

    • supunsilva.
      Junior Member
      • Aug 2009
      • 32

      #197
      Hi Mumbles,
      Thanks for your reply. Are you using Yahoo IM or Skype??
      Can you show me how to place a 0.01 stake when I only have less thank 2.00

      Comment

      • supunsilva.
        Junior Member
        • Aug 2009
        • 32

        #198
        Reply to Mumbles

        Hi Mumbles,
        Thanks for your reply. Are you using Yahoo IM or Skype??
        Can you show me how to place a 0.01 stake when I only have less thank 2.00

        Comment

        • Mumbles0
          Junior Member
          • Jan 2009
          • 240

          #199
          No I'm not.

          The £2 minimum bet is a limit you will have to come to terms with yourself. I can't tell you what to do about this.

          Comment

          • Mumbles0
            Junior Member
            • Jan 2009
            • 240

            #200
            Step 20. Monitoring Bet Status

            Having placed a bet you will no doubt be keen to know if and when the bet is matched. This can be done by calling getMUBets at regular time intervals (e.g. 1 sec) .

            If you look in the API Guide you will see that many of the request parameters are used to control the way that data is returned if you have a large number of bets on a market. To keep things simple we won’t worry about these for the time being. We simply set .marketId to return all bets on the current market.

            Add this sub to the Testform class:

            Code:
            Private Sub GetBetStatus(ByVal YourMarket As Integer)
              Dim Req As New BFUK.GetMUBetsReq
              With Req
                .header = oHeaderUK()       'The standard header
                .marketId = YourMarket        'The market of interest
                .betStatus = BFUK.BetStatusEnum.MU  'Return status of matched and unmatched bets
                .recordCount = 100    'Max 100 bets
              End With
              StateCount += 1
              BetFairUK.getMUBetsAsync(Req, StateCount)    'Send the request to the API
            End Sub
            Because a typical application will call getMUBets frequently, we make this an async call to maintain efficiency (as discussed in Step 10). The additional request parameters are unassigned and will default to appropriate values, except for .recordCount which we set to a number greater than the maximum number of bets we are likely to have on a market.

            Also add the code for the response event handler:

            Code:
            Private Sub BetFairUK_getMUBetsCompleted(ByVal sender As Object, ByVal e As BFUK.getMUBetsCompletedEventArgs) Handles BetFairUK.getMUBetsCompleted
              Try
                If Not e.Cancelled Then
                  With e.Result
                    CheckHeader(.header)
                    Print("ErrorCode = " & .errorCode.ToString)
                    If .errorCode = BFUK.GetMUBetsErrorEnum.OK Then
                      For i = 0 To .bets.Length - 1   'For all bets on the market
                        With .bets(i)
                          Print("BetId = " & .betId & " " & .betStatus.ToString & " Price = " & .price & " Size = " & .size)
                        End With
                      Next
                    End If
                  End With
                End If
            
              Catch ex As Exception
                Print(ex.Message)   'If problem
              End Try
            End Sub
            To test this add a “BetStatus” button to the TestForm. Name it bBetStatus and add this code for its Click event handler:

            Code:
            Private Sub bBetStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bBetStatus.Click
              Print("*** GetBetStatus ***")
              GetBetStatus(Market)         'Call getMUBets
            End Sub
            Market is the variable we added in Step 19.

            Now log onto the website and go to your market of interest. Set up another test bet as described in Step 19 and run the project. When you click the “BetStatus” button you will get the NO_RESULTS message (assuming you have no bets on the market). Now click the “PlaceBet” button to place the test bet. This bet should appear on the “My Bets” tab on the website.

            Now click the “BetStatus” button again. The parameters for this bet (.betId, .betStatus, .price and .size) will now be printed and should agree with the website. Several other parameters of interest are returned too (see the API Guide).

            You can experiment with this by changing the odds and the stake on the website and observing what is printed when you click “BetStatus”. If you wish, cancel or match the bet.

            A practical application will probably won’t have a “BetStatus” button. Instead getMUbets could be called from the Tick event of a “refresh” timer or similar.

            A partially-matched bet will be returned as 2 bets with the same betId. The data for each part (.status, .size, .price, etc.) will be given in a separate element in the .bets array

            As an alternative, you can call getBet to return data for a single bet in more detail. However, for a quick look at all your bets on a market, a call to getMUbets should suffice.

            Comment

            • supunsilva.
              Junior Member
              • Aug 2009
              • 32

              #201
              Hi Mumbles...
              Could you kindly tell me how we can call account available balance?
              I am waiting for Cancel bet cording also....
              Very big thanks 4 you...........

              Regards,
              Supun Silva

              Comment

              • Mumbles0
                Junior Member
                • Jan 2009
                • 240

                #202
                Supunsilva,

                Please realize that this forum is only a part-time activity for me - I have other things to do also. I will post a step on cancelBets (also updateBets) when time permits. You don’t have to nag me.

                Account balance.

                The purpose of this tutorial thread is for you to learn about accessing the API with VB. The examples show code and ideas for readers to adapt into their own projects. You should practice writing the code for yourself. Getting the account balance is a good exercise for you. I’ll give you some tips:

                The call you require is getAccountFunds on the UK server. This a very easy call to make because there are no request parameters (except for the standard header). The response object contains the .availBalance parameter. This is what you want.

                Your English is quite good. I’m sure you can read the chapter on getAccountFunds in the API Guide.

                Comment

                • supunsilva.
                  Junior Member
                  • Aug 2009
                  • 32

                  #203
                  Hi Mumbles, I apologize for bothering you.

                  Regards,
                  Supun Silva

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #204
                    Step 21. Cancelling a Bet

                    To cancel unmatched bets you can call cancelBets. With cancelBets you can cancel several bets at once. To keep things simple the following example cancels a single bet only.

                    Add this sub to Class TestForm:

                    Code:
                    Sub CancelBet(ByVal betId As Long)
                    
                      Dim oCancelBetsReq As New BFUK.CancelBetsReq   'Create the request object
                      Dim oCancelBetsResp As BFUK.CancelBetsResp     'A variable to hold the response object
                      With oCancelBetsReq
                        .header = oHeaderUK()      'The standard request header
                        ReDim .bets(0)                    'Single element array
                        .bets(0) = New BFUK.CancelBets    'Create an object of type CancelBets
                        .bets(0).betId = betId          'The BetId to be cancelled
                      End With
                    
                      oCancelBetsResp = BetFairUK.cancelBets(oCancelBetsReq)  'Call API to cancel the bet
                    
                      With oCancelBetsResp     'The response
                        CheckHeader(.header)
                        Print("ErrorCode = " & .errorCode.ToString)
                        If .errorCode = BFUK.CancelBetsErrorEnum.OK Then  'The call succeeded
                          For i = 0 To .betResults.Length - 1   'In this case there should only be one result
                            With .betResults(i)
                              Print(.resultCode.ToString)   'The result of the cancellation
                              If .success Then Print("BetId " & .betId & " cancelled")
                            End With
                          Next
                        End If
                      End With
                    
                    End Sub
                    This is a sync call which follows the normal calling procedure. Note that an object of type BFUK.CancelBets is required to hold the betId in the first element of the .bets array. 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 cancel a bet you simply call Sub CancelBet with the betId. To test this add a “CancelBet” button to the TestForm. Name it bCancelBet and add this code:

                    Code:
                    Private Sub bCancelBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCancelBet.Click
                      Print("*** CancelBet ***")
                      CancelBet(TheBetId)             'TheBetId is saved by Sub PlaceBet
                    End Sub
                    Now set up the parameters for a test bet (as in step 19) and run the project. Observe this market on the website. As previously, the bet will be appear on “My Bets” after you click the “PlaceBet” button. Now click “CancelBet” and observe what happens.

                    There is a similar service called cancelBetsByMarket. Use this if you require bulk cancellation of unmatched bets across one or more markets.

                    Comment

                    • supunsilva.
                      Junior Member
                      • Aug 2009
                      • 32

                      #205
                      Thank you very much mumbles...

                      Comment

                      • Monairda
                        Junior Member
                        • Jan 2009
                        • 32

                        #206
                        Thank you very much mumbles

                        Comment

                        • nYury
                          Junior Member
                          • Apr 2009
                          • 2

                          #207
                          [QUOTE=Mumbles0;251]
                          Code:
                          Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogin.Click
                            Print("*** Login ***")
                            Dim oLoginReq As New BFGlobal.LoginReq
                            Dim oLoginResp As BFGlobal.LoginResp
                            With oLoginReq
                              .username = "[i]YourUsername[/i]"
                              .password = "[i]YourPassword[/i]"
                              .productId = 82           'For free API
                            End With
                            oLoginResp = BetfairGL.login(oLoginReq)     'Call the API
                            With oLoginResp
                              CheckHeader(.header)
                              Print("ErrorCode = " & .errorCode.ToString)
                            End With
                          End Sub[FONT="Courier New"][/FONT]
                          Why the program displays an error message CSharpAPI6.betfair.api.global.APIErrorEnum.PRODUCT _REQUIRES_FUNDED_ACCOUNT? I there is money.

                          Comment

                          • supunsilva.
                            Junior Member
                            • Aug 2009
                            • 32

                            #208
                            Your account shound have at least before 3 months transactions. If you have money in your account, first you have to do a at least one transaction[bet on market]. After that your Api will work fine!!!!

                            Thanks & Regards,
                            Supun Silva

                            Comment

                            • supunsilva.
                              Junior Member
                              • Aug 2009
                              • 32

                              #209
                              Reply;

                              Your account should have at least before 3 months transactions. If you have money in your account, first you have to do a at least one transaction[bet on market]. After that your Api will work fine!!!!

                              Thanks & Regards,
                              Supun Silva

                              Comment

                              • Drifter
                                Junior Member
                                • Mar 2009
                                • 30

                                #210
                                GetMUBets - bets array null?

                                Mumbles,

                                I'm having a bit of an issue with GetMUBets(Resp).

                                I'm trying to return the value mylocalobjectofGetMUBetsResp.bets.selectionId

                                The value in 'bets' is being returned as null. I can see why this might be, simply because the market I am testing for, I have no bets on. How then do I compile for a value which is not defined at compile time because the 'bet object' is not yet instantiated(if that is what is happening) in the API?

                                What I am looking to do is to (re)generate a betting profile to recover my bet state after a crash. Here in Thailand, internet outages are so common, that I have to expect a disconnect during an event - say soccer game - as part of life.

                                To recover my bet state, I want to poll GetMUBets with the marketId that I know I will (perhaps) have bet on. What I have been trying to do is build an array of MarketId:SelectionId, to do a sanity check on re-start. However, there will be no guarantee that I have, at that point, made a bet. Am I approaching this the right way?

                                Regards
                                G

                                Comment

                                Working...
                                X