Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mbrylski
    Junior Member
    • Jul 2010
    • 5

    #361
    re: getAllMarkets problem

    Thx Mumbles0

    I found it this in App.config after changed value to 999999999 everything working correctly

    Code:
    <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />

    Comment

    • Mumbles0
      Junior Member
      • Jan 2009
      • 240

      #362
      App.config file

      My App.config file hasn't got this line in it. Could you please post a copy of your App.config for my information.

      Comment

      • mbrylski
        Junior Member
        • Jul 2010
        • 5

        #363
        RE: App.config file

        Code:
        <?xml version="1.0" encoding="utf-8" ?>
        <configuration>
            <startup>
                <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
            </startup>
            <system.serviceModel>
                <bindings>
                    <basicHttpBinding>
                        <binding name="BFGlobalService" closeTimeout="00:01:00" openTimeout="00:01:00"
                            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
                            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                            useDefaultWebProxy="true">
                            <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                            <security mode="Transport">
                                <transport clientCredentialType="None" proxyCredentialType="None"
                                    realm="" />
                                <message clientCredentialType="UserName" algorithmSuite="Default" />
                            </security>
                        </binding>
                        <binding name="BFGlobalService1" closeTimeout="00:01:00" openTimeout="00:01:00"
                            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
                            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                            useDefaultWebProxy="true">
                            <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                            <security mode="None">
                                <transport clientCredentialType="None" proxyCredentialType="None"
                                    realm="" />
                                <message clientCredentialType="UserName" algorithmSuite="Default" />
                            </security>
                        </binding>
                        <binding name="BFExchangeService" closeTimeout="00:01:00" openTimeout="00:01:00"
                            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
                            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                            useDefaultWebProxy="true">
                            <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                            <security mode="Transport">
                                <transport clientCredentialType="None" proxyCredentialType="None"
                                    realm="" />
                                <message clientCredentialType="UserName" algorithmSuite="Default" />
                            </security>
                        </binding>
                        <binding name="BFExchangeService1" closeTimeout="00:01:00" openTimeout="00:01:00"
                            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
                            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                            useDefaultWebProxy="true">
                            <readerQuotas maxDepth="32" maxStringContentLength="999999999" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                            <security mode="None">
                                <transport clientCredentialType="None" proxyCredentialType="None"
                                    realm="" />
                                <message clientCredentialType="UserName" algorithmSuite="Default" />
                            </security>
                        </binding>
                    </basicHttpBinding>
                </bindings>
                <client>
                    <endpoint address="https://api.betfair.com/global/v3/BFGlobalService"
                        binding="basicHttpBinding" bindingConfiguration="BFGlobalService"
                        contract="BFGlobal.BFGlobalService" name="BFGlobalService" />
                    <endpoint address="https://api.betfair.com/exchange/v5/BFExchangeService"
                        binding="basicHttpBinding" bindingConfiguration="BFExchangeService"
                        contract="BFUK.BFExchangeService" name="BFExchangeService" />
                </client>
            </system.serviceModel>
        </configuration>

        Comment

        • Alth79
          Junior Member
          • Jul 2010
          • 2

          #364
          Placing a bet

          Hi Mumbles0
          Wow - what a brilliant tutorial, thanks for your time and effor!

          I have pulled together a basic bot following your advice and am kean to progress this further. I have completed all of your steps upto step 19 - the placing a bet section.

          This might seam like a stupid problem but I cannot place a bet because i receive an error message stating:

          "Name 'TheBetID' is not declared

          Sorry if this is something trivial which I should be aware of!

          If you could let me know how to deal with this it would be much appreciated

          Cheers

          Comment

          • Mumbles0
            Junior Member
            • Jan 2009
            • 240

            #365
            Alth79,

            In step 19 TheBetId is the name of a variable accessed from within the PlaceBet sub. Make sure that you have declared it outside the sub with a line like this:
            Dim TheBetId As Long

            (In step 19 this has been declared in the code for the test call.)

            Comment

            • gvigliani
              Junior Member
              • Jul 2010
              • 17

              #366
              Hi Mumbles0,
              excuse if you do not write well in English but I hope to be able to make myself understood. I can first declare that I have learned more by following your posts you read all the books on Betfair.
              I was trying to do a test on Step 23. Changing Beth.
              my program that works well, but with this function fails giving error:

              BetPrice = .newPrice
              BetSize = .newSize 'Update with the new values
              nudPrice.Value = .newPrice
              nudSize.Value = .newSize

              1) BetPrice is not Declared
              2) BetSize is not Declared

              I checked Function Placebet and is identical to the one you published and this, with the button and place your bets bPlaceBet works but the function UpdateBet gives me those errors. May depend on what?
              Thanks

              Comment

              • gvigliani
                Junior Member
                • Jul 2010
                • 17

                #367
                Hi Mumbles0,

                I put the following dim in Class Test Forms

                Dim TheBetId As Long 'The betId (returned from placeBets)
                Dim BetPrice As Decimal = Nothing 'Your desired odds
                Dim BetSize As Decimal = Nothing 'Your bet amount in currency units

                the problem is gone but I know if it is justified and then do exactly this way.

                Greetings

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #368
                  Declaring variables

                  gvigliani,

                  Your Dim statements are OK (but there’s no point in setting the values to Nothing).

                  The variables BetPrice, BetSize, etc. were declared previously in Step 19. I did not re-declare them in step 23. These variables are declared outside the Subs that use them. Perhaps this has caused some confusion.


                  Declaring variables

                  All variables that you use must be declared somewhere within your program. The first thing the complier does is build a list of variables declared within your program. When you use a variable, the compiler looks for its name in this list. If it doesn’t find it, it gives the 'name' is not declared error.

                  For example, if you have a simple assignment statement:

                  BetPrice = 3.5
                  and you see the message 'BetPrice' is not declared in the error list, this is telling you that the complier does not know what BetPrice is. You must tell the compiler what BetPrice is before you use it. You do this with a declaration statement, for example:

                  Dim BetPrice as Decimal
                  The "not declared" error should now disappear.

                  We can combine these two statements into one:

                  Dim BetPrice as Decimal = 3.5
                  Here we declare the variable BetPrice and initialize it to 3.5 in one line. This can be handy.

                  You can declare several variables in one Dim statement:

                  Dim BetPrice As Decimal, BetSize As Decimal, TheBetId As Long
                  Because BetSize and BetPrice are both of type Decimal you can simplify this to:

                  Dim BetPrice, BetSize As Decimal, TheBetId As Long
                  This is same as writing:

                  Dim BetSize As Decimal
                  Dim BetPrice As Decimal
                  Dim TheBetId As Long
                  These declarations are said to be non-executable statements. They simply instruct the compiler to reserve space in memory for the variables. However, if you initialize a variable, for example:

                  Dim BetSize as Decimal = 2
                  you now have an executable statement - the value 2 is assigned at run time.


                  Variable access

                  You can use the Private, Friend or Public keywords instead of Dim for variables declared outside a sub or function:

                  Private BetPrice, BetSize As Decimal, TheBetId As Long
                  If the declared variable are to be accessed by code anywhere in your project (e.g. from another form) use Friend or Public. Use Private or Dim for variables that are only accessed by code within the current class.

                  Variables declared within a procedure (a procedure is a sub or function) can only be declared with Dim. These variables are local to the procedure and cannot be accessed from outside the procedure directly.

                  Variable access (variable scope) is a fairly large topic, This is just a brief introduction.
                  Last edited by Mumbles0; 02-08-2010, 02:54 PM.

                  Comment

                  • gvigliani
                    Junior Member
                    • Jul 2010
                    • 17

                    #369
                    Thank you

                    Dear friend Mumbles0,
                    You have absolutely right and the program works perfectly and without any problems.
                    I thank you for the fast reply.

                    Gvigliani

                    Comment

                    • gvigliani
                      Junior Member
                      • Jul 2010
                      • 17

                      #370
                      MyApiProg

                      Thank's for All!!!



                      This is just the beginning but I like and I'm proud.

                      gvigliani

                      Comment

                      • gvigliani
                        Junior Member
                        • Jul 2010
                        • 17

                        #371
                        Bet &lt; 2

                        [QUOTE=supunsilva.;2181] I have found how to place low amount(Stake<2) bets.

                        Hi friend,

                        I'm also looking for a way to bet <2. Can you explain what method you used? Thanks

                        Comment

                        • Alth79
                          Junior Member
                          • Jul 2010
                          • 2

                          #372
                          Placing a bet

                          Hi Mumbles0

                          Thanks for getting back to me about ste 19 - placing a bet.

                          I am still struggling to get this working - I have changed my code as you suggested and no longer receive an error message. I am still not able to place a test bet on my application.

                          Below is the code which i have (the market, and id's were correct at the time of testing.

                          (CODE):
                          Private Sub PlaceBet(ByVal YourMarket As Integer, ByVal YourSelection As Integer, ByVal YourBetType As BFUK.BetTypeEnum, ByVal BetPrice As Decimal, ByVal BetSize As Decimal)
                          Dim oPlaceBetsReq As New BFUK.PlaceBetsReq
                          Dim oPlaceBetsResp As BFUK.PlaceBetsResp
                          Dim oBet As New BFUK.PlaceBets
                          With oPlaceBetsReq
                          .header = oHeaderUK()
                          With oBet
                          .asianLineId = 0
                          .betCategoryType = BFUK.BetCategoryTypeEnum.E
                          .betPersistenceType = BFUK.BetPersistenceTypeEnum.NONE
                          .betType = 0
                          .marketId = 101599071
                          .price = 8.8
                          .selectionId = 3804941
                          .size = 2.0
                          .bspLiability = 0
                          End With
                          ReDim .bets(0)
                          .bets(0) = oBet
                          End With
                          oPlaceBetsResp = BetFairUK.placeBets(oPlaceBetsReq)
                          With oPlaceBetsResp
                          CheckHeader(.header)
                          Print("ErrorCode = " & .errorCode.ToString)
                          If .errorCode = BFUK.PlaceBetsErrorEnum.OK Then
                          For i = 0 To .betResults.Length - 1
                          With .betResults(i)
                          Print(.resultCode.ToString)
                          If .success Then
                          Print("BetId = " & .betId)
                          TheBetID = .betId
                          End If
                          End With
                          Next
                          End If
                          End With
                          End Sub
                          Dim TheBetID As Long
                          (CODE END)

                          If you could take a look at this to see where I am going wrong I would be most grateful.

                          Cheers

                          Comment

                          • Mumbles0
                            Junior Member
                            • Jan 2009
                            • 240

                            #373
                            PlaceBet

                            Alth79,

                            I don't know why you're not using the sub's calling parameters, but it works!

                            Is anything being "printed"? If not, the Sub is not being called.

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #374
                              Your app

                              gvigliani,

                              You have been very busy. Nice work!

                              Comment

                              • waldjunge
                                Junior Member
                                • Apr 2009
                                • 12

                                #375
                                I placed a Lay bet which had a price of 5.9 with 7.9 instead. The following ".errorCode = BFUK.PlaceBetsErrorEnum.OK" gave me OK.

                                However the .PlaceBetsResults.success was not successful and I have gotten "INVALID_INCREMENT"

                                What does this INVALID_INCREMENT exactly mean? The bet was not matched because of this error (message), what did I do wrong, and how can I prevent this in future?

                                thanks,

                                Waldjunge
                                Last edited by waldjunge; 05-08-2010, 03:56 PM.

                                Comment

                                Working...
                                X