Is there any VB.Net Windows Form App demo programs for acessing the Betfair API?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joshtas
    Junior Member
    • Nov 2024
    • 2

    #1

    Is there any VB.Net Windows Form App demo programs for acessing the Betfair API?

    Hi all.
    Years ago when I was playing around with the Betfair API and VB6, I was able to get markets and list odds, etc.
    I'm trying to get back into it, and finding it difficult, as a lot of the posts seem to be related to the older API that, I guess, no longer works.

    I have seen people suggesting using the C sharp demo program that is stickied, and then referencing/calling that C Sharp code from within VB.net... but I can't work it out, most of my experience is with VB6, and am still learning my way around VB.net.

    I have ran the demo program and created an App Key and a Session Token, but am a bit stuck from where to go from here.

    Any suggestions, references, links or advice greatly appreciated.
  • bfexplorer
    Senior Member
    • Sep 2018
    • 204

    #2
    https://github.com/StefanBelo/Bfexpl...iVB/Program.vb



    Imports System.ComponentModel
    Imports BeloSoft.Betfair.StreamingAPI
    Imports BeloSoft.Betfair.StreamingAPI.Models
    Imports BeloSoft.Bfexplorer
    Imports BeloSoft.Bfexplorer.Domain
    Imports BeloSoft.Bfexplorer.Service
    Imports Microsoft.FSharp.Collections

    Module Program
    Private Function GetUserNameAndPassword() As (UserName As String, Password As String)?
    Dim entryParameters = Command.Split(" ")

    If entryParameters.Length = 2 Then
    Return (entryParameters(0), entryParameters(1))
    Else
    Return Nothing
    End If
    End Function

    Public Sub OnMarketPropertyChanged(sender As Object, args As PropertyChangedEventArgs)
    If args.PropertyName = "TotalMatched" Then
    Dim market = CType(sender, Market)

    Console.WriteLine($"{market}: {market.TotalMatched:N2}")
    End If
    End Sub

    Public Sub OnMarketsOpened(sender As Object, markets As FSharpList(Of Market))
    For Each market In markets
    Console.WriteLine($"{market}")
    AddHandler CType(market, INotifyPropertyChanged).PropertyChanged, AddressOf OnMarketPropertyChanged
    Next
    End Sub

    Async Function Execute() As Task
    Dim result = GetUserNameAndPassword()

    If Not result.HasValue Then
    Throw New Exception("Please enter your betfair user name and password!")
    End If

    Dim bfexplorerService = New BfexplorerService(initializeBotManager:=False) With {
    .UiApplication = New BfexplorerHost()
    }

    Dim loginResult = Await bfexplorerService.Login(result?.UserName, result?.Password).ExecuteAsyncTask()

    If loginResult.IsSuccess Then
    Dim marketUpdateService = New MarketUpdateService(bfexplorerService, StreamingData.MarketDataFilterForPassiveMarkets)

    AddHandler marketUpdateService.OnMarketsOpened, AddressOf OnMarketsOpened

    Dim startResult = Await marketUpdateService.Start().ExecuteAsyncTask()

    If startResult.IsSuccessResult Then
    ' Horse Racing
    Dim filter = ListModule.OfArray(New BetEventFilterParameter() {
    BetEventFilterParameter.NewBetEventTypeIds(New Integer() {7}),
    BetEventFilterParameter.NewMarketTypeCodes(New String() {"WIN"}),
    BetEventFilterParameter.NewCountries(New String() {"GB"})
    })

    Dim subscribeResult = Await marketUpdateService.Subscribe(filter).ExecuteAsync Task()

    Dim message As String

    If subscribeResult.IsSuccessResult Then
    message = If(marketUpdateService.ConnectionHasSuccessStatus, "Successfully subscribed.", $"Failed to subscribe: {marketUpdateService.ErrorMessage}")
    Else
    message = subscribeResult.FailureMessage
    End If

    Console.WriteLine($"{message}\nPress any key to exit.")
    Console.ReadKey()
    End If

    Await bfexplorerService.Logout().ExecuteAsyncTask()
    End If
    End Function

    Sub Main()
    Execute().Wait()
    End Sub
    End Module​

    Comment

    • jabe
      Senior Member
      • Dec 2014
      • 698

      #3
      Originally posted by joshtas View Post
      Any suggestions, references, links or advice greatly appreciated.
      My usual suggestion is to write yourself data-only classes for the data and data types returned by each call. It's all in the documentation. That way you get to understand how all the data is related. Read about JSON and how data can be sent to and received from Betfair using it. When you understand the data, you can see that there is a hierarchy of calls you need to make to get the data you want. I've explained the hierarchy in several posts on here over time, so it'll be there when you need it. It's a steep learning curve, so give yourself time to get to know it and don't expect it all to come at once.

      Comment

      • joshtas
        Junior Member
        • Nov 2024
        • 2

        #4
        Thank you bfexplorer, I appreciate the code.
        Thank you also jabe, I will have to get my head around JSON from the look of it.

        Comment

        • jabe
          Senior Member
          • Dec 2014
          • 698

          #5
          You will need to add the JSON processing into VS Studio. It's easy enough once you've got it. The JSON addition can convert a returned JSON string directly into your specified data class (and the other way round), Some of your data classes will include other classes for each of which you'll also need to set up classes. You can recognise these easily enough in the documentation because they are not VB data types.

          Comment

          Working...
          X