Here’s a quick walk through of how to access the streaming api from a vb.net project using Visual Studio.
This will allow you access the OnMarketChange event from vb.net.
1. Download the “stream-api-sample-code-master” project
2. Load the csharp version into Visual Studio.
3. Add a new project Visual Basic Windows Forms App (.NET Framework)
4. Set as startup project.
5. Add the following controls: -
a. Button cmdLogin
b. Button cmdLoadMarketID
c. TextBox txtMarketID
6. Add the references for Betair.ESAClient & Betfair.ESASwagger
7. Copy the following code into Form1.vb
8. Fill in your own username and password ect…
9. The important point is that because the _clientCache has been created in the vb code the OnMarketChanged event will work. (AddHandler _clientCache.MarketCache.MarketChanged, AddressOf OnMarketChanged)
10. The market data filter has been set to ExBestOffersDisp and LadderLevels = 3.
11. By using the debugger you can access the c# code and make changes to the GetOrCreateNewSession functions ect…
12. The format of the Market Id the text box is 1.133391123
Replace you vb.net Form1 code with this:-
This will allow you access the OnMarketChange event from vb.net.
1. Download the “stream-api-sample-code-master” project
2. Load the csharp version into Visual Studio.
3. Add a new project Visual Basic Windows Forms App (.NET Framework)
4. Set as startup project.
5. Add the following controls: -
a. Button cmdLogin
b. Button cmdLoadMarketID
c. TextBox txtMarketID
6. Add the references for Betair.ESAClient & Betfair.ESASwagger
7. Copy the following code into Form1.vb
8. Fill in your own username and password ect…
9. The important point is that because the _clientCache has been created in the vb code the OnMarketChanged event will work. (AddHandler _clientCache.MarketCache.MarketChanged, AddressOf OnMarketChanged)
10. The market data filter has been set to ExBestOffersDisp and LadderLevels = 3.
11. By using the debugger you can access the c# code and make changes to the GetOrCreateNewSession functions ect…
12. The format of the Market Id the text box is 1.133391123
Replace you vb.net Form1 code with this:-
Code:
Imports Betfair.ESAClient.Cache
Imports Betfair.ESAClient.Auth
Imports Betfair.ESAClient
Imports Betfair.ESASwagger.Model
Imports Betfair.ESASwagger.Model.MarketDataFilter
Public Class Form1
Dim ssohost As String = "identitysso.betfair.com"
Dim appkey As String = "???????????????"
Dim username As String = "???????????????"
Dim password As String = "???????????????"
Dim _host As String = "stream-api-integration.betfair.com"
Dim _port As Integer = 443
Dim host As String = "stream-api-integration.betfair.com"
Dim port As Integer = 443
Dim SessionProvider As AppKeyAndSessionProvider
Public _clientCache As ClientCache
Private Sub cmdLogin_Click(sender As Object, e As EventArgs) Handles cmdLogin.Click
Login()
End Sub
Private Sub cmdLoadMarketID_Click(sender As Object, e As EventArgs) Handles cmdLoadMarketID.Click
SubscribeMarkets(txtMarketID.Text)
End Sub
Public Sub NewSessionProvider(ByVal ssohost As String,
ByVal appkey As String,
ByVal username As String,
ByVal password As String)
Try
Dim oSessionProvider As AppKeyAndSessionProvider = New AppKeyAndSessionProvider(ssohost, appkey, username, password)
SessionProvider = oSessionProvider
Catch oException As System.Exception
'HandleException("NewSessionProvider:", oException.ToString)
End Try
End Sub
Public Sub Login()
Try
NewSessionProvider(ssohost, appkey, username, password)
SessionProvider.GetOrCreateNewSession()
ESA_SetupMarketChangeEvent()
Catch oException As System.Exception
'HandleException("SaveLogin:", oException.ToString)
End Try
End Sub
Public Sub ESA_SetupMarketChangeEvent()
Try
Dim oClient As Client = New Client(_host, _port, SessionProvider)
_clientCache = New ClientCache(oClient)
AddHandler _clientCache.MarketCache.MarketChanged, AddressOf OnMarketChanged
Catch oException As System.Exception
'HandleException("ESA_SetupMarketChangeEvent:", oException.ToString)
End Try
End Sub
Public Sub SubscribeMarkets(ByVal strMaketID As String)
Dim oMarketDataFilter As New MarketDataFilter
Dim listFields As New List(Of MarketDataFilter.FieldsEnum?)
listFields.Add(FieldsEnum.ExBestOffersDisp)
oMarketDataFilter.Fields = listFields
oMarketDataFilter.LadderLevels = 3
_clientCache.MarketDataFilter = oMarketDataFilter
_clientCache.SubscribeMarkets(strMaketID)
End Sub
Public Sub OnMarketChanged(ByVal sender As Object, ByVal e As MarketChangedEventArgs)
Try
Dim oMarketSnap As Betfair.ESAClient.Cache.MarketSnap
oMarketSnap = e.Snap
If oMarketSnap.MarketId = Nothing Then
Exit Sub
End If
Dim dblTraded As Double
dblTraded = e.Snap.TradedVolume
Catch oException As System.Exception
' HandleException("OnMarketChanged", oException.ToString)
End Try
End Sub
End Class


Comment