Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davecon
    Junior Member
    • Dec 2010
    • 86

    #706
    exe App

    Hi 223
    For a PC etc Use a Flash Drive or CD/DVD if you want to Install on another Computer besides your own
    Or Just Install to a Folder on your Comp
    Example Your Project Name is 'BFTest'
    Either Way - Create a New Folder for your App (Say on Desktop if not in your Flash etc Name it eg "BFTest Install")
    For First Time Install its Best to Add a Desktop ShortCut before Publishing So in VB2010 Main Menu Click
    Project - "BFTest Properties" (Ignore Publish BFTest this Time)
    In Properties - Select "Publish"
    1-In the Top Publish Location Browse to your "BFTest Install" Folder
    2- Select the "(Launchable from Start Menu") Option
    3 - Click Options (You can Play with all this later )but for now
    4- Click Manifests
    5 - Tick "Create DeskTop Shortcut" (If you add or have added an icon to your project it will show this on your Desktop Do that from BFTest Properties -Application - Add Icon Link) for now it will just use the vb default - Click Ok
    6 - then Click "Publish Now" It will show in your status bar publishing and if it succeeded
    Finally go to your Installation Folder and Double Click the Setup.exe and it will install like any other Program
    It will show a Desktop Icon and Start Menu and will also be in your Uninstall Programs from the Control Panel
    After Doing the above you only need to Use the VB Main Menu
    Project - Publish BFTest and Click Finish in the Dialogue
    This will Update your Publication each time so you can just use Setup.exe to keep your application updated with your latest Project version you are working on
    Also handy to Test your Project "live" while you can make any adjustments in the VBStudio in your project at the same time without the debugger
    Hope this Helps
    Dave
    PS Forgot to mention you can also locate in your Project files
    The Bin Folder and use the .exe file from The Release Folder (NOT Debug folder)
    Last edited by davecon; 22-08-2011, 12:11 PM. Reason: oops

    Comment

    • I am the one and only223
      Junior Member
      • Sep 2009
      • 7

      #707
      Thanks Dave. I had figured out how to create the exe file, but I went through your processes and created it again. But it still gives an error. When I run it in VS2010 it runs fine. It's just the simple login example with the 3 buttons "login", "logout" and "keepalive".

      The login call gives the error:

      Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error...

      And under Details:
      System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 84.20.200.10:443

      What might be the reason that the exe fails but not the project?

      Comment

      • NFLMAN
        Junior Member
        • Jun 2010
        • 17

        #708
        Async calls and global variables

        Hyperthetical question surrounding async calls and global variables.

        I have a timer event that 'ticks' every minute.

        Sometimes the tick event hnadler takes longer than one minute to process the information. What happens when the tick events overlap? Do they overlap? I'm particularly interested to know that if they do overlap then what happens to global variables when different tick events access them.

        I'll give a scenario to explain what I'm getting at.

        Timer has been started with a 1 minute interval.
        1 minute elapses and the tick event is triggered (let's call it TickEvent1)
        TickEvent1 assign global vatiable Var1 to 0
        TickEvent1 does some processing and changes Var1 to 5
        TickEvent1 does some more processing
        TickEvent2 starts
        TickEvent2 assign global vatiable Var1 to 0
        TickEvent1 is still processing and uses the Var1 variable in a calculation
        However, Var1 has been changed by TickEvent2 to 0 but Tickevent1 needs Var1 to be 5.
        Can you see my problem?

        Comment

        • I am the one and only223
          Junior Member
          • Sep 2009
          • 7

          #709
          The reason I need an exe file is that I want to call it from Excel VBA. If somebody could explain how I can create a dll in VB2010 so that I can use the methods in my Excel VBA application then it wouldn't matter why it fails!

          Comment

          • davecon
            Junior Member
            • Dec 2010
            • 86

            #710
            Hi 223

            Zip Folder Below for Sample Spreadsheet DLL

            https://bdp.betfair.com/index.php?op...catid=59&id=11

            Dave

            Comment

            • I am the one and only223
              Junior Member
              • Sep 2009
              • 7

              #711
              Thanks Dave, now I need a tutorial on how to use the dll.

              I'll have a go tomorrow. My brain is returning a "NO SESSION" error atm!

              Comment

              • I am the one and only223
                Junior Member
                • Sep 2009
                • 7

                #712
                The BDPAPI6.dll doesn't seem to have all the API functionality. I specifically need to use the asynchronous placebets call, but the nearest call I can see in BDPAPI6.dll is placebetpage, which is not asynchronous. Anybody know if I can create a dll in VB2010 with just the login/logout/keepalive and placebetsasync calls?

                Comment

                • Camper
                  Junior Member
                  • Jul 2011
                  • 30

                  #713
                  I'm having two problems.

                  First I want to use a combobox to filter the markets by date.
                  I tried this with no luck:

                  Code:
                  Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                          ComboBox1.Items.Add("Today")
                          ComboBox1.Items.Add("Yesterday")
                          ComboBox1.Items.Add("Tomorow")
                      End Sub
                  Code:
                  Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
                          ListBox1.Items.Clear()
                          [B]Dim tempo as Integer
                          Select Case ComboBox1.SelectedIndex
                              Case 0
                                  tempo = 0
                              Case 1
                                  tempo = 1
                              Case 2
                                  tempo = 2
                          End Select[/B]
                          Dim oMarketsReq As New BFUK.GetAllMarketsReq
                          Dim oMarketsResp As BFUK.GetAllMarketsResp
                          With oMarketsReq
                              .header = oHeaderUK()
                              ReDim .eventTypeIds(0) : .eventTypeIds(0) = 2
                             [B] If tempo = 0 Then
                                  .fromDate = Today.AddDays(0)
                                  .toDate = Today.AddDays(0)
                              End If
                              If tempo = 1 Then
                                  .fromDate = Today.AddDays(-1)
                                  .toDate = Today.AddDays(-1)
                              End If
                              If tempo = 2 Then
                                  .fromDate = Today.AddDays(1)
                                  .toDate = Today.AddDays(1)
                              End If[/B]
                              .locale = "en"
                          End With
                          oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)  'Call the UK API
                          With oMarketsResp
                              CheckHeader(.header)
                              Print("ErrorCode = " & .errorCode.ToString)
                              If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                                  Dim AllMarkets As New UnpackAllMarkets(.marketData)   'Create an object and unpack the string
                                  With AllMarkets
                                      For i = 0 To .marketData.Length - 1
                                          With .marketData(i)
                                              If .marketStatus = "ACTIVE" Then
                                                  If .marketName = "Match Odds" Or .marketName = "Probabilidades" Then
                                                      Dim Items As String() = Split(.menuPath, "\")
                                                      Dim time, hour, min As String
                                                      hour = .eventDate.Hour
                                                      min = .eventDate.Minute
                                                      time = hour & ":" & min
                                                      Dim Q As New Market
                                                      Q.id = .marketId
                                                      Q.path = Items(UBound(Items))
                                                      Q.hour = time
                                                      ListBox1.Items.Add(Q)
                                                  End If
                                              End If
                                          End With
                                      Next
                                  End With
                              End If
                          End With
                      End Sub
                  It's not working at all, I have no idea.

                  The other problem I have is here:
                  Code:
                  Dim time, hour, min As String
                  hour = .eventDate.Hour
                  min = .eventDate.Minute
                  time = hour & ":" & min
                  Dim Q As New Market
                  Q.id = .marketId
                  Q.path = Items(UBound(Items))
                  Q.hour = time
                  ListBox1.Items.Add(Q)
                  It shows the time in a wrong way, lets say the match is at 16:00, it only shows 16:0, if the match it at 03:15 it only shows 3:15.

                  Thanks in advance.

                  Comment

                  • I am the one and only223
                    Junior Member
                    • Sep 2009
                    • 7

                    #714
                    Hi Camper, I may know nothing about .exe and .dll files, but I know a bit of VB.

                    For your date/time problem use the format function:
                    x=format(Now,"hh:nn")

                    so x="15:58"

                    And for your selection problem I think it's not returning anything because the fromDate is the same as the toDate. If you want today's events I think you might have to have the toDate as tomorrow.

                    Comment

                    • Camper
                      Junior Member
                      • Jul 2011
                      • 30

                      #715
                      Thanks for the help.

                      Hour, min and time are strings so I can't format them using the method you said. I figured out, It was simple after all, I've just changed this:
                      Code:
                      hour = Format(.eventDate.Hour, "00")
                      min = Format(.eventDate.Minute, "00")
                      The second problem I have I cant figure it out.
                      To select from today, tomorow, and yesterday wich values must have .fromDate and .toDate ?

                      Comment

                      • Camper
                        Junior Member
                        • Jul 2011
                        • 30

                        #716
                        I guess I founded it:

                        Today:
                        Code:
                        .fromDate = Today.AddDays(-1)
                        .toDate = Today.AddDays(1)
                        Yesterday:
                        Code:
                        .fromDate = Today.AddDays(-2)
                        .toDate = Today.AddDays(-1)
                        Tomorow:
                        Code:
                        .fromDate = Today.AddDays(1)
                        .toDate = Today.AddDays(2)

                        Comment

                        • BigSprout
                          Junior Member
                          • Feb 2011
                          • 60

                          #717
                          Camper,
                          it's as 223 suggested

                          Dim Tme=format(.eventdate, "HH:mm") ="03:10"
                          or
                          Dim Tme=format(.eventdate, "HH.mm") = "03.10"

                          Dim Dte=format(.eventdate,"yyyyMMdd") = "20110824"
                          or
                          dim Dte=format(.eventdate,"dd/MM/yyyy") = "24/08/2011"
                          or any valid combination

                          use Format the same as currency,decimal etc

                          hope this helps

                          Comment

                          • Geierkind
                            Junior Member
                            • May 2011
                            • 10

                            #718
                            Hi there. I got a problem here, which is really over my head because I really can't think of an explanation.

                            I get prices for all Markets which fit a certain criteria (cleansheet or some other), with a modified showmprices-sub:

                            [examplary for 3-Way Match Odds]
                            Code:
                            Sub ShowMprices3(ByVal MpriceResp As BFUK.GetMarketPricesResp)
                                    Dim Back1, Back2, Back3 As String
                                    With MpriceResp
                                        CheckHeader(.header)
                            
                                        If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
                                            With .marketPrices
                                                With .runnerPrices(0)
                                                    Back1 = .bestPricesToBack(0).price
                            
                                                End With
                                                With .runnerPrices(1)
                                                    Back2 = .bestPricesToBack(0).price
                            
                                                End With
                                                With .runnerPrices(2)
                                                    Back3 = .bestPricesToBack(0).price
                            
                                                End With
                                                Print(.marketId & "µ" & Back1 & "µ" & Back2 & "µ" & Back3)
                                            End With
                            
                                        End If
                                    End With
                                End Sub
                            This is the Prices-Sub (which later works without problems, the above is the sub in question I think):

                            Code:
                            Private Sub b3wprices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3wprices.Click
                                  
                                    With AllMarkets
                                        For j = 0 To AllMarkets.marketData.Length - 1
                                            If AllMarkets.marketData(j).marketName.Contains("Wettquoten") Or AllMarkets.marketData(j).marketName.Contains("Match Odds") Then
                                                iMarket = j
                                          
                                                ShowMprices3(BetFairUK.getMarketPrices(MpricesReq))    'Get market prices
                            
                            
                                            End If
                            
                                        Next
                                      
                            
                                    End With
                                End Sub
                            So far so good. Now I can build this application and it seemingly works without errors, but when I actually get all those 3-Way prices (for example) after some time (may be 3 or 5 or even 10 minutes) the application (while getting all those prices) crashes with this error-message:

                            IndexOutOfRangeException was unhandled, with the following line of ShowMprices3 marked yellow:

                            Code:
                             With .runnerPrices(0)
                            Now this is the point where I don't get it. How can the Error-Code be ok, but the .runnerPrices(0) be out of the Range of the .marketPrices array? Even with he first element?!

                            Plus, this Sub works for a few minutes like I said. All this is very confusing to me.

                            Thanks for any help.

                            Comment

                            • Camper
                              Junior Member
                              • Jul 2011
                              • 30

                              #719
                              You need to add this

                              Code:
                              With .marketPrices
                              With .runnerPrices(0)
                              [B]If .bestPricesToBack.Length > 0 Then[/B]
                              Back1 = .bestPricesToBack(0).price
                              [B]End If[/B]
                              End With

                              Comment

                              • Geierkind
                                Junior Member
                                • May 2011
                                • 10

                                #720
                                Haha, so it's really first level Thank you very much, before your solution I was confident that I already knew a little bit about it

                                Comment

                                Working...
                                X