API-NG for dummies

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lmlac
    Junior Member
    • Feb 2014
    • 27

    #1

    API-NG for dummies

    I started using the old API from the original Excel sample spreadsheet with VBA code years ago. Over the last 9 years I've developed lots of Excel applications always starting with the code from the example spreadsheet. I know very little even about how the old API worked, although I know VBA quite well by now. I really can't go back and rewrite my bots in another language because some of them have massive amounts of code. So I'm looking at converting my code to use the new API.
    If anybody from Betfair is reading this then they will know I do contribute large chunks of liquidity into lots of markets so it might be in their interests to give me some guidance!

    First steps. OK, so I've downloaded the example excel spreadsheet. Now it looks like I need an App key before I can even log in. According to the documentation I need to use SSL to create this App key. So I go to the OpenSSL website link to download it. But all I see are some "tarball" files ending with .gz whatever they are. Can someone explain what I need to do to install SSL so I can get started on this frustration road?
  • BetfairDeveloperProgram
    Administrator
    • Oct 2008
    • 680

    #2
    Hi lmlac,

    I started using the old API from the original Excel sample spreadsheet with VBA code years ago. Over the last 9 years I've developed lots of Excel applications always starting with the code from the example spreadsheet
    We will be offering a API-NG version of the Excel VBA sample spreadsheet and expect this to be completed before the end of May.

    Thanks

    Neil

    Comment

    • lmlac
      Junior Member
      • Feb 2014
      • 27

      #3
      Thanks for the quick reply Neil. Will that spreadsheet take care of the SSL encryption and session key creation itself? Or will I still have to do these separately? I really want to do as much as I can now because I'm going to be away most of the summer and don't want to get back in August with only a couple of months left to change and test literally hundreds of code modules.

      Comment

      • BetfairDeveloperProgram
        Administrator
        • Oct 2008
        • 680

        #4
        Hi lmlac,

        The updated spreadsheet will use the interactive login method, so you will still need to implement the non-interactive login method yourself.

        FYI - You can create an Application Key for your Betfair account using the createDeveloperAppKeys operation or by using the Accounts API Visualiser (https://api-ng.betstores.com/account/).

        You can grab your sessionToken manually from your web browser - see details via https://api.developer.betfair.com/se...G+-+Visualiser

        Thanks

        Neil

        Comment

        • lmlac
          Junior Member
          • Feb 2014
          • 27

          #5
          The updated spreadsheet will use the interactive login method, so you will still need to implement the non-interactive login method yourself.


          So once I've generated the App Key once for the non-interactive sessions I don't have to do that ever again? I can use that key for every login after that?

          Comment

          • BetfairDeveloperProgram
            Administrator
            • Oct 2008
            • 680

            #6
            So once I've generated the App Key once for the non-interactive sessions I don't have to do that ever again? I can use that key for every login after that?
            Yes, that's correct.

            Comment

            • lmlac
              Junior Member
              • Feb 2014
              • 27

              #7
              OK sorry to bang on about this!

              I read in the documentation for API-NG:

              The non-interactive login method for API-NG requires that you create and upload a self signed certificate which will be used, alongside your username and password, to authenticate your credentials and generate a session token... followed by instructions on how to use SSL.

              So instead of going through this procedure I can just use the visualiser to get the key I need to login? If I use other PCs/laptops to login to the same account, can I use the same key on each machine, or do I need to generate a different key on different machines?

              Comment

              • lmlac
                Junior Member
                • Feb 2014
                • 27

                #8
                OK, another question. I'm trying to list soccer matches for a particular day. In the old API in VBA I used getEvents with a sportId of 14 to get a list of fixture date "events". Then used the event id for a particular date to search for matches with a matching parent id. Now it doesn't seem like this sport id is there in the new API, so I'm just trying to get event ids for a particular day. I don't know anything about what these JSON strings are supposed to look like or what the rules are for structuring the strings. There's an awful lot of ruddy quotation marks that's for sure. Anyway I've tried writing a function to structure the parameters for ListEvents to give me what I want but it gives me an error. Without the marketStartTime parameter it works fine, so I'm obviously not structuring this part correctly. If anyone could point out my obvious mistake I'd be eternally grateful. Or even just point me in the direction of a teach yourself JSON strings webpage that would be helpful.

                Function geteventsForDateString(ByVal event_id As String, ByVal eventDate As Date) As String
                fromDateWanted = Format(eventDate, "yyyy-mm-dd hh:mm:ss")
                fromDatePlusDay = DateAdd("d", 1, eventDate)
                endOfFromDay = DateAdd("s", -1, fromDatePlusDay)
                toDateWanted = Format(endOfFromDay, "yyyy-mm-dd hh:mm:ss")
                geteventsForDateString = "{""filter"":{""eventTypeIds"":[""" & event_id & """],""marketStartTime"":{""from"":""" & fromDateWanted & """,""to"":""" & toDateWanted & """}}}"
                End Function

                Comment

                • lmlac
                  Junior Member
                  • Feb 2014
                  • 27

                  #9
                  OK I'm going to try and answer my own questions as no-one else seems to know. I'm assuming I don't need to go through the SSL installation palaver because I can just use the same App key from the visualiser over and over again. Which is probably not ideal because I guess it's less secure in the long run. And I'm going to assume that the same key can be used for different PCs. If it isn't then I'll find out soon enough.

                  For the filter code that wasn't working I had just copied the marketStartTime parameter format from function GetListMarketCatalogueRequestString in the example VBA code. I sort of assumed it was formatted correctly. The reason it wasn't working is that the date needs to be formatted as "2014-02-11T00:00:00Z" to include "T" and "Z".

                  Onwards and upwards.

                  Comment

                  • lmlac
                    Junior Member
                    • Feb 2014
                    • 27

                    #10
                    Also http://json.org/ gives an explanation of the constructs even I can understand.

                    Comment

                    • BetfairDeveloperProgram
                      Administrator
                      • Oct 2008
                      • 680

                      #11
                      Hi lmlac,

                      So instead of going through this procedure I can just use the visualiser to get the key I need to login?
                      You appear to be confusing App Keys with SSL certificates. You need to create an SSL certificate and link this to your Betfair account in order to use the non-interactive login method. This is the secure method for logging into the Betfair API automatically.

                      If you prefer to use a desktop style login, you should use the interactive login method.

                      The App Key is used to identify a user’s requests to API-NG. The App Key is required to be passed in every API-NG request along with the session token that is created at Login.

                      I hope this clarifies things.

                      Neil

                      Comment

                      • lmlac
                        Junior Member
                        • Feb 2014
                        • 27

                        #12
                        And things were just starting to go so well.

                        OK, I'm not only confused about the difference between SSL and App keys, I'm also confused about the difference between interactive and non-interactive logins. Us dummies often get confused.

                        So I do need to use SSL to create the App key for the non-interactive login? So I go to the OpenSSL website link to download it. But all I see are some "tarball" files ending with .gz whatever they are. I'm getting deja-lu !
                        Can anyone enlighten me and give Neil a break from dealing with this idiot?

                        Comment

                        • BetfairDeveloperProgram
                          Administrator
                          • Oct 2008
                          • 680

                          #13
                          Hi lmlac,

                          So I do need to use SSL to create the App key for the non-interactive login?
                          To clarify, OpenSSL is not used to create the App Key, OpenSSL is used to create the self signed certificate for the non-interactive login.

                          We are currently putting additional documentation together that should make this process a lot easier for those experiencing similar issues.

                          I'll link to this documentation from this page once this is complete.

                          Thanks

                          Neil

                          Comment

                          • lmlac
                            Junior Member
                            • Feb 2014
                            • 27

                            #14
                            Thanks Neil. In the end I didn't download any files from the SSL site. It seemed easier to use slproweb.com. I also downloaded the Microsoft Visual C++2008 Redistributable. Managed to go through the certificate creation procedure and got the curl command line to return a session token, which was pleasing! Still have to work out how to login using VBA though. Had some problems along the way:
                            1 Got an error message "Unable to write random state" when trying to create the key. Got round that by setting RANDFILE at the command line prompt: set RANDFILE=c:\openssl-win64\.rnd

                            2 Had lots of problems with the config file. Again used the command line: set OPENSSL_CONF=c:\openssl-win64\openssl.cnf
                            (I'd already copied the .cnf file from some other location and added the recommended lines)

                            3. Downloaded cUrl from http://www.confusedbycode.com/curl/

                            Comment

                            • tkw141
                              Junior Member
                              • Nov 2013
                              • 18

                              #15
                              Hi lmlac,

                              I've sent you a PM.

                              Comment

                              Working...
                              X