Betfair Developers

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 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
 Private Function SendSportsReq(ByVal jsonString As String)

        Dim request As HttpWebRequest = _
WebRequest.Create _

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

        Dim responseFromServer As String = ""

            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()


        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  _

    End Function
The code I used in Form1 is
 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)
        params.filter.eventTypeIds = eventTypeIds

        Dim marketProjection As New List(Of String)




        params.marketProjection = marketProjection

        'Dim marketTypeCodes As New List(Of String)


        ' 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"


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

        End If = Today.ToString("u").Replace(" ", "T").Replace("00:00", "23:00")

        params.filter.marketStartTime = marketStartTime

        request.params = params

            Dim allMarkets() As MarketCatalogueResponse
            allMarkets =
            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)

        Catch ex As NullReferenceException

        End Try
    End Sub
jabe jabe is offline
Senior Member

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

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