Racego PS
PS you have to of course deserialize the response before you can use it
VBNet Sample (Yes really)
Collapse
This is a sticky topic.
X
X
-
reply to racego re lastpricetraded
Hi Racego
Dim strRequest As String = ""
strRequest = "{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listMarketBook"", ""params"": {""marketIds"":[""" & marketId & """],""priceProjection"":{""priceData"":[""EX_BEST_OFFERS""],""virtualise"":""true""}}, ""id"": 1}"
I use a "MktBook" class, which is a VB consolidation of the "MarketBook" and "Runner" classes in the development team's C# API-NG example app, as follows (it doesn't yet include all possible properties - only those I need to date):
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Public Class MktBook
<JsonProperty(PropertyName:="result")> _
Public Property Result() As List(Of PriceInfo)
End Class
Public Class PriceInfo
<JsonProperty(PropertyName:="marketId")> _
Public Property MarkId() As String
<JsonProperty(PropertyName:="numberOfWinners")> _
Public Property NumberOfWinners() As Integer
<JsonProperty(PropertyName:="numberOfActiveRunners ")> _
Public Property NumberOfActiveRunners() As Integer
<JsonProperty(PropertyName:="runners")> _
Public Property Horses() As List(Of RaceHorse)
End Class
Public Class RaceHorse
<JsonProperty(PropertyName:="selectionId")> _
Public Property sId() As Long
<JsonProperty(PropertyName:="status")> _
Public Property Status() As hseStatus
<JsonProperty(PropertyName:="adjustmentFactor")> _
Public Property Adjust() As Double
<JsonProperty(PropertyName:="removalDate")> _
Public Property RemTime() As Date
<JsonProperty(PropertyName:="ex")> _
Public Property Exes() As ExchangeP
<JsonProperty(PropertyName:="totalMatched")> _
Public Property TotMatched() As Double
<JsonProperty(PropertyName:="lastPriceTraded")> _
Public Property LastPriceTraded() As Double?
End Class
<JsonConverter(GetType(StringEnumConverter))> _
Public Enum hseStatus
ACTIVE
WINNER
LOSER
REMOVED_VACANT
REMOVED
End Enum
Public Class ExchangeP
<JsonProperty(PropertyName:="availableToBack")> _
Public Property Backps() As List(Of PSize)
<JsonProperty(PropertyName:="availableToLay")> _
Public Property Layps() As List(Of PSize)
<JsonProperty(PropertyName:="tradedVolume")> _
Public Property TradVol() As List(Of PSize)
End Class
Public Class PSize
<JsonProperty(PropertyName:="price")> _
Public Property p() As Double
<JsonProperty(PropertyName:="size")> _
Public Property s() As Double
End Class
'WITH THE RESPONSE:
For y As Integer = 0 To objJson.Result.Count - 1
With objJson.Result(y)
Dim listHse As List(Of RaceHorse)
listHse = .Horses
For Each Hse As RaceHorse In listHse
With Hse
Dim stat As hseStatus = .Status
Dim selRef As Long = .sId
Dim adfactor As Double = .Adjust
'etc, etc. What you want is:
Dim lastTraded As Double? = .LastPriceTraded
......
End With
......
Next
......
End With
......
Next
Hope this helps
Mike
Leave a comment:
-
Right, I've managed to solve every problem I have had for a while now but now I am stuck again.
I want to update a particular grid, but when I use objDataGrid it always just uses the last grid that was added to the tabs even though the one displayed is a different one.
Not sure why this is, but how do I avoid this and get it to update the cells in the one I am trying to access?
Thanks
Leave a comment:
-
Hi NatOriginally posted by NatHunter View Post...
Being a Lazy Son of a Bitch I have just started to do my New App this Week and it just so happens that I had not got around to Accounts just yet
However now you ask I have just killed 2 Birds with one Stone and set about it
Looking at the Account Statement I would first ask myself after seeing it
What the hell would I want that for? Its massive and contains a lot of GobblyGook
Its a Hell of a lot easier to just get that Info from the Site!
Anyways I have included the Request string you want but Ive not done any classes for it - You can suss that for yourself because hopefully you may be a bit wiser if you play with the below - This Json stuff with VB is OK after a few Goes so have a Try similar to below with the Statement if you so desire lol I have just Done Classes for what I will be using - eg The Funds - The Details and the AppKeys you can add the rest yourself – Just Copy and Paste all Below in your App (You can move the Classes to a separate Module afterwards if you want) The Account Funds and Details are dead easy once you dig the AppKeys!
I have done the Examples in a Long about Way without loops and things so they might be easier to follow as separate items
Hope this Helps and let me know if you get stuck
Dave
‘With what you have Given the Request would be something like this
Code:'This is for GetDeveloperAppKeys Try Others yourself Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, btnTest.Click 'Statement (This is Large and Slow to download) Dim strGetAccountStatement As String = "{""jsonrpc"": ""2.0"", ""method"":""AccountAPING/v1.0/getAccountStatement"", ""id"": 1}" 'Funds (Available Funds, Points etc) Dim strGetAccountFunds As String = "{""jsonrpc"": ""2.0"", ""method"":""AccountAPING/v1.0/getAccountFunds"", ""id"": 1}" 'Your Details (Your Name, DiscountRate Points balance etc) Dim strGetAccountDetails As String = "{""jsonrpc"": ""2.0"", ""method"":""AccountAPING/v1.0/getAccountDetails"", ""id"": 1}" 'Get your AppKeys (No need for CreateDeveloperAppKeys as you have an Account Already) Dim strGetDeveloperAppKeys As String = "{""jsonrpc"": ""2.0"", ""method"":""AccountAPING/v1.0/getDeveloperAppKeys"", ""id"":1}" 'Send Request with your Choice of Above ' Dim GetMyStuff As Object = CreateRequest(AppKey, sSEssToken, strGetAccountStatement, "Account") Dim GetMyStuff = CreateRequest(AppKey, sSessToken, strGetDeveloperAppKeys, "Account") 'etc 'Before Creating the Classes get the Full Response String and then Break it Down into Objects ' Save in a File for future reference in a Seperate TextEditor ' ' I have enclosed a TextEditor I made for the purpose and have enclosed as an attachement 'Just Unzip and Copy and Paste the 3 files directly into your App in Studio and access it like this ' 'Form_JsonResponseText.Show() 'Form_JsonResponseText.rTxtResponse.Text = GetMyStuff ' ' '============ Just use below for a quick test========== 'Display the JsonResponse Dim TextEditor As New Form 'Create a New Form to Hold a Docked textBox TextEditor.Height = 600 TextEditor.Width = 800 TextEditor.StartPosition = FormStartPosition.CenterScreen Dim txtDetails As New TextBox 'Create the TextBox txtDetails.Dock = DockStyle.Fill txtDetails.Multiline = True txtDetails.ScrollBars = ScrollBars.Both TextEditor.Controls.Add(txtDetails) 'Add the TextBox to the Form txtDetails.Text = GetMyStuff 'Show the Response Text TextEditor.Show() 'Show the Form with Textbox Text '========================================================== ' Copy Response Text and Now do all your Class Objects Properties etc before DeserialIzing ' ' ** See the AppKey Class first from the Response in Accounts then Come back Here ** ' 'Full Json response '{"jsonrpc":"2.0","result":[{"appName":"TheNameGiven","appId":9999,"appVersions":[ '{"owner":"mickMouse","versionId":1234,"version":"1.0-DELAY","applicationKey":"BlaBla1","delayData":true,"subscriptionRequired":true,"ownerManaged":false,"active":true}, '{"owner":"mickMouse","versionId":1235,"version":"1.0","applicationKey":"BlaBla2","delayData":false,"subscriptionRequired":true,"ownerManaged":false,"active":true}]}],"id":1} 'Get the Class Objects from the above Json response Text (See AppKeys Class Below) Dim objAppKeys = Newtonsoft.Json.JsonConvert.DeserializeObject(Of AppKeys)(GetMyStuff) 'What do we want from the Main Level? '{"jsonrpc":"2.0","result":[{"appName":"TheNameGiven","appId":9999, Dim strAppName As String = "" ' TheNameGiven Dim intAppID As Integer = 0 ' 9999 'Then from the Array[appVersions] {First Object properties} '{"owner":"mickMouse","versionId":1234,"version":"1.0-DELAY","applicationKey":"BlaBla1","delayData":true,"subscriptionRequired":true,"ownerManaged":false,"active":true}, Dim strOwner As String = "" ' mickMouse Dim intVersionID As Integer = 0 '1234 Dim strVersion As String = "" ' 1.0-DELAY Dim strAppDelayKey As String = "" 'BlaBla1 Dim bDelayData As Boolean = True ' true 'Then from the Array[appVersions] {Second Object properties} ' {"owner":"mickMouse","versionId":1235,"version":"1.0","applicationKey":"BlaBla2","delayData":false,"subscriptionRequired":true,"ownerManaged":false,"active":true}]}],"id":1} Dim strOwner2 As String = "" ' mickMouse same as first Dim intVersionID2 As Integer = 0 '1235 Dim strVersion2 As String = "" ' 1.0 = Live Key Dim strAppLiveKey As String = "" 'BlaBla2 Dim bDelayData2 As Boolean = False ' false With objAppKeys.Result(0) 'Do all Top Level as required strAppName = .AppName intAppID = .AppID.ToString ''Now the Array "appVersions"[] This Consists of 2 Json Objects{} but each with same properties With .AppVersions(0) 'Do all from here as required strOwner = .Owner intVersionID = .VersionID.ToString strVersion = .Version strAppDelayKey = .ApplicationKey bDelayData = .DelayData.ToString End With 'appVersions(0) With .AppVersions(1) 'Do all from here as required strOwner2 = .Owner intVersionID2 = .VersionID.ToString strVersion2 = .Version strAppLiveKey = .ApplicationKey bDelayData2 = .DelayData.ToString End With 'appVersions(1) End With 'Result(0) ' Display all the Stuff above Dim strAllMyStuff As String = _ "App Name " & strAppName & vbCrLf _ & "App ID # " & intAppID & vbCrLf _ & "________________________________ " & vbNewLine _ & "Owner #1 " & strOwner & vbCrLf _ & "Version ID " & intVersionID & vbCrLf _ & "Key Version = " & strVersion & vbCrLf _ & "Delay Key is: " & strAppDelayKey & vbCrLf _ & "Is it Delayed? " & bDelayData & vbCrLf _ & "________________________________ " & vbNewLine _ & "Owner #2 " & strOwner2 & vbCrLf _ & "Version ID 2 " & intVersionID2 & vbCrLf _ & "Key Version 2 = " & strVersion2 & vbCrLf _ & "Live Key is: " & strAppLiveKey & vbCrLf _ & "Is it Delayed? " & bDelayData2 & vbCrLf _ & "________________________________ " 'Show somewhere MsgBox(strAllMyStuff) End Sub 'Button 1 'Accounts Class Begin ' ' Dont forget these Imports if moving below to a Module '#Region "IMPORTS" 'Imports Newtonsoft.Json '~~> Enable the the use of Json Objects 'Imports Newtonsoft.Json.Converters 'Imports System.IO 'Text Streams 'Imports System.Net 'Web 'Imports System.Text '#End Region 'Imports General throughout program ' ' Account Funds, Account Details and AppKeys Json Response Classes ' 'JSON Syntax Rules 'Data is in name/value pairs 'Data is separated by commas 'Curly braces hold objects 'Square brackets hold arrays 'GetDeveloperAppKeys ' Public Class AppKeys 'Top Level 'Response String Returns for GetDeveloperAppKeys Get the String then Disect it into Properties/Objects 'Note: This is an Array ""result"":[] Then Inside this is another Array "appVersions": [] '{"jsonrpc":"2.0","result":[{"appName":"TheNameGiven","appId":9999,"appVersions":[{"owner":"mickMouse","versionId":1234,"version":"1.0-DELAY","applicationKey":"BlaBla1","delayData":true,"subscriptionRequired":true,"ownerManaged":false,"active":true},{"owner":"mickMouse","versionId":1235,"version":"1.0","applicationKey":"BlaBla2","delayData":false,"subscriptionRequired":true,"ownerManaged":false,"active":true}]}],"id":1} 'So we now want a List of all the ones{"appName":"","appId":0 before the othe Array "appVersions"[ <JsonProperty(PropertyName:="result")> _ Public Property Result() As List(Of FrontDetails) 'Make the FrontDetails Class Below End Class '>> Account Details Top Level >> DeserializeObject(Of AppKeys) ' ' Main Level Returns from Result (First Array []) These are the Objects {} ' Public Class FrontDetails '< You dont use/see this Name anywhere else except here ' 'The First is a String "appName" and the 2nd an Integer value "appID" and the 3rd is another Array "appVersions"[] 'AppName <JsonProperty(PropertyName:="appName")> Public Property AppName As String 'Call what you want now we have Json property Name 'AppID <JsonProperty(PropertyName:="appId")> Public Property AppID As Integer ' ' 'Now we need another List here because "appVersions":[] is an Array inside this First One <JsonProperty(PropertyName:="appVersions")> _ Public Property AppVersions() As List(Of AppVersions) 'Now the Start of the Next Array End Class 'FrontDetails ' ' Returns from the 2nd Array [} - There are 2 Objects {} that contain the same properties ' Public Class AppVersions '{"jsonrpc":"2.0","result":[{"appName":"TheNameGiven","appId":9999,"appVersions":[ '{"owner":"mickMouse","versionId":1234,"version":"1.0-DELAY","applicationKey":"BlaBla1","delayData":true,"subscriptionRequired":true,"ownerManaged":false,"active":true}, '{"owner":"mickMouse","versionId":1235,"version":"1.0","applicationKey":"BlaBla2","delayData":false,"subscriptionRequired":true,"ownerManaged":false,"active":true}]}],"id":1} 'owner string <JsonProperty(PropertyName:="owner")> Public Property Owner As String 'versionID integer <JsonProperty(PropertyName:="versionID")> Public Property VersionID As Integer 'version string <JsonProperty(PropertyName:="version")> Public Property Version As String 'applicationKey <JsonProperty(PropertyName:="applicationKey")> Public Property ApplicationKey As String 'delayData Boolean <JsonProperty(PropertyName:="delayData")> Public Property DelayData As Boolean 'subscriptionRequired Boolean <JsonProperty(PropertyName:="subscriptionRequired")> Public Property SubscriptionRequired As Boolean 'ownerManaged Boolean <JsonProperty(PropertyName:="ownerManaged")> Public Property OwnerManaged As Boolean 'active Boolean <JsonProperty(PropertyName:="active")> Public Property Active As Boolean End Class ' App Versions [] {Object Properties) ' 'GetAccountFunds ' Public Class AccountFunds 'Top Level 'Response String Returns GetAccountFunds ' Funds {"jsonrpc":"2.0","result":{"availableToBetBalance":1107.27,"exposure":0.0,"retainedCommission":0.0,"exposureLimit":-5000.0},"id":1} ' 'Notice here that it is not an Array list from "result" like catalogue "result":{ NOT "result":[{ <JsonProperty(PropertyName:="result")> _ Public Property Result() As FundReturns '~~> Not List of returns End Class '>> AccountFunds Top Level >> DeserializeObject(Of AccountFunds)(str) ' 'Main Level 2 Returns to Cover all from Result ' Public Class FundReturns 'Points Balance <JsonProperty(PropertyName:="availableToBetBalance")> _ Public Property AvailableBalance() As Double 'Returns Amount after deducting outstanding bets 'Current Bets in Play dosh <JsonProperty(PropertyName:="exposure")> _ Public Property Exposure() As Double 'Returns the amount of current unsettled bets ' 'Function to return the Full Balance this is not available in Bfair or Json ' Public Function FullBalance() As Double Dim dblSetExposure As Double = (-Exposure) 'if we minus the minus exposure it will give a plus when calculated Dim dblFullBalance = AvailableBalance + dblSetExposure 'Will now show Full Balance before any Outstanding bets Return dblFullBalance End Function 'Full Balance Function End Class 'Returns Main Level ' 'GetAccountDetails Also Not an Array -- Just Json Objects ' Public Class AccountDetails 'Top Level 'Response String Returns GetAccountDetails 'Details {"jsonrpc":"2.0","result":{"currencyCode":"GBP","firstName":"Mickey","lastName":"Mouse","localeCode":"en","region":"GBR","timezone":"Europe/London","discountRate":2.0,"pointsBalance":1671},"id":1} <JsonProperty(PropertyName:="result")> _ Public Property Result() As DetailsReturns End Class '>> Account Details Top Level >> DeserializeObject(Of AccountDetails) ' 'Main Level 2 Returns to Cover all from Result ' Public Class DetailsReturns ' ' First Name ' <JsonProperty(PropertyName:="firstName")> _ Public Property FirstName() As String ' ' 'Last Name ' <JsonProperty(PropertyName:="lastName")> _ Public Property LastName() As String ' ' 'Discount Rate ' <JsonProperty(PropertyName:="discountRate")> _ Public Property DiscountRate() As Double ' This returns 2.0 as a % this would be 2 * 1/100 or 2/100 ' 'Points Balance ' <JsonProperty(PropertyName:="pointsBalance")> _ Public Property PointsBalance() As Integer ' End Class 'Returns Main Level ' 'Accounts ENDAttached FilesLast edited by davecon; 30-10-2014, 04:49 PM.
Leave a comment:
-
last price matched
does anyone know how to check the last price matched for a given marketid and selection?
thanks
Leave a comment:
-
thanks
thanks, i've sorted it out
For i = 0 To 5 - 1
With objJson.Result(i)
txtLog.AppendText(.MarketId & " | " & .MarketStartTime & " | " & .RaceType & " |")
Dim ix As Integer = .MarketId
For ix = 0 To 1 - 1
Dim strRunnerName As String = objJson.Result(i).Runners(ix).RunnerName
txtLog.AppendText(strRunnerName & " | ")
Next
txtLog.AppendText(vbCrLf)
End With
Next
Leave a comment:
-
You get a list of runners names for each race from listMarketCatalogue. Deserialize the response then do something like this:
For i As Integer = 0 To objJson.Result.Count - 1
With objJson.Result(i)
For j = 0 To .Runners.Count - 1
Dim strRunnerName As String = .Runners(j).RunnerName
.........
Next
End With
........
Next
The result, runners, and runnername properties in the above are derived from a Marketcatalogue class. You can find a spec for this class early in this thread, kindly provided by davecon. If you're using this already there must be something you aren't doing right in your code if you can't get runner names.
Then do whatever you want with RunnerName - save to array, post to listBox etc
Leave a comment:
-
deserialize
hello, i took davecon code and was able to display the following results :
txtLog.AppendText(.MarketId & " | " & .MarketStartTime & " | " & .RaceType & " |" & vbCrLf)
but i cant seem to display the runners, im not trying to use a treeview, just a simple line with marketid, starttime and the runners, can you please enlight me?
thank you in advance
Leave a comment:
-
OK - I have successfully passed the AccountStatement request string. It needs to go to the "accounts" endpoint (code below).
I just need to have a steer to how to DeSerialize this...
Function CreateRequest(AppKey As String, sSessToken As String, postData As String, Optional sEndPoint As String = "betting")
If UCase(sEndPoint) = "BETTING" Then
Url = "https://api.betfair.com/exchange/betting/json-rpc/v1/"
ElseIf UCase(sEndPoint) = "ACCOUNT" Then
Url = "https://api.betfair.com/exchange/account/json-rpc/v1"
End If
request = WebRequest.Create(New Uri(Url))
request.Method = "POST"
...
Leave a comment:
-
GetAccountStatement Class
Hi All.
Firstly I would like to thank everyone for contributing to this forum - the rewrite of my Betfair bot would not have got off the ground without the input posted here.
I only discovered 10 days ago that the old API was being canned in November, since when I have more or less rewritten my application. Special thanks are in order for DaveCon, I think. I took his basic app and the original VB.zip, plus the VBA examples plus posts and came up with my VB2012.NET solution.
I did take the JSON client code and modules from VB.zip originally, but have replaced this code - which I could not possibly maintain in case of errors - with code which has its roots in DaveCon's BasicApp.
I am using class 'headers', an example of which was provided in BasicApp, to form a collection class of the 'TO' classes provided in VB.zip, which, pending testing, seems to work well.
I can listMarketCatelogue and listMarketBook (including orders/bets) in this way using JSON DeserializeObject.
The last remaining area that I need to add is that of AccountStatement. It's not vital, but very useful.
I am after an account statement request string and a class to point it at for Deserialization.
Can anyone provide these, please, or point me in the right direction?
Thanks for any help on this.
Leave a comment:
-
ListCurrentOrders
if I place un-match bet having persistence type = lapse at the time market goes inplay listcurrentorders doesn't return any bet in the markets. so how can we set bet is lapsed in our bot. before inplay market the bet was there having unmatch size. but after inplay its not cuming from anywhere I am send to from time range to = now and from now-30 days plz help me out
Leave a comment:
-
Self Signed Certificate Required
Hi To All , I want to ask that I have read somewhere on sites that the self signed certificate we are using right now for non interactive login using open-ssl will not work after 1st nov we have to supply self signed certificate after purchasing from VeriSign or some other company is it right ? please enlighten me thanks in advance
Leave a comment:
-
TreeView Using Data Navigation
I had tried to read json.txt from datanavigation path but takes so much time to download and then making tree view from that. if Mr Ed u have or any one else have any working example for treeview using json.txt or other way I will really appreciate to him if suppliedOriginally posted by Mr Ed View PostI am really bad at this stuff, but I had an identical problem with listCurrentOrders. No mandatory fields but getting the same error.
Then I changed it to
"{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listCurrentOrders"",""params"": {""orderProjection"": ""EXECUTABLE""},""id"": 1}"
and it worked
Leave a comment:
-
I am really bad at this stuff, but I had an identical problem with listCurrentOrders. No mandatory fields but getting the same error.Originally posted by API NG View Postyes the first page have treeview but hardcoded for only horseracing without starting listeventtypes what I want is you guide me that first I make call listeventtypes then forexample listcompetions then listevents and in the end listmarketcatalogue or something like that
cancelorder request doesn't need any mandatory field but in response returns error "cancelorders error code -32602 message DSC-0018 its a error when we miss any mandatory field but I am sending betid and sizereduction 0.0 and tried null tooo still got this error. help me out....
Then I changed it to
"{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listCurrentOrders"",""params"": {""orderProjection"": ""EXECUTABLE""},""id"": 1}"
and it worked
Leave a comment:
-
Treeview plus cancelorder problem
yes the first page have treeview but hardcoded for only horseracing without starting listeventtypes what I want is you guide me that first I make call listeventtypes then forexample listcompetions then listevents and in the end listmarketcatalogue or something like that
cancelorder request doesn't need any mandatory field but in response returns error "cancelorders error code -32602 message DSC-0018 its a error when we miss any mandatory field but I am sending betid and sizereduction 0.0 and tried null tooo still got this error. help me out....
Leave a comment:


Leave a comment: