Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • valentroch
    Junior Member
    • May 2011
    • 3

    #616
    Invalid_Price error

    Hi,

    Thank you for this topic. It very helped me to make a automatic exchange program.

    But I have a little problem. I place a lot of bet with my program and mostly it works but sometimes I have an INVALID_PRICE error (bet's Result Code). I have this problem even with totally normal odds (like 1.36, 1.54, 1.81, 1.33, 1.07, 1.06)... I don't understand. Can anybody help me?

    Thank you
    valentroch

    Comment

    • Mumbles0
      Junior Member
      • Jan 2009
      • 240

      #617
      valentroch,

      It’s possible that your problem is caused by the API’s use of type Double to hold price values. This can cause rounding errors.

      Try using a rounding function like this:

      odds = 1.54 'Your odds value
      .price = Decimal.Round(CDec(odds), 2)
      This is not guaranteed to work, but it might improve the problem.

      Comment

      • valentroch
        Junior Member
        • May 2011
        • 3

        #618
        Thank you for the response Mumbles0.

        I will try and I tell you back if it works.

        Comment

        • antonello273
          Junior Member
          • Feb 2010
          • 12

          #619
          updatebet

          Hello everyone, first of all I CuSO for my English, I state that programming vb.net are a beginner, having said that you tell me how I can open the "UpdateBet" du times consecutively? I tried using the function call, but I noticed that the first time is the second tells me there are a pricing error, ie the value of nudprice back to 1000 instead of changing the value 10.
          Thanks and I apologize again for my English.

          I post my code:

          Private Sub bPlaceBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bPlaceBet.Click
          Dim quota As Decimal
          Dim stake As Decimal
          Print("*** PlaceBet ***")


          If stake < 2.0 Then
          If rbBack.Checked Then BetType = bfuk.BetTypeEnum.B Else BetType = bfuk.BetTypeEnum.L 'Select Back or Lay bet
          PlaceBet(IdMercato.Text, IdSelezione.Text, bfuk.BetTypeEnum.B, 1000, 2) 'The call to place the bet
          Call UpdateBet(TheBetId, 1000, 1000, 2 + nudSize.Value, 2)
          quota = InputBox("Iserisci la nuova quota")
          nudPrice.Value = quota
          Call UpdateBet(TheBetId, nudPrice.Value, 1000, nudSize.Value, 2 + nudSize.Value)
          Else

          BetPrice = nudPrice.Value 'The selected price
          BetSize = nudSize.Value 'The selected bet size

          PlaceBet(IdMercato.Text, IdSelezione.Text, bfuk.BetTypeEnum.B, BetPrice, BetSize) 'The call to place the bet
          End If

          End Sub

          Comment

          • antonello273
            Junior Member
            • Feb 2010
            • 12

            #620
            Update bets

            Thanks I solved it by myself, found the solution.

            Comment

            • antonello273
              Junior Member
              • Feb 2010
              • 12

              #621
              Events 13-14-15

              Hello everyone, I am again asking for your help, some of you have solved how to download the events 13-14-15?, Thank you all.

              Comment

              • Speedbird
                Junior Member
                • May 2011
                • 2

                #622
                New Kid.... somewhat lost

                Mumbles0... thanks for a brilliant initiative. I'm brand new at this and evidently bloody stupid, so pls be nice. I've been trying to follow your step by step guide but get stuck at an early stage (running the login...as soon as I run it an error mssg is coughed up telling me the NotImplementedException is unhandled). It also screams at me that the 'SessTokFile' is not declared.
                What am I missing? Would you mind checking my code thus far? (I'm using VB 2010 Express).
                Thank you very much

                Public Class TestForm
                Sub Print(ByVal Message As String)
                Dim oHeaderGL As New BFGlobal.APIRequestHeader
                Dim BetfairGL As New BFGlobal.BFGlobalService
                Const SessTokFile = "C:\Betfair\SessToken.txt"
                With tLog
                .SelectionStart = .Text.Length
                .SelectedText = vbCrLf & Message
                End With
                End Sub
                Sub CheckHeader(ByVal Header As BFGlobal.APIResponseHeader)
                With Header
                Print("HeaderCode = " & .errorCode.ToString)
                oHeaderGL.sessionToken = .sessionToken
                End With
                End Sub

                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 = "acc name"
                .password = "password"
                .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

                Private Sub bLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogout.Click
                Print("*** Logout ***")
                Dim oLogoutReq As New BFGlobal.LogoutReq
                Dim oLogoutResp As BFGlobal.LogoutResp
                oLogoutReq.header = oHeaderGL
                oLogoutResp = BetfairGL.logout(oLogoutReq) 'Call the API
                With oLogoutResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                End With
                End Sub

                Private Sub bKeepAlive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bKeepAlive.Click
                Print("*** KeepAlive ***")
                Dim oKeepAliveReq As New BFGlobal.KeepAliveReq
                Dim oKeepAliveResp As BFGlobal.KeepAliveResp
                oKeepAliveReq.header = oHeaderGL
                oKeepAliveResp = BetfairGL.keepAlive(oKeepAliveReq) 'Call the API
                CheckHeader(oKeepAliveResp.header)
                End Sub

                Private Function BetfairGL() As Object
                Throw New NotImplementedException
                End Function

                Private Function oHeaderGL() As BFGlobal.APIRequestHeader
                Throw New NotImplementedException
                End Function

                Private Sub TestForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
                My.Computer.FileSystem.WriteAllText(SessTokFile, oHeaderGL.sessionToken, False)
                End Sub

                Private Sub TestForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                oHeaderGL.sessionToken = My.Computer.FileSystem.ReadAllText(SessTokFile)
                End Sub

                Private Sub bEvents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bEvents.Click
                Print("*** Events ***")
                Dim oEventsReq As New BFGlobal.GetEventTypesReq 'Create the request object
                Dim oEventsResp As BFGlobal.GetEventTypesResp 'Create a variable for the response object
                oEventsReq.header = oHeaderGL() 'Load request parameters
                oEventsResp = BetfairGL.getActiveEventTypes(oEventsReq) 'Call the API
                With oEventsResp
                CheckHeader(.header) 'Check response header
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFGlobal.GetEventsErrorEnum.OK Then 'Check the response errorcode
                For i = 0 To .eventTypeItems.Length - 1 'Process the received data
                With .eventTypeItems(i)
                Print(.name & " (" & .id & ")")
                End With
                Next
                End If
                End With

                End Sub
                End Class

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #623
                  Speedbird.

                  I am surprised you managed to get it to run at all.

                  The 3 declaration statements don’t belong in the Print sub. Put them at the top of the class like this:

                  Code:
                  Public Class Speedbird
                  
                    Dim oHeaderGL As New BFGlobal.APIRequestHeader
                    Dim BetfairGL As New BFGlobal.BFGlobalService
                    Const SessTokFile = "C:\Betfair\SessToken.txt"
                  
                    Sub Print(ByVal Message As String)
                      With tLog
                        .SelectionStart = .Text.Length
                        .SelectedText = vbCrLf & Message
                      End With
                    End Sub
                  
                    ...........
                    ...........
                  What on earth are these functions for ???????????

                  Code:
                    Private Function BetfairGL() As Object
                      Throw New NotImplementedException
                    End Function
                  
                    Private Function oHeaderGL() As BFGlobal.APIRequestHeader
                      Throw New NotImplementedException
                    End Function
                  I guess you added them to resolve the "not declared" compiler errors which occurred because you put the declarations in the wrong place.

                  I’m not surprised you get the NotImplementedException because that’s what you are asking for.

                  Comment

                  • Speedbird
                    Junior Member
                    • May 2011
                    • 2

                    #624
                    Thank you Mumbles0. Runs perfect.... so far. Will do my best not be a nuisance

                    Comment

                    • antonello273
                      Junior Member
                      • Feb 2010
                      • 12

                      #625
                      Evant 13-14-15

                      Who can help me to solve my problem concerning the events 13-14-15?

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #626
                        getAllMarkets does not return any data for eventTypeIds 13, 14 or 15.

                        Step 18 may help you.

                        Comment

                        • antonello273
                          Junior Member
                          • Feb 2010
                          • 12

                          #627
                          Thank you so much I've been helpful.
                          PS Forum super useful.

                          Comment

                          • LionKing
                            Junior Member
                            • Jul 2010
                            • 1

                            #628
                            Excel

                            Hi all
                            Can we build dll api functions that we invoke thur vba procedures in friendly excel?
                            thks

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #629
                              LionKing,

                              I don't know a great deal about VBA, but I believe this can be done. You can use VB2010 to make a DLL that can be called from Excel using VBA. There would be restrictions on the type of objects that can be passed as parameters.

                              Grantay has done some work in this area. See this post.

                              Comment

                              • gkr
                                Junior Member
                                • May 2011
                                • 2

                                #630
                                Mumbles0 many thanks for this useful thread.

                                I want to ask a question

                                I place a bet back Unmatched and i want to know if all the bet matched (no partially-matched) and then i put a lay bet.

                                Now i am doing this

                                I place the bet and so i have the betId.

                                Then i call GetBet and i check betStatus.

                                If the return is "M" i place the lay

                                Is this correct or i must change my code and follow step 20 ?

                                Comment

                                Working...
                                X