VBNet Sample (Yes really)

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts

  • jabe
    replied
    Originally posted by SimonN View Post
    Can someone explain all about these certificates. I am really ignorant, lol.

    So you can call them on any machine for your certificated logon. You can change your account password without having to regenerate your certificate?

    How does it all work? What's the point, really?

    Apologies and thanks.

    Si
    I haven't done it, but it would be useful for automation. If your program fails, you can have it restart without your presence. Ideal for bots.

    Leave a comment:


  • jabe
    replied
    Originally posted by LordRom View Post
    Could you please share your classes for the deserealise object of MarketBook Jabe.

    I have the data in the string returned, but it gets lost when converting.

    Thanks for your time.
    They were your classes.

    I'll tell you what I put where in my program.

    I'm using the Visual Studio 2015 Community edition.

    1. I started a new project - it's a Windows Form Project (but doesn't do anything GUI at all).

    2. I did nothing at all to the form.

    3. Via Project, Manage NuGet Packages, I installed the NewtonSoft JSON converter package.

    4. In the Form1_Load, I assigned your JSON string to a string (see 5), set up a new JSONBookObject, as you did, deserialising your string, and added a few lines to check the values. I put your classes in the Form1 class. I added the Includes statements to the top of Form1.vb.

    5. I put your JSON string into NotePad, changed " to "" throughout, added " at each end of the string, and assigned it to inString.

    This is all that is in Form1.vb

    Code:
    Imports Newtonsoft.Json '~~> Enable the the use of Json Objects
    Imports Newtonsoft.Json.Converters
    Public Class Form1
    
        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
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim inString = "{""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}"
    
            Dim jsonBookObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of MarketBook)(inString)
            Dim c1 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack.Count
            Dim c2 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack(0).Size
            Dim c3 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack(0).Price
    
    
            Dim pauseHere = "wait!"
        End Sub
    End Class
    5. I added a breakpoint on the line where pauseHere is defined so I could check the values in c1, c2, and c3. Then I ran it.
    Last edited by jabe; 05-10-2016, 04:59 AM.

    Leave a comment:


  • SimonN
    replied
    Can someone explain all about these certificates. I am really ignorant, lol.

    So you can call them on any machine for your certificated logon. You can change your account password without having to regenerate your certificate?

    How does it all work? What's the point, really?

    Apologies and thanks.

    Si
    Last edited by SimonN; 04-10-2016, 09:48 PM.

    Leave a comment:


  • LordRom
    replied
    Could you please share your classes for the deserealise object of MarketBook Jabe.

    I have the data in the string returned, but it gets lost when converting.

    Thanks for your time.

    Leave a comment:


  • jabe
    replied
    I've put your code into a program and deserialised the JSON string.

    I added these three lines after the DeserializeObject statement:

    Code:
    Dim c1 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack.Count
    Dim c2 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack(0).Size
    Dim c3 = jsonBookObject.Result(0).Runners(0).ExchangePrices.AvailableToBack(0).Price
    They have values 3, 12, 3, which is probably what you want, and I only used your code.

    Leave a comment:


  • jabe
    replied
    Might be the code in your listMarketBook request then, if the rest is working okay.

    This is the line from mine that sets up the JSON request string

    Code:
    Dim intext = """marketIds"" : [" & marketId & "], ""priceProjection"" : {""priceData"": [""EX_BEST_OFFERS""],""virtualise"":""true""}"
    See if using these parameters helps.

    Leave a comment:


  • LordRom
    replied
    Code:
    With jsonBookObject.Result(0).Runners(i).ExchangePrices
    It's the exchangeprices that doesn't exist in the object.

    Leave a comment:


  • jabe
    replied
    I'll try putting your code into a program later so I can see if I can work out why it's not doing as you want.

    Leave a comment:


  • jabe
    replied
    Try

    Dim jsonBookObject as MarketBook = Newtonsoft.Json.JsonConvert.DeserializeObject(Of MarketBook)(ListMarketBookResponse)

    Might not make a difference - I don't know to what extent VB.Net knows to make the Dimmed item the same as the item value being assigned to it.
    Last edited by jabe; 03-10-2016, 02:06 PM.

    Leave a comment:


  • LordRom
    replied
    Thanks Jabe. I have the following classes (copied from an earlier post). I think something is maybe missing from in there beacuse when I try the following I don't get the prices back from the string.

    Dim jsonBookObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of MarketBook)(ListMarketBookResponse)



    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

    Leave a comment:


  • jabe
    replied
    I've been using a different serialiser, but this should show you the idea.

    This is my ClassMarketBook class definition
    Code:
    Public Class ClassMarketBook ' The dynamic data in a market
        Public marketId As String           ' The unique identifier for the market
        Public isMarketDataDelayed As Boolean ' True if the data returned by listMarketBook will be delayed. The data may be delayed because you are not logged in with a funded account or you are using an Application Key that does not allow up to date data.
        Public status As MarketStatus  ' The status of the market, for example ACTIVE, SUSPENDED, SETTLED, etc.
        Public betDelay As Integer          ' The number of seconds an order is held until it is submitted into the market. Orders are usually delayed when the market is in-play
        Public bspReconciled As Boolean     ' True if the market starting price has been reconciled
        Public complete As Boolean          ' If false, runners may be added to the market
        Public inplay As Boolean            ' True if the market is currently in play
        Public numberOfWinners As Integer   ' The number of selections that could be settled as winners
        Public numberOfRunners As Integer   ' The number of runners in the market
        Public numberOfActiveRunners As Integer ' The number of runners that are currently active. An active runner is a selection available for betting
        Public lastMatchTime As DateTime ' The most recent time an order was executed
        Public totalMatched As Double ' The total amount matched
        Public totalAvailable As Double ' The total amount of orders that remain unmatched
        Public crossMatching As Boolean ' True if cross matching is enabled for this market.
        Public runnersVoidable As Boolean   ' True if runners in the market can be voided
        Public version As Long              ' The version of the market. The version increments whenever the market status changes, for example, turning in-play, or suspended when a goal score.
        Public runners() As ClassRunner     ' Information about the runners (selections) in the market.
    End Class
    Note that it includes ClassRunner, for which a class definition is also needed, and MarketStatus, which is an enum and needs defining somewhere. ClassRunner also has elements defined in further classes and enums, all of which must be defined.

    I have a further class called ClassListMarketBookResult, into which the returned string is deserialised:
    Code:
    Public Class ClassListMarketBookResult
        Public jsonrpc As String
        Public result() As ClassMarketBook
    End Class
    I'm using JavaScriptSerializer, which requires this statement
    HTML Code:
    Imports System.Web.Script.Serialization
    before the start of any class (Form1, in my case) that uses it.

    Whenever I use it, I need a definition:

    Code:
    Dim jss As New JavaScriptSerializer() 'JSON serialiser
    And to deserialise, I do this

    Code:
    odds = jss.Deserialize(Of ClassListMarketBookResult)(inrec)
    where odds is defined like this:

    Code:
    Public odds As New ClassListMarketBookResult
    You may well need to specifically define your jsonBookObject as a New MarketBook or something that includes the MarketBook class. I begin all my class names with the word Class so I know what they are.

    This might be enough to help you past your problem, but let us know if it doesn't, and what you did manage to get done.

    Leave a comment:


  • LordRom
    replied
    Hi All,

    Have taken over an old app and am trying to get it functionaing as required. Looking at some of the prior posts I'm learning slowly.

    So I have copied the following, but although it is returning the prices and available stakes into the string, it's not letting me DeserializeObject correctly, so they are not showing in my object.

    I have copied the Market Book class, but guess I must be missing something fairly basic.

    All help is much appreciated.


    Code:
    Dim strBookRequest As String = "{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listMarketBook"", ""params"": {""marketIds"":[""" & tabMarkets.SelectedTab.Name & """],""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)
    Last edited by LordRom; 03-10-2016, 11:58 AM.

    Leave a comment:


  • SimonN
    replied
    Oh right - thanks Jabe - didn't realise server timers not accurate but yes in any case that makes good sense to call earlier than 4 hours.. cheers - how's your projects going, bud?

    Leave a comment:


  • jabe
    replied
    Apparently so; however, given the accuracy of timers on PCs, I'd do it a bit sooner. Maybe every 3 hours or 200 minutes or something. Try it and see.

    Leave a comment:


  • SimonN
    replied
    So I have to call this every 4 hours then to maintain login state? https://identitysso.betfair.com/api/keepAlive

    Leave a comment:

Working...
X