Betfair Developers


.NET
Discussion about the .NET Framework (C#/VB), Microsoft's platform for building applications that have visually stunning user experiences, seamless and secure communication, and the ability to model a range of business processes.

Post Reply
nestor1971 nestor1971 is offline
Junior Member
 
Default Vb.net filter tennis markets

Hi, in my application I would only receive Atp and Wta encounters, you know how I can do it,
The code I used in Module1 is
Code:
 Private Function SendSportsReq(ByVal jsonString As String)

        Dim request As HttpWebRequest = _
WebRequest.Create _
("https://api.betfair.com/exchange/betting/json-rpc/v1")

        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(jsonString)

        Dim responseFromServer As String = ""

        Try
            request.Method = "POST"
            request.ContentType = "application/json"
            request.ContentLength = byteArray.Length
            request.Headers.Add("X-Application: " & appKey)
            request.Headers.Add("X-Authentication: " & SessionToken)
            request.AutomaticDecompression = _
DecompressionMethods.GZip Or DecompressionMethods.Deflate
            request.ServicePoint.Expect100Continue = False
            request.Timeout = 2000

            Dim dataStream As Stream = request.GetRequestStream()
            dataStream.Write(byteArray, 0, byteArray.Length)

            Dim response As WebResponse = request.GetResponse()
            dataStream = response.GetResponseStream()

            Dim reader As New StreamReader(dataStream)
            responseFromServer = reader.ReadToEnd()

            Form1.Print(responseFromServer)
            reader.Dispose()
            dataStream.Dispose()
            response.Dispose()

        Catch ex As WebException 'Exception
            Form1.Print("SendSportsReq Error: " & ex.Message)
        End Try

        Return responseFromServer

    End Function

    'Classi e funzioni per la richiesta catalogo Mercato
    Public Class MarketCatalogueRequest
        Public jsonrpc As String = "2.0"
        Public method As String ="sportsAPING/V1.0/listMarketCatalogue"
        Public params As New Params
        Public id As Integer = 1
    End Class

    Public Class Params
        Public filter As New Filter
        Public sort As String = "FIRST_TO_START"
        Public maxResults As String = "200"
        Public marketProjection As New List(Of String)
    End Class

    Public Class Filter
        Public eventTypeIds As New List(Of String)
        Public marketTypeCodes As New List(Of String)
        Public marketStartTime As New StartTime
    End Class

    Public Class StartTime
        Public [to] As String
    End Class

    Function SerializeMarketCatalogueRequest(ByVal requestList As  _
        List(Of MarketCatalogueRequest))

        ' Dim temp As String = JsonConvert.SerializeObject(requestList)
        '  Form1.Print(temp)

        ' Form1.Print("")

        ' Return temp

        Return JsonConvert.SerializeObject(requestList)

    End Function

    'Classi e funzione di risposta listMarketCatalogue
    Public Class MarketCatalogueResponse
        Public jsonrpc As String
        Public result As List(Of MarketCatalogue)
        Public id As Integer
    End Class

    Public Class MarketCatalogue
        Public marketId As String
        Public marketName As String
        Public marketStartTime As String
        Public totalMatched As Double
        Public runners As New List(Of Runners)()
        Public [event] As New [Event]
    End Class

    Public Class Runners
        Public selectionId As Integer
        Public runnerName As String
        Public handicap As Double
        Public sortPriority As Integer
    End Class

    Public Class [Event]
        Public id As Integer
        Public name As String
        Public countryCode As String
        Public timezone As String
        Public venue As String
        Public openDate As String
    End Class

    Function DeserializeMarketCatalogueResponse(ByVal jsonResponse As String)

        Return JsonConvert.DeserializeObject(Of  _
        MarketCatalogueResponse())(SendSportsReq(jsonResponse))

    End Function
The code I used in Form1 is
Code:
 Private Sub ListMarketCatalogue()

        Dim requestList As New List(Of MarketCatalogueRequest)

        Dim request As New MarketCatalogueRequest

        Dim params As New Params

        Dim eventTypeIds As New List(Of String)
        eventTypeIds.Add("2")
        params.filter.eventTypeIds = eventTypeIds

        Dim marketProjection As New List(Of String)

        marketProjection.Add("MARKET_START_TIME")

        marketProjection.Add("RUNNER_DESCRIPTION")

        marketProjection.Add("EVENT")

        params.marketProjection = marketProjection

        'Dim marketTypeCodes As New List(Of String)

        'marketTypeCodes.Add("MATCH_ODDS")

        ' params.filter.marketTypeCodes = marketTypeCodes

        Dim marketStartTime As New StartTime

        If Today.IsDaylightSavingTime() Then

            marketStartTime.from = Format(Date.Now, "yyyy-MM-dd") & "T" & _
                Format(Now.AddHours(-2), "HH:mm") & "Z"

        Else

            marketStartTime.from = Format(Date.Now, "yyyy-MM-dd") & "T" & _
             Format(Now.AddHours(-1), "HH:mm") & "Z"

        End If

        marketStartTime.to = Today.ToString("u").Replace(" ", "T").Replace("00:00", "23:00")

        params.filter.marketStartTime = marketStartTime

        request.params = params
        requestList.Add(request)

      Try
            Dim allMarkets() As MarketCatalogueResponse
            allMarkets =
            DeserializeMarketCatalogueResponse(SerializeMarketCatalogueRequest(requestList))
            For i = 0 To allMarkets(0).result.Count - 1
                marketsListBox.Items.Add(Format(allMarkets(0).result(i).marketStartTime _
              , "Short Time") & "  " & allMarkets(0).result(i).marketId)
            Next

        Catch ex As NullReferenceException

        End Try
    End Sub
jabe jabe is offline
Senior Member
 
Default

Hi. For future reference, with this kind of thing, it always helps would-be helpers to see what the JSON string you're sending actually looks like, rather than have them wade through all that code without knowing whether the JSON string is ever properly formed. By all means also post the code so we can see where any errors might have crept in. It also helps to see what any returned strings look like, even if you do have to cut them down to make them suitable for posting.
jabe jabe is offline
Senior Member
 
Default

I've looked at listCompetitions and they only list the tournament name without specifying LTA or WTA. I've looked at listEvents and listMarketCatalogue and neither have any reference to the LTA or WTA.

Although I specified COMPETITION in marketProjection for the listMarketCatalogue, none was returned.
Post Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump