Using VB2008 to acccess the Betfair API: A tutorial
Collapse
This topic is closed.
X
X
-
BigSprout thank you for your answer now everything is working properly. I have one more question. How can I check current score of the game. Most interests me soccer
-
mbrylski,
at times there is no prices for the Back or Lay and this is the reason you are getting this error, try something like this to test that there is a price first:
orCode:dgvField("FdBk", Rw).Value = If(.bestPricesToBack.Length > 0, Format(.bestPricesToBack(0).price, " 0.00"), "") 'Update best Back price dgvField("FdLay", Rw).Value = If(.bestPricesToLay.Length > 0, Format(.bestPricesToLay(0).price, " 0.00"), "") 'Update best Lay price
Code:If .bestPricesToBack.Length > 0 Then Field(Fd).Fld(Rw).ftBck = .bestPricesToBack(0).price 'Update best Back price Field(Fd).Fld(Rw).ftbAmt = .bestPricesToBack(0).amountAvailable End If If .bestPricesToLay.Length > 0 Then Field(Fd).Fld(Rw).ftLay = .bestPricesToLay(0).price 'Update best Lay price Field(Fd).Fld(Rw).ftlAmt = .bestPricesToLay(0).amountAvailable End If
Edit:
replace "dgvField("FdBk", Rw).Value" and "Field(Fd).Fld(Rw).ftBck" for your own variablesLast edited by BigSprout; 28-06-2011, 02:39 AM.
Leave a comment:
-
Hi All
Mumbles0 I found a bug in the procedure from Step 14. Generally it working very good except when market for back or lay is empty. When I tray use .bestPricesToBack(0).price Or .bestPricesTolay(0).price I receive the message “Index out of range”.
Can you correct this??
Maybe it is not a bug it is problem with function which display result. How can I check the range of bestPricesToBack or bestPricesTolay. I know the maximum is three, can I check the current range.Last edited by mbrylski; 27-06-2011, 09:02 PM.
Leave a comment:
-
Thanks for the replies. I had used WithEvents and got async calls working fine in one class, I just wasn't sure if I could use the service object in more than one class or if I would run into problems.
I found my applications became restricted when placing all the calls in one class as I couldn't deal with different responses how I wanted and everything was too generic. Therefore I have gone down the route of using a 'Session' class that handles the key and provides API headers, then another class to 'allocate' the data to custom objects. Then I have some worker classes that handle all the program logic. These worker class make all the calls so I needed each one to have it's own API object. I will probably run into problems with this method further down the line and end up changing the whole structure of my application .... But that wouldn't be the first time!
Leave a comment:
-
This is fun. My bot is now placing bets for me :-)
One thing I need to be able to do is stop it from placing a second bet on the same selectionID when the bot loops back round. What's the best way to do this? I am looking at calling GetBetHistory and putting some logic in there against the returned selectionID's but if there's an easier way I'm all ears....
Leave a comment:
-
Beans,
You can have as many instances of the BFGlobalService (or BFExchangeService) class as you want. Go ahead, it's fairly efficient, besides, you have lots of memory.
Looks like you have realized that, with async calls, you need a separate service object on each form (or class) which accesses the API, in order to handle the resulting "completed" events. (Of course each service object variable should be declared with the WithEvents keyword as BigSprout points out.)
Having said this, did you know that it’s possible to put all of your async API calls into a single class? Here, data from the API can be returned to the calling program using Event properties defined in this class. If you are interested I can show you how to do this.
Leave a comment:
-
Hi Beans,
you need to change this:
to this to to be able to use Async on the global serverCode:Dim BetfairGL As New BFGlobal.BFGlobalService
I converted most of my calls to Async mode and this was the only major change needed (please note, my naming of the global server may be different to Mumbles)Code:Dim [B][COLOR="Red"]WithEvents[/COLOR][/B] BetfairGL As New BFGlobal.BFGlobalService
Leave a comment:
-
Hi, back in step 2 we created the BetfairGL object for the BFGlobalService. I was just wondering if we are limited to only one of these objects in our application?
The reason I ask is I am trying to change my old application to an ASYNC capable version. I had classes for each type of call which shared a BFGlobalService stored in a module. Now I want to change to ASYNC I have a problem in that each class now needs it's own BFGlobalService object in order to 'Handle' the async response. Is this a problem? Does it use up lots of unnecessary memory or is it fine to create multiple versions of the service object?
Leave a comment:
-
I think I can answer my own question here. I have found the reference guide :-) Looks like GetCompleteMarketPricesCompressed can do this. 60 calls/minute should be quick enough for my needs.
And I can confirm that the error was EXCEEDED_THROTTLELast edited by NFLMAN; 21-06-2011, 11:28 PM.
Leave a comment:
-
Thanks guys,
I'll test it out when I get home.
If this is indeed the case, are there any more 'throttle generous' calls I can make that will give me the SelectionID's I require?
Cheers
Leave a comment:
-
NFLMAN,
I agree with BigSprout. Note that there are 2 errorCodes in the response object.
When oMarketResp.errorCode returns API_ERROR then the errorCode in the response header will give you more information. Try something like this
or call the CheckHeader sub.Code:With oMarketResp Print("ErrorCode = " & .errorCode.ToString) If .errorCode = BFUK.GetMarketErrorEnum.API_ERROR Then Print("HeaderCode = " & .header.errorCode.ToString) ...........
You will probably see that the API_ERROR is in fact EXCEEDED_THROTTLE.
Leave a comment:
-
Hi NFLMan,
on the free API, you are only allowed 5 calls per minute to "GetMarkets", this may be your problem.
How many correct prints do you get and is it consistent each minute?
Let us know how it goes
cheers
re-reading your code again:
You are making a call for every "womens tournament round matches" so you would be exceeding the throttle limits after 5 calls in every minuteLast edited by BigSprout; 21-06-2011, 01:33 AM.
Leave a comment:
-
Thanks Mumbles.Originally posted by Mumbles0 View PostNFLMAN,
You can also look at the menuPath string. If you study this for a while you should see a pattern emerge and gain some insight into how Betfair name market groups.
A current example:
\Tennis\Group A\Wimbledon 2011\Mens Tournament\First Round Matches\A Murray v Gimeno Traver
You can filter this for "Mens Tournament" and "First Round Matches". This obviously won't work for "Second Round Matches", etc. but you refine the filter as you go along.
I'm getting there......
I've added this after calling getAllMarkets:
This will print something like this:Code:'Unpack response into readable format and assign to AllMarkets Dim AllMarkets As New UnpackAllMarkets(oMarketsResp.marketData) With AllMarkets For i = 0 To .marketData.Length - 1 'Loop through all records in AllMrkets With .marketData(i) .marketName = "MATCH ODDS" 'Filter fo Match Odds markets .noOfRunners = 2 'Filter for 2 participants (don't think this matters) If InStr(.menuPath, "Round Matches") And InStr(.menuPath, "Womens Tournament") Then 'Further filters to find only ladies singles matches Print("MarketID=" & .marketId & " Event Start: " & .eventDate & " " & .menuPath) Dim oMarketReq As New BFUK.GetMarketReq 'Create GetMarket request object Dim oMarketResp As BFUK.GetMarketResp 'Create GetMarket response object With oMarketReq .header = oHeaderUK() .marketId = AllMarkets.marketData(i).marketId End With oMarketResp = BetFairUK.getMarket(oMarketReq) 'Call the API With oMarketResp Print("ErrorCode = " & .errorCode.ToString) If .errorCode = BFUK.GetMarketErrorEnum.OK Then With .market If UCase(.name) = "MATCH ODDS" Then For j = 0 To .runners.Length - 1 With .runners(j) Print(.name & " Selection ID: " & .selectionId) End With Next j Else Print("NO BET") End If End With End If End With End If End With Next i End With
MarketID=102995053 Event Start: 21/06/2011 14:00:00 \Tennis\Group A\Wimbledon 2011\Womens Tournament\First Round Matches\Wozniacki v Parra Santonja
ErrorCode = OK
Caroline Wozniacki Selection ID: 2309522
Arantxa Parra Santonja Selection ID: 2309573
This is exactly what I want but after a few correct prints like this I start to get this:
MarketID=102995087 Event Start: 21/06/2011 17:30:00 \Tennis\Group A\Wimbledon 2011\Womens Tournament\First Round Matches\An Rodionova v Hlavackova
ErrorCode = API_ERROR
Once the errors start I do not get any correct data again. I was thinking I was throttling it but that's a different message, yes? I can't see any references to what this error means. Any ideas?
Leave a comment:
-
You're better off using one of the historical data services available to get that kind of information.Originally posted by karas View PostHi there. quick question. is it possible through for the api to retrieve all the matched bets of a market, one by one as it happens in a list, and not just my own but all the matched bets of a specific market. thanx
Try http://solutions.betfair.com and look for Historical Data.
Leave a comment:
-
Bets matched on a market
karas,
No. you can only see your own bets with the bet status calls getMUBets, getBet, getCurrentBets etc.
However, if you analyse the data returned by getMarketTradedVolumeCompressed you can gain some insight into current betting matching on a market.
Leave a comment:


Leave a comment: