VBNet Sample (Yes really)

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davecon
    Junior Member
    • Dec 2010
    • 86

    #106
    Hi Simon
    Try
    Dim dFromDate As Date : dFromDate = #1/16/2015 4:00:00 PM#
    Dim dToDate As Date : dToDate = #1/16/2015 4:30:00 PM#
    '** Now you convert to the String **
    Dim FromDate As String : FromDate = Format(dFromDate, "yyyy-MM-ddTHH:mm:ssZ")
    Dim ToDate As String : ToDate = Format(dToDate, "yyyy-MM-ddTHH:mm:ssZ")

    You were doing 10 (October)anyways

    Comment

    • davecon
      Junior Member
      • Dec 2010
      • 86

      #107
      Simon
      There is also a venues filter for Horse Racing in marketCatalogue
      ""venues"":[""Lingfield""] will return just this meeting


      GetListMarketCatalogueRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""marketCountries"":[""GB""],""marketTypeCodes"":[""WIN""],""marketStartTime"":{""from"":""" & FromDate & """,""to"":""" & ToDate & """} ,""venues"":[""Lingfield""] },""sort"":""FIRST_TO_START"",""maxResults"":" " 10"",""marketProjection"":[""RUNNER_DESCRIPTION"",""MARKET_START_TIME""]}"

      You can Call listVenues (Does what it says on the Can)
      Dim strList_Venues As String = _
      "{""jsonrpc"": ""2.0"", ""method"":""SportsAPING/v1.0/listVenues"",""params"":{""filter"":{""eventTypeId s"":[""7""],""marketCountries"":[" & GetCountries() & "],""marketStartTime"":{""from"":""" & FromToday() & """,""to"":""" & ToTodayPlus(nudAddDays.Value) & """}}},""id"":1}"

      Dave

      Comment

      • SimonN
        Junior Member
        • Dec 2014
        • 71

        #108
        Top of the pops guys - thank you !!

        That's it working beautifully with your great help!

        Betdynamics, I did actually add an extra second (or was it millisecond) onto the "to date" but as you Dave astutely point out my month and day were the wrong way around - no wonder the JSON string returned blank lol!

        That's what you get when you tryna do it at 3 o clock in the am!

        Dave you neatly anticipated my next baby step incorporating the venue together with the date..so now that's working together nicely and will work on getting a particular runner from it next.

        By the way, I didnt need to use :


        You can Call listVenues (Does what it says on the Can)
        Dim strList_Venues As String = _
        "{""jsonrpc"": ""2.0"", ""method"":""SportsAPING/v1.0/listVenues"",""params"":{""filter"":{""eventTypeId s"":[""7""],""marketCountries"":[" & GetCountries() & "],""marketStartTime"":{""from"":""" & FromToday() & """,""to"":""" & ToTodayPlus(nudAddDays.Value) & """}}},""id"":1}"
        This just slotted into the sample program already -

        GetListMarketCatalogueRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""marketCountries"":[""GB""],""marketTypeCodes"":[""WIN""],""marketStartTime"":{""from"":""" & FromDate & """,""to"":""" & ToDate & """} ,""venues"":[""Lingfield""] },""sort"":""FIRST_TO_START"",""maxResults"":" " 10"",""marketProjection"":[""RUNNER_DESCRIPTION"",""MARKET_START_TIME""]}"
        However, I am curious about "ToTodayPlus(nudAddDays.Value)" since I maybe should validate for null returns or errors.

        Am so happy for the help here - I really dunno where I was gonna turn after this lol!

        Cheers, S

        Comment

        • davecon
          Junior Member
          • Dec 2010
          • 86

          #109
          Hi Si
          Sorry to Confuse with "ToTodayPlus(nudAddDays.Value)" , I was just being lazy and pasted my own request string which uses a Date Function with a Windows NumericUpDown Control with my Function ToTodayPlus(Optional AddDays As Integer = 0)

          You would use your own Date/Time methods but may I just add that the API will only return the Content that is on the Site regardless of how many Days you ask for (With Racing you only get Todays cards then they add Tomorrow in UK afternoon) Unless you want AntePost etc

          So to Get all of the Todays Venues (By entering Date Manually) for 17th Jan or similar you would use

          Code:
          Dim strList_Venues As String = _
                       "{""jsonrpc"": ""2.0"", ""method"":""SportsAPING/v1.0/listVenues"",""params"":{""filter"":{""eventTypeIds"":[""7""],""marketCountries"":[""GB""],""marketStartTime"":{""from"": ""2015-01-17T00:00:00Z"",""to"":""2015-01-17T23:59:00Z""}}},""id"":1}"
          This would return all Todays venues/Meetings available in Json

          {"jsonrpc":"2.0","result":[{"venue":"Haydock","marketCount":14},{"venue":"Asc ot","marketCount":14},{"venue":"Lingfield","market Count":12},{"venue":"Taunton","marketCount":12}],"id":1}

          You could then use a Function to add the required Venues (Best Seeing you need to add double-double quotes in VB to get your venues string) to your Catalogue Call

          eg [""Haydock""] Or [""Haydock",""Lingfield"",""Ascot""] etc

          Dave

          ps Dont know why pasting stuff in here produces gaps sometimes eg "Asc ot"

          Comment

          • SimonN
            Junior Member
            • Dec 2014
            • 71

            #110
            Hello Davecon and Betdynamics,

            Sorry I haven't been able to reply till now - one thing and another mounting up.

            I continue to work away on my little Excel app and thank you for your help - can't tell you how much frustration you saved me.

            Am not there yet but in due course I am going to be looking at why the ServiceClientNG-SampleSpreadsheet.xlsm file place bets function is not working but that's a step or two down the road ahead.

            Will doubtless be back with more perplexing (to me anyway) issues if that's okay.

            I have done quite a bit of VBA but am derusting but this betfair stuff is all new so I very much appreciate your help.

            Kind regards,

            Si

            Comment

            • granted
              Junior Member
              • Jun 2009
              • 14

              #111
              hi guys

              i am just going thru the basic app and its code

              how would i add code to be able to place a bet using the basic app on page 1?
              Last edited by granted; 26-02-2015, 05:55 AM.

              Comment

              • nestor1971
                Junior Member
                • Sep 2014
                • 5

                #112
                Listmarketbook

                Hi,
                I have a problem with listmarketbook as image not seen all market prices
                http://imageshack.com/a/img538/3122/l5VIgj.png
                I used the code which gave me Davecon
                code Market Book Class is
                Code:
                '{"jsonrpc":"2.0","result":[{"marketId":"1.112356482","isMarketDataDelayed":true,"status":"OPEN","betDelay":0,"bspReconciled":false,"complete":true,"inplay":false,"numberOfWinners":1,"numberOfRunners":7,"numberOfActiveRunners":7,"totalMatched":9052.89,"totalAvailable":45390.63,"crossMatching":true,"runnersVoidable":false,"version":665893793,"runners":[{"selectionId":7860579,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":35.0,"totalMatched":0.0,"ex":{"availableToBack":[{"price":3.0,"size":12.0},{"price":2.92,"size":9.72},{"price":2.9,"size":61.49}],"availableToLay":[{"price":3.05,"size":21.22},{"price":3.1,"size":40.0},{"price":3.15,"size":3.24}],"tradedVolume":[]}},{"selectionId":7554252,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":27.7,"totalMatched":0.0,"ex":{"availableToBack":[{"price":3.45,"size":21.62},{"price":3.35,"size":16.72},{"price":3.3,"size":14.0}],"availableToLay":[{"price":3.5,"size":46.95},{"price":3.55,"size":24.32},{"price":3.6,"size":12.89}],"tradedVolume":[]}},{"selectionId":7267924,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":16.6,"totalMatched":0.0,"ex":{"availableToBack":[{"price":5.7,"size":14.01},{"price":5.6,"size":32.0},{"price":5.5,"size":53.0}],"availableToLay":[{"price":6.0,"size":13.32},{"price":6.2,"size":25.0},{"price":6.4,"size":3.89}],"tradedVolume":[]}},{"selectionId":7323197,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":8.3,"totalMatched":0.0,"ex":{"availableToBack":[{"price":11.0,"size":8.74},{"price":9.8,"size":4.03},{"price":9.2,"size":3.63}],"availableToLay":[{"price":12.0,"size":8.0},{"price":12.5,"size":4.97},{"price":13.0,"size":13.31}],"tradedVolume":[]}},{"selectionId":7588394,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":5.0,"totalMatched":0.0,"ex":{"availableToBack":[{"price":20.0,"size":2.51},{"price":18.0,"size":2.07},{"price":17.5,"size":3.54}],"availableToLay":[{"price":22.0,"size":4.68},{"price":23.0,"size":6.0},{"price":25.0,"size":3.62}],"tradedVolume":[]}},{"selectionId":7554256,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":4.5,"totalMatched":0.0,"ex":{"availableToBack":[{"price":24.0,"size":4.45},{"price":23.0,"size":9.48},{"price":22.0,"size":6.65}],"availableToLay":[{"price":29.0,"size":5.15},{"price":30.0,"size":3.64},{"price":38.0,"size":3.72}],"tradedVolume":[]}},{"selectionId":7615290,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":2.8,"totalMatched":0.0,"ex":{"availableToBack":[{"price":36.0,"size":4.35},{"price":34.0,"size":3.48},{"price":32.0,"size":2.72}],"availableToLay":[{"price":50.0,"size":3.65},{"price":55.0,"size":7.59},{"price":60.0,"size":2.0}],"tradedVolume":[]}}]}],"id":1}
                Imports Newtonsoft.Json '~~> Enable the the use of Json Objects
                Imports Newtonsoft.Json.Converters
                Public Class MarketBook
                    Private m_result As List(Of BookInfo) '~~> "result"
                    <JsonProperty(PropertyName:="result")> _
                    Public Property Result() As List(Of BookInfo) '~~> This can now be called anything InfoResult etc
                        Get
                            Return m_result
                        End Get
                        Set(value As List(Of BookInfo))
                            m_result = value
                        End Set
                    End Property '"result" 
                End Class 'MarketBook Top Level
                Public Class BookInfo
                    Private m_marketId As String
                    <JsonProperty(PropertyName:="marketId")> _
                    Public Property MarketId() As String
                        Get
                            Return m_marketId
                        End Get
                        Set(value As String)
                            m_marketId = value
                        End Set
                    End Property '~~>"marketId" for Meeting
                    <JsonProperty(PropertyName:="isMarketDataDelayed")> _
                    Public Property IsMarketDataDelayed() As Boolean
                        Get
                            Return m_IsMarketDataDelayed
                        End Get
                        Set(value As Boolean)
                            m_IsMarketDataDelayed = Value
                        End Set
                    End Property
                    Private m_IsMarketDataDelayed As Boolean
                    <JsonProperty(PropertyName:="status")> _
                    Public Property MarketStatus() As MarketStatus
                        Get
                            Return m_Status
                        End Get
                        Set(value As MarketStatus)
                            m_Status = value
                        End Set
                    End Property
                    Private m_Status As MarketStatus
                    <JsonProperty(PropertyName:="betDelay")> _
                    Public Property BetDelay() As Integer
                        Get
                            Return m_BetDelay
                        End Get
                        Set(value As Integer)
                            m_BetDelay = value
                        End Set
                    End Property
                    Private m_BetDelay As Integer
                    <JsonProperty(PropertyName:="bspReconciled")> _
                    Public Property IsBspReconciled() As Boolean
                        Get
                            Return m_IsBspReconciled
                        End Get
                        Set(value As Boolean)
                            m_IsBspReconciled = Value
                        End Set
                    End Property
                    Private m_IsBspReconciled As Boolean
                    <JsonProperty(PropertyName:="complete")> _
                    Public Property IsComplete() As Boolean
                        Get
                            Return m_IsComplete
                        End Get
                        Set(value As Boolean)
                            m_IsComplete = value
                        End Set
                    End Property
                    Private m_IsComplete As Boolean
                    <JsonProperty(PropertyName:="inplay")> _
                    Public Property IsInplay() As Boolean
                        Get
                            Return m_IsInplay
                        End Get
                        Set(value As Boolean)
                            m_IsInplay = value
                        End Set
                    End Property
                    Private m_IsInplay As Boolean
                    <JsonProperty(PropertyName:="numberOfWinners")> _
                    Public Property NumberOfWinners() As Integer
                        Get
                            Return m_NumberOfWinners
                        End Get
                        Set(value As Integer)
                            m_NumberOfWinners = Value
                        End Set
                    End Property
                    Private m_NumberOfWinners As Integer
                    <JsonProperty(PropertyName:="numberOfRunners")> _
                    Public Property NumberOfRunners() As Integer
                        Get
                            Return m_NumberOfRunners
                        End Get
                        Set(value As Integer)
                            m_NumberOfRunners = value
                        End Set
                    End Property
                    Private m_NumberOfRunners As Integer
                    <JsonProperty(PropertyName:="numberOfActiveRunners")> _
                    Public Property NumberOfActiveRunners() As Integer
                        Get
                            Return m_NumberOfActiveRunners
                        End Get
                        Set(value As Integer)
                            m_NumberOfActiveRunners = Value
                        End Set
                    End Property
                    Private m_NumberOfActiveRunners As Integer
                    <JsonProperty(PropertyName:="lastMatchTime")> _
                    Public Property LastMatchTime() As System.Nullable(Of DateTime)
                        Get
                            Return m_LastMatchTime
                        End Get
                        Set(value As System.Nullable(Of DateTime))
                            m_LastMatchTime = value
                        End Set
                    End Property
                    Private m_LastMatchTime As System.Nullable(Of DateTime)
                    <JsonProperty(PropertyName:="totalMatched")> _
                    Public Property TotalMatched() As Double
                        Get
                            Return m_TotalMatched
                        End Get
                        Set(value As Double)
                            m_TotalMatched = value
                        End Set
                    End Property
                    Private m_TotalMatched As Double
                    <JsonProperty(PropertyName:="totalAvailable")> _
                    Public Property TotalAvailable() As Double
                        Get
                            Return m_TotalAvailable
                        End Get
                        Set(value As Double)
                            m_TotalAvailable = Value
                        End Set
                    End Property
                    Private m_TotalAvailable As Double
                    <JsonProperty(PropertyName:="crossMatching")> _
                    Public Property IsCrossMatching() As Boolean
                        Get
                            Return m_IsCrossMatching
                        End Get
                        Set(value As Boolean)
                            m_IsCrossMatching = value
                        End Set
                    End Property
                    Private m_IsCrossMatching As Boolean
                    <JsonProperty(PropertyName:="runnersVoidable")> _
                    Public Property IsRunnersVoidable() As Boolean
                        Get
                            Return m_IsRunnersVoidable
                        End Get
                        Set(value As Boolean)
                            m_IsRunnersVoidable = value
                        End Set
                    End Property
                    Private m_IsRunnersVoidable As Boolean
                    <JsonProperty(PropertyName:="version")> _
                    Public Property Version() As Long
                        Get
                            Return m_Version
                        End Get
                        Set(value As Long)
                            m_Version = value
                        End Set
                    End Property
                    Private m_Version As Long
                    <JsonProperty(PropertyName:="runners")> _
                    Public Property Runners() As List(Of Runners)
                        Get
                            Return m_Runners
                        End Get
                        Set(value As List(Of Runners))
                            m_Runners = value
                        End Set
                    End Property
                    Private m_Runners As List(Of Runners)
                End Class 'Book Info
                Public Class Runners
                    <JsonProperty(PropertyName:="selectionId")> _
                    Public Property SelectionId() As Long
                        Get
                            Return m_SelectionId
                        End Get
                        Set(value As Long)
                            m_SelectionId = value
                        End Set
                    End Property
                    Private m_SelectionId As Long
                    <JsonProperty(PropertyName:="handicap")> _
                    Public Property Handicap() As System.Nullable(Of Double)
                        Get
                            Return m_Handicap
                        End Get
                        Set(value As System.Nullable(Of Double))
                            m_Handicap = Value
                        End Set
                    End Property
                    Private m_Handicap As System.Nullable(Of Double)
                    <JsonProperty(PropertyName:="status")> _
                    Public Property RunnerStatus() As RunnerStatus
                        Get
                            Return m_Status
                        End Get
                        Set(value As RunnerStatus)
                            m_Status = value
                        End Set
                    End Property
                    Private m_Status As RunnerStatus
                    <JsonProperty(PropertyName:="adjustmentFactor")> _
                    Public Property AdjustmentFactor() As System.Nullable(Of Double)
                        Get
                            Return m_AdjustmentFactor
                        End Get
                        Set(value As System.Nullable(Of Double))
                            m_AdjustmentFactor = value
                        End Set
                    End Property
                    Private m_AdjustmentFactor As System.Nullable(Of Double)
                    <JsonProperty(PropertyName:="lastPriceTraded")> _
                    Public Property LastPriceTraded() As System.Nullable(Of Double)
                        Get
                            Return m_LastPriceTraded
                        End Get
                        Set(value As System.Nullable(Of Double))
                            m_LastPriceTraded = value
                        End Set
                    End Property
                    Private m_LastPriceTraded As System.Nullable(Of Double)
                    <JsonProperty(PropertyName:="totalMatched")> _
                    Public Property TotalMatched() As Double
                        Get
                            Return m_TotalMatched
                        End Get
                        Set(value As Double)
                            m_TotalMatched = value
                        End Set
                    End Property
                    Private m_TotalMatched As Double
                    'SPSP Pre off
                    '"runners":[{"selectionId":7934226,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":22.9,"lastPriceTraded":4.6,"totalMatched":14270.64,"sp":{"nearPrice":4.7,"farPrice":6.262127089148748,"backStakeTaken":[],"layLiabilityTaken":[]},"ex":{"availableToBack":[{"price":4.6,"size":76.83}],"availableToLay":[{"price":4.7,"size":82.07}],"tradedVolume":[]}},{"
                    'Off
                    '"runners":[{"selectionId":8587406,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":23.3,"lastPriceTraded":5.0,"totalMatched":136460.37,"sp":{"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":4.4},"ex":{"availableToBack":[{"price":5.0,"size":113.74}],"availableToLay":[{"price":5.5,"size":2.0}],"tradedVolume":[]}},{"
                    <JsonProperty(PropertyName:="sp")> _
                    Public Property StartingPrices() As StartingPrices
                        Get
                            Return m_StartingPrices
                        End Get
                        Set(value As StartingPrices)
                            m_StartingPrices = value
                        End Set
                    End Property
                    Private m_StartingPrices As StartingPrices
                    <JsonProperty(PropertyName:="ex")> _
                    Public Property ExchangePrices() As ExchangePrices
                        Get
                            Return m_ExchangePrices
                        End Get
                        Set(value As ExchangePrices)
                            m_ExchangePrices = value
                        End Set
                    End Property
                    Private m_ExchangePrices As ExchangePrices
                End Class 'Runners
                Public Class StartingPrices
                    <JsonProperty(PropertyName:="nearPrice")> _
                    Public Property NearPrice() As Double
                        Get
                            ' Return Math.Round(m_nearPrice, 2)
                            Return m_nearPrice
                        End Get
                        Set(value As Double)
                            m_nearPrice = value
                        End Set
                    End Property
                    Private m_nearPrice As Double
                    <JsonProperty(PropertyName:="farPrice")> _
                    Public Property FarPrice() As Double
                        Get
                            'Return Math.Round(m_farPrice, 2)
                            Return m_farPrice
                        End Get
                        Set(value As Double)
                            m_farPrice = value
                        End Set
                    End Property
                    Private m_farPrice As Double
                    <JsonProperty(PropertyName:="actualSP")> _
                    Public Property ActualSP() As Double
                        Get
                            'Return Math.Round(m_farPrice, 2)'Or Format in app
                            Return m_actualSP
                        End Get
                        Set(value As Double)
                            m_actualSP = value
                        End Set
                    End Property
                    Private m_actualSP As Double
                End Class 'StartingPrices
                Public Class ExchangePrices
                    <JsonProperty(PropertyName:="availableToBack")> _
                    Public Property AvailableToBack() As List(Of PriceSize)
                        Get
                            Return m_AvailableToBack
                        End Get
                        Set(value As List(Of PriceSize))
                            m_AvailableToBack = value
                        End Set
                    End Property
                    Private m_AvailableToBack As List(Of PriceSize)
                    <JsonProperty(PropertyName:="availableToLay")> _
                    Public Property AvailableToLay() As List(Of PriceSize)
                        Get
                            Return m_AvailableToLay
                        End Get
                        Set(value As List(Of PriceSize))
                            'If AvailableToLay IsNot Nothing AndAlso AvailableToLay.Count > 0 Then
                            m_AvailableToLay = value
                            'End If
                        End Set
                    End Property
                    Private m_AvailableToLay As List(Of PriceSize)
                    <JsonProperty(PropertyName:="tradedVolume")> _
                    Public Property TradedVolume() As List(Of PriceSize)
                        Get
                            Return m_TradedVolume
                        End Get
                        Set(value As List(Of PriceSize))
                            m_TradedVolume = value
                        End Set
                    End Property
                    Private m_TradedVolume As List(Of PriceSize)
                End Class 'Xchange Prices
                Public Class PriceSize
                    <JsonProperty(PropertyName:="price")> _
                    Public Property Price() As Double
                        Get
                            Return m_Price
                        End Get
                        Set(value As Double)
                            m_Price = value
                        End Set
                    End Property
                    Private m_Price As Double
                    <JsonProperty(PropertyName:="size")> _
                    Public Property Size() As Double
                        Get
                            Return m_Size
                        End Get
                        Set(value As Double)
                            m_Size = value
                        End Set
                    End Property
                    Private m_Size As Double
                End Class 'PriceSize
                <JsonConverter(GetType(StringEnumConverter))> _
                Public Enum MarketStatus
                    INACTIVE
                    OPEN
                    SUSPENDED
                    CLOSED
                End Enum
                <JsonConverter(GetType(StringEnumConverter))> _
                Public Enum RunnerStatus
                    ACTIVE
                    WINNER
                    LOSER
                    REMOVED_VACANT
                    REMOVED
                End Enum
                code ListMarketBook is
                Code:
                Sub LoadMktBook()
                        'When the race finishes they put the non-runners to the Top so Using Status We terminate at Suspended same as old api
                        ''''''''''''''''Make the Market Book Request'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                        Dim strBookRequest As String = "{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listMarketBook"", ""params"": {""marketIds"":[""" & txtMktID.Text & """],""priceProjection"":{""priceData"":[""EX_BEST_OFFERS"",""SP_AVAILABLE""],""exBestOffersOverrides"":{""bestPricesDepth"":1} }}, ""id"": 1}"
                        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                        Dim ListMarketBookResponse = CreateRequest(UseAppKey, GetSessToken, strBookRequest)
                        Try '
                            'Get the Response and convert the Text to Classes from MarketBook
                            Dim jsonBookObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of MarketBook)(ListMarketBookResponse)
                            'TEXT - Show the Json Text Response in the Text Editor or similar if required 
                            'ShowJsonText(ListMarketBookResponse)
                            'Json Class Results
                            '===========Get Prices===============
                            Dim strPrices As String = ""
                            Dim BackList As New List(Of Double)
                            Dim LayList As New List(Of Double)
                            BackList.Clear()
                            LayList.Clear()
                
                            'We could use the Runners Count here but if we use RowCount it is more Visible (Less 1 for Extra Bottom Row)
                            For i = 0 To objDataGrid.RowCount - 2 '1 is the Btm Info Row Or use .NumberOfRunners-1 (Not NumberOfActiveRunners)
                                'Get the Exchange Prices We are only Using Best Prices Depth == 1
                                With jsonBookObject.Result(0).Runners(i).ExchangePrices
                                    Dim dblBack() As Double = {}
                                    Dim dblLay() As Double = {}
                                    'Get the Prices in the array
                                    For t = 0 To .AvailableToBack.Count  'I only have the one here
                                        If .AvailableToBack IsNot Nothing AndAlso .AvailableToBack.Count > 0 Then
                                            dblBack = {.AvailableToBack(0).Price} '
                                        Else
                                            dblBack = {0.0} 'Use zero rather than nothing
                                        End If
                                        If .AvailableToLay IsNot Nothing AndAlso .AvailableToLay.Count > 0 Then
                                            dblLay = {.AvailableToLay(0).Price}
                                        Else
                                            dblLay = {0.0} 'Use zero rather than nothing
                                        End If '
                                    Next t
                                    strPrices = dblBack(0) & "  |  " & dblLay(0) & vbCrLf 'Use/Test in a TextBox etc
                                    BackList.Add(dblBack(0)) 'Add to our List
                                    LayList.Add(dblLay(0)) 'Add to our List
                                End With 'Json Book Exchange prices
                                With objDataGrid.Rows(i) 'All the Grid Rows Fill in the Cell Values/Properties/Formats as Required 
                                    '
                                    '=======Back and Lay Prices Col/Cells 3 and  4======
                                    '
                                    'Back Column 3 Cell 3
                                    .Cells(3).Value = BackList.Item(i)
                                    '
                                    'Lay Column 4 Cells 4
                                    .Cells(4).Value = LayList.Item(i)
                                End With
                            Next i
                        Catch ex As Exception
                
                        End Try
                    End Sub
                what is wrong?

                Comment

                • SimonN
                  Junior Member
                  • Dec 2014
                  • 71

                  #113
                  Listevents - textQuery not working?

                  First GetListEventsRequestString works but second -when I try to add in textQuery -does not! Please help..

                  Dim dateNow As Date: dateNow = Format(Now, "yyyy-mm-dd hh:mm:ss")
                  Dim dateThen As Date: dateThen = Format(DateAdd("d", 5, dateNow), "yyyy-mm-dd hh:mm:ss")
                  Dim searchString As String: searchString = "Man*"

                  GetListEventsRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""marketStartTime"": {""from"": ""2016-02-23T00:00:01Z"",""to"": ""2016-02-29T00:00:00Z""}}}"

                  GetListEventsRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""textQuery"":[""" & searchString & """],""marketStartTime"": {""from"": ""2016-02-23T00:00:01Z"",""to"": ""2016-02-29T00:00:00Z""}}}"

                  Comment

                  • jabe
                    Senior Member
                    • Dec 2014
                    • 705

                    #114
                    The parameter for the textQuery is a string and not an array, so just remove the brackets.


                    i.e;
                    GetListEventsRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""textQuery"":""" & searchString & """,""marketStartTime"": {""from"": ""2016-02-23T00:00:01Z"",""to"": ""2016-02-29T00:00:00Z""}}}"

                    Comment

                    • SimonN
                      Junior Member
                      • Dec 2014
                      • 71

                      #115
                      hahaha Thank you kind Sir Jabe!

                      I was just about to post I sorted it as you say like so:

                      GetListEventsRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""textQuery"":""" & searchString & """}}"


                      But what I would really love to know is why these things aren't documented anywhere? It's very - these rules - suck n see and not as far as I can see anywhere spelled out except maybe in passing in examples.

                      Thanks again! (Y)
                      Originally posted by jabe View Post
                      The parameter for the textQuery is a string and not an array, so just remove the brackets.


                      i.e;
                      GetListEventsRequestString = "{""filter"":{""eventTypeIds"":[""" & EventTypeId & """],""textQuery"":""" & searchString & """,""marketStartTime"": {""from"": ""2016-02-23T00:00:01Z"",""to"": ""2016-02-29T00:00:00Z""}}}"

                      Comment

                      • jabe
                        Senior Member
                        • Dec 2014
                        • 705

                        #116
                        My current (VB.NET) app has a number of tabs and one of them is a test page, so I can select which API call to make, put the filter/parameter string in a textbox, then click a button to try out the call. The result is displayed in a second textbox. It's been very useful.

                        I noticed in the documentation PDF that listEvents requires a MarketFilter, and clicking on MarketFilter shows the options. On the page showing the options (below), items that can take multiple parameters are shown with Type = Set<String> (for example) and so parameters are displayed within square brackets, which is how JSON holds arrays or collections. The type for textQuery was String, so I tried the call without brackets and it worked.

                        The documentation is useful but doesn't tell us everything and there are oddities in the returned data.

                        https://api.developer.betfair.com/se...s-MarketFilter

                        Comment

                        • SimonN
                          Junior Member
                          • Dec 2014
                          • 71

                          #117
                          Yes I did manage to pick up that Type = Set<String> is for ID's etc where there are defined values or arrays as you say and from the examples (but NOT anywhere else explicitly) I could see that the parameters are - as you say - "displayed within square brackets".

                          Your next phrase though, being unfamiliar with JSON, I did not know - "which is how JSON holds arrays or collections."

                          I'll do a little bit of digging to get more conversant with JSOn conventions.

                          Cheers Jabe

                          EDIT> Straight away I find it - easy when you're pointed in the right direction cheers

                          The JSON syntax is a subset of the JavaScript syntax.

                          JSON Syntax Rules
                          JSON syntax is derived from JavaScript object notation syntax:

                          Data is in name/value pairs
                          Data is separated by commas
                          Curly braces hold objects
                          Square brackets hold arrays

                          http://www.w3schools.com/json/json_syntax.asp

                          and...

                          JSON Values
                          JSON values can be:

                          A number (integer or floating point)
                          A string (in double quotes)
                          A Boolean (true or false)
                          An array (in square brackets)
                          An object (in curly braces)
                          null
                          Last edited by SimonN; 23-02-2016, 04:34 AM.

                          Comment

                          • jabe
                            Senior Member
                            • Dec 2014
                            • 705

                            #118
                            A bit of additional info which might help, in case you haven't reached it yet. With the JSON serialise and deserialise options, you can convert the string returned from Betfair straight into an object (or the other way). These objects are often of this format:

                            Public Class ClassListEventResult
                            Public jsonrpc As String
                            Public result() As ClassEventResult
                            End Class

                            So, if you've asked for several Events to be returned, result() is an array containing them, as long as they call worked. I haven't decided yet whether the sequence Events in the result() array can be relied on, however, which can make being certain rather messy.

                            Something that initially confused me but which was obvious when I realised it; if you have a keyed collection, your JSON may contain data looking like this:

                            "game": {"27698997":"27698997","27691816":"27691816","2769 8993":"27698993","27697806":"27697806","27697805": "27697805","27699717":"27699717","27699716":"27699 716","27699715":"27699715"}

                            So the data name is the name of the key value in this instance (these are football match ids). I'm a little surprised those brackets are not square ones, tbh.

                            Comment

                            • SimonN
                              Junior Member
                              • Dec 2014
                              • 71

                              #119
                              Hello Jabe!

                              Thanks for this! Excellent insights!


                              The way I am working is using the simple Betfair Excel VBA sample - adapting it to suit my needs. (https://api.developer.betfair.com/se...pageId=3834079 )

                              This parses the JSON string into a collection. Is this what you mean by deserialisation? I checked and there is nothing in that sample specifically referencing the word serialisation but I notice there are a number of deserialisation functions in the other more complex VBA example (by Robin Barrett) (https://github.com/betfair/API-NG-Excel-Toolkit) which appears to essentially do the same thing as the simple sample - using collections to store the JSON string. So I suspect that deserialisation is the parsing of the JSOn string into a collection. Is this what you mean by serialisation?

                              Regarding your second point, I haven't yet needed to query the collection / dictionary directly to highlight the game ID's you show having been able to get it all working following the BF sample convention looping through the entries count and navigating the items hierarchy. I will have a look at where I can tap into the sample code to query the collection / dictionary though - it might be handy going forward for more complicated needs.

                              One thing that I am keen to know is - what is the quickest most efficient way of getting prices for several markets for several events? As of now I am fetching several events and then drilling down to the market book prices submitting the various JSON requests in a loop for each of these events. I guess there is not shortcut really?

                              Cheers,

                              Simon
                              Originally posted by jabe View Post
                              A bit of additional info which might help, in case you haven't reached it yet. With the JSON serialise and deserialise options, you can convert the string returned from Betfair straight into an object (or the other way). These objects are often of this format:

                              Public Class ClassListEventResult
                              Public jsonrpc As String
                              Public result() As ClassEventResult
                              End Class

                              So, if you've asked for several Events to be returned, result() is an array containing them, as long as they call worked. I haven't decided yet whether the sequence Events in the result() array can be relied on, however, which can make being certain rather messy.

                              Something that initially confused me but which was obvious when I realised it; if you have a keyed collection, your JSON may contain data looking like this:

                              "game": {"27698997":"27698997","27691816":"27691816","2769 8993":"27698993","27697806":"27697806","27697805": "27697805","27699717":"27699717","27699716":"27699 716","27699715":"27699715"}

                              So the data name is the name of the key value in this instance (these are football match ids). I'm a little surprised those brackets are not square ones, tbh.

                              Comment

                              • jabe
                                Senior Member
                                • Dec 2014
                                • 705

                                #120
                                The de/serialisation relates to translating a string of JSON data to an object or vice-versa.

                                For example, when a listMarketBook call is made, it returns a JSON string:

                                Code:
                                Public odds As New ClassListMarketBookResult
                                Dim jss As New JavaScriptSerializer() 'JSON (de)serialiser 
                                
                                ' inrec is the JSON string returned from Betfair:
                                odds = jss.Deserialize(Of ClassListMarketBookResult)(inrec)
                                
                                ClassListMarketBookResult looks like this:
                                
                                Public Class ClassListMarketBookResult
                                    Public jsonrpc As String
                                    Public result() As ClassMarketBook
                                End Class
                                So when the JSON string is deserialised, I get an array of ClassMarketBooks. So, if you specify several markets in your API call, you get them all in the result() array.

                                I'm sure there are other equally valid ways to do this.

                                So, for the final part of your post, I start my program by getting a list of Events (these are particular football matches). For each, I get the MarketCatalogue data that I'm interested in. All of this is stored in a (one of many) football match object. After that, when I want to get odds, I use a list of MarketIds (a string) from the MarketCatalogue in my listMarketBook call, allowing me to get several markets at once. I don't know whether I can get multiple markets from different events in a single call.

                                Comment

                                Working...
                                X