Incorrect API Key after 100 or so quick requests

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RegularRefunds
    Junior Member
    • Mar 2016
    • 6

    #1

    Incorrect API Key after 100 or so quick requests

    Hi,

    I have an application that queries the Betfair API (listMarketBook) potentially thousands of times, but it gets into about 100 records, and it throws an exception with error:

    "INVALID_API_KEY"

    Any ideas on what the problem is? Is there a limit on how many calls I can make in a certain amount of time?
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    The limit for listMarketBook for any market is five times per second. Betfair only updates each market five times per second, so requesting the data more frequently is pointless.

    Comment

    • RegularRefunds
      Junior Member
      • Mar 2016
      • 6

      #3
      The requests are not made for the same markets, but different markets, would this make any difference?

      Comment

      • BetfairDeveloperProgram
        Administrator
        • Oct 2008
        • 679

        #4
        Hi,

        Are you logging in and creating a new session before making each listMarketBook request?

        Thanks

        Neil

        Comment

        • RegularRefunds
          Junior Member
          • Mar 2016
          • 6

          #5
          Hi Neil,

          I am not logging in for every request, it is all done on the same session token. After so many requests like this my account is locked out for over 15 minutes (I'm unable to even log in to the Betfair site).

          Thanks in advance


          EDIT :: I am using the API-NG-sample-code project. I retrieve the session key once, which is then used for the whole procedure, however, when checking my login attempts here : https://myaccount.betfair.com/accoun...rity?showAPI=1 - there are many attempts at the same time which seems to suggest otherwise?

          Login record here :http://postimg.org/image/pzuhr9rkv/
          Last edited by RegularRefunds; 29-03-2016, 09:00 PM.

          Comment

          • jabe
            Senior Member
            • Dec 2014
            • 705

            #6
            Originally posted by RegularRefunds View Post
            The requests are not made for the same markets, but different markets, would this make any difference?
            I'd expect a more relevant error message if you were overdoing it.

            Your image with lots of logins at the same time is strange. I've looked at mine and they're all single occurrences.

            Comment

            • BetfairDeveloperProgram
              Administrator
              • Oct 2008
              • 679

              #7
              I am not logging in for every request, it is all done on the same session token. After so many requests like this my account is locked out for over 15 minutes (I'm unable to even log in to the Betfair site).
              I've checked our records and can confirm that you are hitting the 100 successful logins per minute ban. I'd therefore review your code and check why you might be logging in so frequently.

              Thanks

              Neil

              Comment

              • RegularRefunds
                Junior Member
                • Mar 2016
                • 6

                #8
                Thanks for pointing me in the right direction Neil, I thought this might be the case from looking at my account, I've attached my code below. I only ever make one call for a session token, but numerous calls to listMarketBook:

                private String getSessionToken()
                {
                String SessionToken = "";

                try
                {
                const string postData = "username=#########&password=##########";
                X509Certificate2 x509certificate = new X509Certificate2("c:\\ssl\\client-2048.p12", "#########");
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://identitysso-api.betfair.com/api/certlogin");
                request.UseDefaultCredentials = true;
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Headers.Add("X-Application", "###########");
                request.ClientCertificates.Add(x509certificate);
                request.Accept = "*/*";
                request.Proxy = null;
                using (Stream stream = request.GetRequestStream())
                {
                using (StreamWriter writer = new StreamWriter(stream, Encoding.Default))
                {
                writer.Write(postData);
                }
                }
                using (Stream stream = ((HttpWebResponse)request.GetResponse()).GetRespon seStream())
                {
                using (StreamReader reader = new StreamReader(stream, Encoding.Default))
                {
                var jsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<Logi nResponse>(reader.ReadToEnd());
                if (jsonResponse.loginStatus == "SUCCESS")
                {
                SessionToken = jsonResponse.sessionToken;
                }
                else {
                System.Media.SystemSounds.Exclamation.Play();
                }
                }
                }
                }
                catch (System.Exception ex)
                {
                System.Media.SystemSounds.Exclamation.Play();
                String getData = ex.Data.ToString();
                }

                return SessionToken;
                }


                public void UpdateSoccerMarkets()
                {

                // Loop through all Soccer markets
                JsonRpcClient client = new JsonRpcClient(Url, APIKey, getSessionToken());

                MarketFilter marketFilter = new MarketFilter();

                // Set projections to be returned
                ISet<MarketProjection> marketProjections = new HashSet<MarketProjection>();
                marketProjections.Add(MarketProjection.COMPETITION );
                marketProjections.Add(MarketProjection.EVENT);
                marketProjections.Add(MarketProjection.EVENT_TYPE) ;
                marketProjections.Add(MarketProjection.RUNNER_DESC RIPTION);

                // Set football market
                ISet<string> eventTypeIDs = new HashSet<string>();
                eventTypeIDs.Add("1");
                marketFilter.EventTypeIds = eventTypeIDs;

                // Loop through all competitions
                foreach (String Competition in CompetitionIDs())
                {
                // Set filter for Competition
                ISet<string> CompetitionID = new HashSet<string>();
                CompetitionID.Add(Competition);
                marketFilter.CompetitionIds = CompetitionID;

                var marketSort = MarketSort.FIRST_TO_START;

                // Get markets for this Event Type / Competition
                IList<MarketCatalogue> Markets = client.listMarketCatalogue(marketFilter, marketProjections, marketSort, "1000");

                // Update database
                EFUpdateMarkets(Markets);
                }
                }


                I really can't understand why I am logging in repeatedly?

                Comment

                • RegularRefunds
                  Junior Member
                  • Mar 2016
                  • 6

                  #9
                  FIXED.

                  I discovered another call later in my procedures that grabbed a new session token, my bad.

                  Thanks for the help guys

                  Comment

                  • betdynamics
                    Junior Member
                    • Sep 2010
                    • 534

                    #10
                    Your code in UpdateSoccerMarkets logs in EVERY time you make the call.

                    You are creating a new RPC client every time you make a call to UpdateSoccerMarkets. Initialising the client calls getSessionToken which logs you in each time in order to retrieve the session id.

                    You should create and initialise a single RPC client outside of UpdateSoccerMarkets. You can then pass that client as a parameter to UpdateSoccerMarkets so that you are re-using the existing session.
                    Last edited by betdynamics; 30-03-2016, 10:36 AM.

                    Comment

                    Working...
                    X