Dealing with usage limits

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arbu
    Junior Member
    • Nov 2012
    • 16

    #1

    Dealing with usage limits

    I've been using the betfair API for a while now and have just started running into usage limits. What I see is that I get BFUK.GetMarketPricesErrorEnum.API_ERROR and BFUK.GetMarketErrorEnum.API_ERROR errors when I make requests too frequently. So clearly I need to manage this. Two questions:

    1. Is there a way to know when I can make a new request? My understanding is that I'm limited to ten per minute, so I could just wait six seconds each time. But in practice it seems that I can do them more frequently than this. I suppose I could try every half second until I'm successful. But it would be better if I could just get a notification of when I'm entitled to make a new one. Is this possible?

    2. I see here that it's possible to request multiple markets in each data request. I wasn't aware that this was possible. I thought that the way it worked was that you declared a BFUK.GetMarketReq and specified the marketId for this and that counted as one request. Can anyone kindly clarify this?

    Thanks
  • AlgoTrader
    Junior Member
    • Mar 2012
    • 243

    #2
    Did you hear the old API V6 is about to be discontined? Do you know the new API NG is free and not throttled at the current moment of time?

    It's certainly time to switch to API NG
    Betfair Bots Made Easy

    Comment

    • Arbu
      Junior Member
      • Nov 2012
      • 16

      #3
      Originally posted by AlgoTrader View Post
      It's certainly time to switch to API NG
      Are you sure? I've spent about four hours today trying to switch over. I can get a response to this request:

      Dim postData As String = "[{""jsonrpc"": ""2.0"", ""method"": ""SportsAPING/v1.0/listMarketTypes"", ""params"": {""filter"":{""eventTypeIds"":[""7""]}}, ""id"": 1}]"

      but when I try to copy the horseracing codehere I have:

      postData = "[{""jsonrpc"":""2.0"",""method"":""SportsAPING/v1.0/listMarketCatalogue"",""params"":{""filter"":{""ev entTypeIds"":[""7""],""marketTypeCodes"":[" & _
      """WIN"",""PLACE""],""marketStartTime"":{""from"":""2014-03-24T00:00:00Z"",""to"":""2014-03-24T23:59:00Z""}},""maxResults"":""200"",*""marketP rojection"":[""MARKET_START_TIME"",""RUNNER_METADATA"",""RUNNER _DESCRIPTION""," & _
      """EVENT_TYPE"",""EVENT"",""COMPETITION""]},""id"":1}]"

      which just gives me a "webexception" error. Once I get this figured out I still have to figure out how to unpack the data, and then get data for each individual horse race. Realistically it's going to take me, what, 2-3 days to get things up and running with the new API? I'd much rather stick with the old one if I can.

      Comment

      • tkw141
        Junior Member
        • Nov 2013
        • 18

        #4
        Hi,

        You seem to have a * after the maxResults comma

        Code:
        ""maxResults"":""200"",*""marketProjection""

        It might be that
        Tony

        Comment

        • Arbu
          Junior Member
          • Nov 2012
          • 16

          #5
          Brilliant, thanks. Oddly this just showed as a space in my vb browser but when I deleted it, it started working. I shall press on.

          Comment

          • AlgoTrader
            Junior Member
            • Mar 2012
            • 243

            #6
            Working with a JSON as a string is the real pain. JSON is a format of serialization objects, so we can make object

            var ourObject = { x: 1, y: 2 }

            then get JSON by serializing it

            var jsonString = JSON.stringify(outObject);

            When we got response, we deserialize JSON into object and work with it as an object.

            VB also has lots of JSON libs, for example http://www.ediy.co.nz/vbjson-json-pa...xidc55680.html
            http://www.pozzware.com/pozzware/Cor...20Library.aspx
            Betfair Bots Made Easy

            Comment

            • Arbu
              Junior Member
              • Nov 2012
              • 16

              #7
              Originally posted by AlgoTrader View Post
              Working with a JSON as a string is the real pain. JSON is a format of serialization objects, so we can make object

              var ourObject = { x: 1, y: 2 }

              then get JSON by serializing it

              var jsonString = JSON.stringify(outObject);

              When we got response, we deserialize JSON into object and work with it as an object.

              VB also has lots of JSON libs, for example http://www.ediy.co.nz/vbjson-json-pa...xidc55680.html
              http://www.pozzware.com/pozzware/Cor...20Library.aspx
              Am running into version problems when I look at each of these. I'm using Visual Basic 2005 (.net). The first of these links is in VB6 and I get a list of 103 upgrade tasks when I try to open it. The second is written in a later version of vb and I can't open the download. I'd be happy to use the code in his webpage but it's not all posted. For instance the JSON.JSONObject is not defined.

              Looks like I have to start from scratch in converting these strings to my objects.

              Comment

              • AlgoTrader
                Junior Member
                • Mar 2012
                • 243

                #8
                I stopped to use VB 10 years ago. The examples are from Chrome console, chrome runs JavaScript
                Betfair Bots Made Easy

                Comment

                • Guest

                  #9
                  Originally posted by AlgoTrader View Post
                  I stopped to use VB 10 years ago. The examples are from Chrome console, chrome runs JavaScript
                  Hi Algo - first mate the new API allows you to get several results at once. I can update all my horse races (next 20) in one call. When you call MarketBook you can provide a list of Market Ids in the request string like I have done below.

                  Code:
                  fnReturnMarketBookData = clientBF.listMarketBook(MarketIDsToGet, priceProjection)
                  You stated above that JSON is a pain, and I thought so to at first. I do wish that they didn't use " as string delimiters since we have parse JSON as a string. You think the JSON developers could have used single quotes ' or another delimiter type, but oh well.

                  Having said that I don't have to deal with JSON at all. I see the request go out and response come back like below (in debug window). But then I just access the data through the class structures which have been provided in the API_NG example posted in the forums here.


                  Code:
                  Got Response: {"jsonrpc":"2.0","result":[{"marketId":"2.100931732","isMarketDataDelayed":true,"status":"SUSPENDED","betDelay":0,"bspReconciled":false,"complete":true,"inplay":false,"numberOfWinners":1,"numberOfRunners":6,"numberOfActiveRunners":6,"totalMatched":0.0,"totalAvailable":1117.23,"crossMatching":false,"runnersVoidable":false,"version":126288826,"runners":[{"selectionId":6943741,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":4.7,"totalMatched":0.0,"ex":{"availableToBack":[],"availableToLay":[],"tradedVolume":[]}},{"selectionId":4108998,"handicap":0.0,"status":"ACTIVE","adjustmentFactor":26.7,"totalMatched":0.0,"ex":{"availableToBack":[{"price":1.16,"size":92.75},{"price":1.15,"size":7.42},{"price":1.1,"size":22.26}],"availableToLay":[],"tradedVolume
                  
                  blah blah blah

                  The JsonRpcClient.vb does the JSON de/serialization and makes a call to the Newtonsoft.Json.6.0.1 package which does all the hard work

                  Comment

                  • AlgoTrader
                    Junior Member
                    • Mar 2012
                    • 243

                    #10
                    Originally posted by troyedwards8 View Post
                    You stated above that JSON is a pain, and I thought so to at first. I do wish that they didn't use " as string delimiters since we have parse JSON as a string. You think the JSON developers could have used single quotes ' or another delimiter type, but oh well.
                    I never said JSON is pain. I said it is pain to parse JSON manually and manually serialize it. If one tries to do with JSON anything but parsing/serialization, then he certainly wants to have troubles.

                    JSON is not just text, it is serialized JavaScript object. JSON stands for Java Script Object Notation, any JSON is a valid JavaScript code. Yep, you can run JSON just as code in JavaScript interpreter. But nobody really runs it because of security, even in JavaScript JSON is parsed.
                    Betfair Bots Made Easy

                    Comment

                    • Guest

                      #11
                      Whoops you are correct. I jumped the gun there.

                      Comment

                      • Arbu
                        Junior Member
                        • Nov 2012
                        • 16

                        #12
                        Making some progress using the parsing code from https://api.developer.betfair.com/se...pageId=3834079. I can now get a list of all the day's horse racing win and place markets with their marketIDs, start times and names.

                        Next step is how to find out which win market relates to which place markets. Is there a good way to do this without iterating through all of them to find a match?

                        Also I need to know the number of winners in the place markets. This was easy enough in the old API but I don't see a way now. Any pointers?

                        Thanks.

                        Comment

                        • betdynamics
                          Junior Member
                          • Sep 2010
                          • 534

                          #13
                          The number of places is determined through the call to listMarketBook.

                          From memory, the property you are interested in is "numberOfWinners"

                          Comment

                          • Arbu
                            Junior Member
                            • Nov 2012
                            • 16

                            #14
                            Thanks, I'll look into it.

                            Is the whole thing down today? My requests seem to hang, and the page where I got the application key from https://api-ng.betstores.com/account/ says "Bad Gateway".
                            Last edited by Arbu; 02-04-2014, 11:51 AM.

                            Comment

                            • Arbu
                              Junior Member
                              • Nov 2012
                              • 16

                              #15
                              OK, I've got it broadly working now (phew!). I need to get the horse names - at the moment I only have their selectionIds. Would I be right in thinking that this has to be done through ListMarketCatalogue (RUNNER_METADATA/RUNNER_DESCRIPTION) rather than ListMarketBook?

                              Comment

                              Working...
                              X