Using VB2008 to acccess the Betfair API: A tutorial
Collapse
This topic is closed.
X
X
-
How to Get the Total Match Points
Hi All,
how i can to get the "Total match points" Value for basketball,Tennis,Ice hokey, ...
I mean for example Total Match Points - Under 142.5pts, Over 142.5pts
I Use the "BetFairUK_getMarketPricesCompressedCompleted" method but i can't find any field to hold this information.
Thanks
Leave a comment:
-
The problem is solved. The reason was a too frequent use of the procedure " PRINT".
Leave a comment:
-
Hi,Bigsprout!
Thank you for quick answer.
I have other code to write to a file:
Probably, I will give a bigger piece of code. Can anyone see a non-optimal code.I am no programmer, wrote as he could.Code:logfile = "C:\scachki\new\" & MarketId & ".txt" My.Computer.FileSystem.WriteAllText(logfile, allttr & vbCrLf, True)
Code:Private Sub BFindMarket_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BFindMarket.Click With FindTimer If .Enabled Then .Stop() BFindMarket.ForeColor = Color.Black Else .Interval = 60000 .Start() BFindMarket.ForeColor = Color.Green End If End With End Sub Private Sub FindTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindTimer.Tick Print("*** Find(timer) ***") FindMatch(BetFairUK.getMarketPrices(MpricesReq)) End Sub Sub FindMatch(ByVal MpriceResp As BFUK.GetMarketPricesResp) Dim result As String Dim oMarketsReq As New BFUK.GetAllMarketsReq Dim oMarketsResp As BFUK.GetAllMarketsResp Dim ttl As Double Dim strtarget, nott As Integer With oMarketsReq .header = oHeaderUK() ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7 ReDim .countries(1) : .countries(0) = "GBR" : .countries(1) = "IRL" .fromDate = Today .toDate = Today.AddDays(1) End With Print("proces=" & proces) If (proces = 0) Then Print("*** WE SEEK A NEW MATCH ***") oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq) With BetFairUK.getAllMarkets(oMarketsReq) CheckHeader(.header) Print("ErrorCode = " & .errorCode.ToString) If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then Dim AllMarkets As New UnpackAllMarkets(.marketData) Dim Names As String(), TodaysCard As New List(Of MarketDataType) With AllMarkets For i = 0 To .marketData.Length - 1 Names = .marketData(i).menuPath.Split("\") If Names.Length = 4 AndAlso Not Names(3).StartsWith("Daily") Then If .marketData(i).noOfWinners = 1 Then TodaysCard.Add(.marketData(i)) End If End If Next End With TodaysCard.Sort(New CompareMarketTimes) For Each Race In TodaysCard With Race ttl = .totalAmountMatched result = .marketId Print("ttl=" & ttl & " proces=" & proces & " result=" & result) Dim reader = My.Computer.FileSystem.ReadAllText("C:\scachki\new\UsedMarket.txt") strtarget = reader.IndexOf(result) Print("strtarget=" & strtarget & " proces=" & proces) If (strtarget = -1) Then My.Computer.FileSystem.WriteAllText("C:\scachki\new\UsedMarket.txt", result & vbCrLf, True) If ttl > 2000 Then MarketId = .marketId proces = 1 find_match = 1 strk = .marketName strt = .eventDate.ToLocalTime.AddHours(1).TimeOfDay.ToString With FindTimer If .Enabled Then .Stop() BFindMarket.ForeColor = Color.Black End If End With With PriceTimer If .Enabled Then nott = 0 Else .Interval = 2000 .Start() BPrices.ForeColor = Color.Green End If End With End If End If End With Next End If End With End If End Sub Private Sub BPrices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BPrices.Click With PriceTimer If .Enabled Then .Stop() BPrices.ForeColor = Color.Black Else .Interval = 2000 .Start() BPrices.ForeColor = Color.Green End If End With End Sub Private Sub PriceTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PriceTimer.Tick Print("*** Prices(timer) ***") Dim oMPCreq As New BFUK.GetMarketPricesCompressedReq With oMPCreq .header = oHeaderUK() .marketId = MarketId End With StateCount += 1 BetFairUK.getMarketPricesCompressedAsync(oMPCreq, StateCount) End Sub Private Sub BetFairUK_getMarketPricesCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketPricesCompressedCompletedEventArgs) Handles BetFairUK.getMarketPricesCompressedCompleted Dim Lay, Back, allttr, yy, logfile, nott As String Dim oMarketsReq As New BFUK.GetAllMarketsReq Dim back1, lay1 As Double Dim dly As Integer Dim yy1, yy2 As DateTime allttr = "" '............................................................................................................... If (proces = 0) Then If (find_match = 1) Then Print("*** WE SEEK A NEW MATCH ***") With PriceTimer If .Enabled Then .Stop() BPrices.ForeColor = Color.Black End If End With With FindTimer If .Enabled Then nott = 0 Else .Interval = 60000 .Start() BFindMarket.ForeColor = Color.Green End If End With Else Print("*** BOT STOPPED ***") With PriceTimer If .Enabled Then .Stop() BPrices.ForeColor = Color.Black End If End With End If Else Try If Not e.Cancelled Then With e.Result CheckHeader(.header) yy = .header.timestamp.ToLocalTime.AddHours(1).ToString Print("ErrorCode = " & .errorCode.ToString) If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then Dim oMarketPrices As New UnpackMarketPricesCompressed(.marketPrices) With oMarketPrices Print("MarketID = " & .marketId & " in play=" & .delay) dly = .delay '----------------- Prepare -------------------------------------------------- allttr = allttr & yy & " " For i = 0 To .runnerPrices.Length - 1 With .runnerPrices(i) Back = "" For j = 0 To .bestPricesToBack.Length - 1 With .bestPricesToBack(j) Back = Back & " " & .price & "/" & Int(.amountAvailable) End With Next If .bestPricesToBack.Length > 0 Then back1 = .bestPricesToBack(0).price Else Print("CURVE DATA") back1 = 0.999 proces = 0 Print("*** MATCH CLOSED ***") End If allttr = allttr & i + 1 & "= " & back1 Lay = "" For j = 0 To .bestPricesToLay.Length - 1 With .bestPricesToLay(j) Lay = Lay & " " & .price & "/" & Int(.amountAvailable) End With Next If .bestPricesToLay.Length > 0 Then lay1 = .bestPricesToLay(0).price Else lay1 = 999 End If allttr = allttr & "-" & lay1 & " " Print(i + 1 & " Back = " & Back & " Lay = " & Lay) End With Next If My.Computer.FileSystem.FileExists(logfile) Then nott = "" Else pred_yy = "23.09.2011 5:02:57" logfile = "C:\scachki\new\" & MarketId & ".txt" My.Computer.FileSystem.WriteAllText(logfile, strt & " " & strk & vbCrLf, True) Print2(strt & " " & strk) End If yy1 = DateTime.Parse(pred_yy) yy2 = DateTime.Parse(yy) '-------------------- main part ----------------------------------------------- If yy2 > yy1 Then allttr = allttr & " " & dly logfile = "C:\scachki\new\" & MarketId & ".txt" My.Computer.FileSystem.WriteAllText(logfile, allttr & vbCrLf, True) pred_yy = yy End If '------------------------------------------------------------------------------------------------- End With End If End With End If Catch ex As ApplicationException Print(e.Error.Message) End Try End If End Sub
Leave a comment:
-
gavvy,
as lines are added to a text file, it then takes a little longer to load the next time - so depending on the size, the files could be causing your problem.
This is easy to check by temporarily disabling the code that is calling the files then running your program again and seeing if the problem disappears
If the size of the files is the problem then you may have to look at limiting the size, alternatively you can put up your code for suggestions.Code:[B][U]'Code for appending lines to file:[/U][/B] Dim sw As StreamWriter sw = File.AppendText("Path to folder\gavvy.Txt") sw.WriteLine("add a line to the end of the file") sw.Close() [B][U]'temporarily disable code so file is not accessed:[/U][/B] 'Dim sw As StreamWriter 'sw = File.AppendText("Path to folder\gavvy.Txt") 'sw.WriteLine("add a line to the end of the file") 'sw.Close()
I am not sure of the advantages of having separate timers when one can do both tasks either.
cheers
Leave a comment:
-
Incidentally, the problem with the API and has no problems with CPU.May be thing is that I do write in a text file every 2 seconds.
Leave a comment:
-
100% cpu
Hello to all members of this community.
I read almost all the posts and i want to thank mubles0 for his excellent work.
I made a bot and it works fine, but there is one problem, it loads the CPU.
Not immediately, but after a few cycles of the search market and work on it.
Somehow, I think it's about timers.
I have two timers.First with a period of 2 seconds works inside market.Second
timer- with a period of 1 minute trying to find a market.
Аnyone encountered this problem?
Sorry for my google translate english.Attached FilesLast edited by gavvy; 26-11-2011, 04:42 PM.
Leave a comment:
-
I found the answer by trial and error. An app.config entry was set to http://uktote-api.betfair.com/tote/v1/BFToteService rather than https://uktote-api.betfair.com/tote/v1/BFToteServiceOriginally posted by Harry Boas View PostI am successfully accessing the free API and retrieving information but am mainly interested in the Tote API. To use that I have to specify a different endpoint URL to be used once I'm logged in. Could anybody tell me where the endpoint URL is specified ?
Leave a comment:
-
Time of a soccer match!!!!!
hi
Thnx for the whole vb tutorial is veryyyyyyy veryyyyyyy usefull...
with your help i have managed to create a trading bot... but for my strategy the time a match is needed (for example that the in-play everton-chealsea match is in its 36th minute. Do you have any idea how and if can I get this information?
Thanking zou in advance
Panos
Leave a comment:
-
Specifying endpoint URL
I'm impressed by the knowledge and co-operation displayed on this thread. Perhaps somebody can help with a quick and perhaps naive question from a newbie (dinosaur) whose background lies in PL1/CICS and relational databases. VB 2010 is my first exposure to object oriented languages.
I am successfully accessing the free API and retrieving information but am mainly interested in the Tote API. To use that I have to specify a different endpoint URL to be used once I'm logged in. Could anybody tell me where the endpoint URL is specified ?
Leave a comment:
-
Yes the size increases.
I'll try and see if your sugestion works. Thanks
Leave a comment:
-
Camper,
I think one of the problems may be caused by not entering all the data required in "oUpdateBet" -
Code:If stage = 1 Then .newSize = NewSize .oldSize = OldSize [B] .newPrice = OldPrice .oldPrice = OldPrice[/B] End If If stage = 2 Then [B] .newSize = OldSize .oldSize = OldSize[/B] .newPrice = NewPrice .oldPrice = OldPrice End If
Not quite sure what "CancelBet2(Bet2Id)" does, if it cancels the original bet then this is okay only if the size of the bet increases - if the new bet size is less than the original bet, then there is no new betId
Hope this is of some help,
cheers
Leave a comment:
-
I'm trying to place bets under 2 while greening.
I get an error when I'm updating the size after making a bet with size 2.
The code I'm using:
The error I'm getting:Code:Private Sub UpdateBet(ByVal Bet2Id As Long, ByVal NewPrice As Decimal, ByVal OldPrice As Decimal, ByVal NewSize As Decimal, ByVal OldSize As Decimal) Dim oUpdateBetsReq As New BFUK.UpdateBetsReq Dim oUpdateBetsResp As BFUK.UpdateBetsResp Dim oUpdateBet As New BFUK.UpdateBets With oUpdateBetsReq .header = SessTok With oUpdateBet .betId = Bet2Id .newBetPersistenceType = BFUK.BetPersistenceTypeEnum.IP .oldBetPersistenceType = BFUK.BetPersistenceTypeEnum.IP If stage = 1 Then .newSize = NewSize .oldSize = OldSize End If If stage = 2 Then .newPrice = NewPrice .oldPrice = OldPrice End If End With ReDim .bets(0) .bets(0) = oUpdateBet End With oUpdateBetsResp = BetFairUK.updateBets(oUpdateBetsReq) With oUpdateBetsResp CheckHeader(.header) If .errorCode = BFUK.UpdateBetsErrorEnum.OK Then For i = 0 To .betResults.Length - 1 With .betResults(i) If .success Then If stage = 1 Then CancelBet2(Bet2Id) If .newBetId <> 0 Then newbetId = CLng(.newBetId) Else stage = 0 TheBetId = Bet2Id GetBetStatus(markid) Checkbet.Enabled = True End If End If End With Next End If End With End Sub
Leave a comment:
-
Reply to BigSprout and Mumbles0
Thanks to both of you for the solutions. I've ammended my app now and it works fine.
Thanks again,
Hoytman
Leave a comment:


Leave a comment: