How I can make asynchronous calls to betfair Exchange APIs using "async...await" of .net framework? Any example of this will be really good.
Asynchronous calls to betfair Exchange APIs
Collapse
X
-
-
Here is an example I use in an app. Not sure if this is exactly what you are after. I should say I did this a bit trial and error but it is simple and works well for me.
Code:Async Sub rollem() Dim markId As String Do If count > 0 Then bStart.Text = "START" bStart.BackColor = Color.Lime Exit Sub End If If Statecount = 0 Then newindex = FindIndex(lbRaces.SelectedIndex) End If lbRaces.SelectedIndex = check(newindex) markId = RaceArray(check(newindex)).Split("~").GetValue(0) Await GetInfo(markId) ‘This calls GetInfo asynchronously getinfoalert = 0 Statecount2 += 1 RaiseEvent StopLoop(blnCancel) If blnCancel Then Exit Sub tbCseTime.Text = lbRaces.SelectedItem If newindex < check.Length Then newindex += 1 End If If newindex = check.Length Then lbNears.Items.Clear() newindex = 0 End If Statecount = 1 Loop End Sub Async Function GetInfo(ByVal marketId As String) As Task attempts = 0 Dim ListMarketBookResponse As Object = Nothing Dim strRequest As String = "" Dim strMarketBook As String = "" Repeat: Try strRequest = "{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listMarketBook"", ""params"": {""marketIds"":[""" & marketId & """],""priceProjection"":{""priceData"":[""EX_BEST_OFFERS""],""virtualise"":""true"",""exBestOffersOverrides"":{""bestPricesDepth"":1}}}, ""id"": 1}" ListMarketBookResponse = CreateRequest(strKey, strSessTok, strRequest) ListBox2.Items.Clear() strMarketBook = ListMarketBookResponse.ToString ‘ Lots of other code here I’ve omitted Catch attempts += 1 If attempts < TextBox3.Text Then GoTo Repeat Else Exit Function End If End Try Await Task_MethodAsync() ‘This simply calls a small delay – could call anything, but all async subs/functions must have an accompanying await contained therein End Function
Mike
Comment