Using VB2008 to acccess the Betfair API: A tutorial

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

  • antonello273
    replied
    Update bets

    Thanks I solved it by myself, found the solution.

    Leave a comment:


  • antonello273
    replied
    updatebet

    Hello everyone, first of all I CuSO for my English, I state that programming vb.net are a beginner, having said that you tell me how I can open the "UpdateBet" du times consecutively? I tried using the function call, but I noticed that the first time is the second tells me there are a pricing error, ie the value of nudprice back to 1000 instead of changing the value 10.
    Thanks and I apologize again for my English.

    I post my code:

    Private Sub bPlaceBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bPlaceBet.Click
    Dim quota As Decimal
    Dim stake As Decimal
    Print("*** PlaceBet ***")


    If stake < 2.0 Then
    If rbBack.Checked Then BetType = bfuk.BetTypeEnum.B Else BetType = bfuk.BetTypeEnum.L 'Select Back or Lay bet
    PlaceBet(IdMercato.Text, IdSelezione.Text, bfuk.BetTypeEnum.B, 1000, 2) 'The call to place the bet
    Call UpdateBet(TheBetId, 1000, 1000, 2 + nudSize.Value, 2)
    quota = InputBox("Iserisci la nuova quota")
    nudPrice.Value = quota
    Call UpdateBet(TheBetId, nudPrice.Value, 1000, nudSize.Value, 2 + nudSize.Value)
    Else

    BetPrice = nudPrice.Value 'The selected price
    BetSize = nudSize.Value 'The selected bet size

    PlaceBet(IdMercato.Text, IdSelezione.Text, bfuk.BetTypeEnum.B, BetPrice, BetSize) 'The call to place the bet
    End If

    End Sub

    Leave a comment:


  • valentroch
    replied
    Thank you for the response Mumbles0.

    I will try and I tell you back if it works.

    Leave a comment:


  • Mumbles0
    replied
    valentroch,

    It’s possible that your problem is caused by the API’s use of type Double to hold price values. This can cause rounding errors.

    Try using a rounding function like this:

    odds = 1.54 'Your odds value
    .price = Decimal.Round(CDec(odds), 2)
    This is not guaranteed to work, but it might improve the problem.

    Leave a comment:


  • valentroch
    replied
    Invalid_Price error

    Hi,

    Thank you for this topic. It very helped me to make a automatic exchange program.

    But I have a little problem. I place a lot of bet with my program and mostly it works but sometimes I have an INVALID_PRICE error (bet's Result Code). I have this problem even with totally normal odds (like 1.36, 1.54, 1.81, 1.33, 1.07, 1.06)... I don't understand. Can anybody help me?

    Thank you
    valentroch

    Leave a comment:


  • Ferbar11
    replied
    What is the best value for the purpose timer function with TabControl?

    1000 ms?

    Leave a comment:


  • Ferbar11
    replied
    How can I place a bet with less than 2€?

    Leave a comment:


  • monkeymagix
    replied
    Throttle_limit

    Cheers for replying Mumbles and BigSprout

    I am already looking into compressed version of market prices but I would like to solve this issue as it is troubling me why my code loses all it's references after a call to my beat method.

    My code is built as a windows service and is already using timers to initiate calls to my Bot at 30 second periods using a Timer object.

    I will amend my code to check for the bestPrices length before accessing them to see if that fixes the problem but it does seem to happen ONLY after a THROTTLE LIMIT error so I am 99.99% sure the issue is down to that and I am wondering if there is some method I can call after a "Beat Throttle Limit" check to ensure all references are still available and if not re-gain them.

    As for server time difference issues I have most certainly run into issues with this before. It would be nice to know how out of sync my server is with Betfair's so that I can add/subtract this to my calculations.

    I know from my day job that our DEV and PRODUCTION servers are up to a minute out of sync and even on the PRODUCTION server our web and DB server are 10+ seconds out of sync which makes scanning log files looking for errors logged in the DB a right pain the XXX.

    Thanks for your help!

    Leave a comment:


  • Mumbles0
    replied
    Beating the throttle limit.

    Monkeymagix,

    Beating the throttle limit.

    You have a scheme which attempts to deal with the call rate limits imposed by the free API. This scheme requires your computer’s clock to be synchronized to Betfair‘s.

    It assumes that Betfair count the calls during a one minute time window and reset the counter at the end of each minute. I experimented with this, but my observations were inconsistent with this assumption. Exactly how Betfair determine the EXCEEDED_THROTTLE condition remains a mystery to me.

    Sleeping the thread could freeze your app until the next minute commences. This may be OK for an unattended bot, but, in general, it may not be a sensible thing to do.

    A more conservative strategy is to simply restrict your call rate using, say, a timer control, rather than firing off a barrage of calls and taking corrective action when the calls ultimately fail.

    The contents of the program’s variables (including object references) should not be affected by the Thread.Sleep call. I don’t know what could be causing your problems here.

    AFIK, the call count is done on a “user” basis, so you can’t “beat the throttle” by using multiple computers concurrently with the same Username.

    BTW, as BigSprout has pointed out, getMarketPrices has a call limit of only 10/min, If you are running into throttle problems you would be better off calling getMarketPricesCompressed. This returns the same data but has a much higher call limit (60/min). See step 14.


    Error: Index was outside the bounds of the array.

    Sometime there is no money for a runner. In this case the .bestPricesToBack array (or .bestPricesToLay) will be empty. So you should always test the length of these arrays before you access any element. Do something like this (if you’ll pardon the VB):

    Code:
      With MpriceResp.marketPrices.runnerPrices(i)
        If .bestPricesToBack.Length > 0 Then backPrice = .bestPricesToBack(0).price
        If .bestPricesToLay.Length > 0 Then layPrice = .bestPricesToLay(0).price
     End With
    If you don’t do this you will get the error.
    Last edited by Mumbles0; 20-04-2011, 12:02 PM.

    Leave a comment:


  • Ferbar11
    replied
    Originally posted by Mumbles0 View Post
    oHeaderUK() is a function, described in Step 5.

    Thanks for help me.

    Leave a comment:


  • Mumbles0
    replied
    oHeaderUK() is a function, described in Step 5.

    Leave a comment:


  • Ferbar11
    replied
    Originally posted by Mumbles0 View Post
    Ferbar11,

    Whenever you cal the API it is always a good idea to check for errors in case the call doesn't work properly. Do something like this:

    Code:
      Dim Req As New BFUK.GetAccountFundsReq
      Dim Resp As BFUK.GetAccountFundsResp
    
      Req.header = oHeaderUK()
      Resp = BetFairUK.getAccountFunds(Req)
    
      With Resp
        CheckHeader(.header)   'Check the header for API error
        If .errorCode = BFUK.GetAccountFundsErrorEnum.OK Then
    
          lShowSaldo.Text = .availBalance  'OK, show balance in the textbox
    
        Else
          Print(.errorCode.ToString)  'If getAccountFunds error
        End If
      End With
    The code shown here does full error checking and will only update the textbox if the call worked OK. Otherwise it will tell you what the problem is.
    What is it; oHeaderUK() ? Method? Variable?

    Leave a comment:


  • BigSprout
    replied
    Originally posted by monkeymagix View Post
    ...My bot only runs once every 30 seconds. So I should not be running into issues related to calling the same market more than once every 30 seconds and can only presume the fault lies when I am trying to get prices for multiple markets (e.g all markets for a day) or something else.

    Any ideas?

    Hmmm, seems I did misinterpret what you wrote

    What I now understand is that you are calling multiple markets every 30 seconds using GetMarketPrices...if this is the case then I refer to my original post

    You can only call GetMarketPrices 10/minute, any more than that and an "Exceeded_Throttle" error is sent, the 10/minute limit is for all markets - not for just one market.

    You appear to be calling multiple markets twice/minute, if at any time the accumulative number of the markets exceed 10, then the error will occur.

    Please advise if I am correct this time and we can then look at an alternative - as this is a tutorial on VB2008 it may be best if another thread was started

    ...or...I could be wrong once again

    cheers

    Leave a comment:


  • Mumbles0
    replied
    GetAccountFunds

    Ferbar11,

    Whenever you cal the API it is always a good idea to check for errors in case the call doesn't work properly. Do something like this:

    Code:
      Dim Req As New BFUK.GetAccountFundsReq
      Dim Resp As BFUK.GetAccountFundsResp
    
      Req.header = oHeaderUK()
      Resp = BetFairUK.getAccountFunds(Req)
    
      With Resp
        CheckHeader(.header)   'Check the header for API error
        If .errorCode = BFUK.GetAccountFundsErrorEnum.OK Then
    
          lShowSaldo.Text = .availBalance  'OK, show balance in the textbox
    
        Else
          Print(.errorCode.ToString)  'If getAccountFunds error
        End If
      End With
    The code shown here does full error checking and will only update the textbox if the call worked OK. Otherwise it will tell you what the problem is.

    Leave a comment:


  • monkeymagix
    replied
    Beating Throttle Limit

    Thanks for replying Big Sprout but if you actually read what I said and look at the code I posted:

    a) I said the following "I thought that rather than get a single horse at one time I would just loop through all the selections in the market and return a list object of a custom struct (bet selection) that could then be saved to the DB."

    So I am not getting the price of a single horse at one time BUT rather I am doing it the way you suggested and getting all the selection prices for a market in one go.

    b) I am using BetfairUK.getMarketPrices to get all the prices for one market.

    I am looking into the compressed version but I would still like to solve this problem with the null object reference after a wait if possible.

    My bot only runs once every 30 seconds. So I should not be running into issues related to calling the same market more than once every 30 seconds and can only presume the fault lies when I am trying to get prices for multiple markets (e.g all markets for a day) or something else.

    Any ideas?

    Leave a comment:

Working...
X