VBNet Sample (Yes really)

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davecon
    Junior Member
    • Dec 2010
    • 86

    #1

    VBNet Sample (Yes really)

    Attached is the Full C# Sample that is included in the Samples but fully converted to VBNet if anybody is interested I did it by using this amazing free app http://www.tangiblesoftwaresolutions...FTHLtAodPU0A-A
    Probably like me it may be beyond you at first but once you see how Json works you can use all the properties and classes etc with a windows form and save a lot of work
    Download it Then just Double Click on the Sin File to open in Studio
    You should not need to install anything else but let me know if you do This is a command line app same as the C# Sample - So
    To make life easier I have copied the cmd.exe into the bin/debug folder so you can just double click it and type API-ng-sample-code.exe YourAppKeyHere YourSessTokenHere
    Leave a space between exe-AppKey-Sess
    And press Enter Key to run the Sample
    If the cmd.exe does not work then just copy cmd.exe from your Windows\System32 Folder
    Saves a lot of typing and hair pulling to get the right path!
    Hope this will give you an insight of what its all about
    I'm starting to get to grips with it all now and I really AM a Dummy! lol
    Dave
    Attached Files
  • Guest

    #2
    Windows app ?

    Dave this looks good - i like the fact that the the vb files have the calls ready to go.

    I am a VB6 programmer and have made the upgrade to VB.NET which is a little scary (ie real classes etc). Time will make this easier.

    However I am looking for a VB.NET windows app which has just the basic betfair login and say get a market. Then I am confident I can write the rest of the code for my bet bot.

    Do you know if this exists ? or whether you can turn your dos based version into a simply windows app which does what I explained above ?

    I am quite surprised that Betfair havn't provided a good example and I have spent around 2 days surfing the web looking for stuff.

    Troy

    Comment

    • davecon
      Junior Member
      • Dec 2010
      • 86

      #3
      Originally posted by troyedwards8 View Post
      Troy
      Hi Troy
      Not surprised you can’t find any examples – the last API you couldn’t find anything!
      I was also trying to find how to log in and get my funds from accounts but I gave up and used the old API to Login and get the session Token and funds and I will use until I have time to do it with this
      However Logging in and getting a session token if you are in the UK is easy enough with the new API but I have not included any Log out or Keep alive (Never had to use it anyway for a Windows app)
      Are you aware that the Excel vba Sample is in VB5 (so I believe – before my time) but of course if you don’t have MS Office then you wont be able to access Visual Studio to get the Code
      So I have included the 2 Modules and the Json library in the VB6 Folder so you can use for reference – It does the same as all the Samples eg – Puts a dummy bet on the first selection in the first race
      You can actually run the whole thing in vbnet using textboxes – But I’m sure you will find it useful as it contains all the request strings required for all you will need
      I have put you together a Basic Windows App which I think is what you are looking for to get you started – A pic is included below along with the Zip for the vbnet
      It does the following (Change the properties for the UserName-Password and 2 App Key textboxes) Only Uses Market Catalogue Module for the Objects
      Anyhow here is my Pea brain basic Program I’m sure will help a little (I’m a Strategy Builder not a Bot Builder)
      Click Log in and gets the session Token
      Click Todays Races and Gets First 12 Races in a TreeView Control (use nud control to alter amount of races to be displayed for your own use)
      Click on any amount of the Desired Races in the TreeView Items this will then
      Open those markets in a New Tab with a New DataGridView for each one with the Selections and there ID’s
      There will be no further need to Call Market Catalogue as The Market ID’s are embedded in each Tab
      You can then go on yourself to Apply Market Book for the prices and with a Fast Timer (eg 1 sec is free) if you want to continue down the Data grid route
      Once The markets are in the grid you can Click on a grid cell to get the Cell Contents
      There is a Timer to refresh the Markets in the treeview every Minute to show the Latest races if required
      I struggled with the Json required at first but asked the question Online here http://stackoverflow.com/questions/2...ems-with-vbnet and everything became clear after this kind chap put me right – So we can now both probably go on to using the more elaborate VBNet Sample that I converted from the C# Sample earlier on here!
      If you also refer to Peters Post here as he is kindly doing a vbnet thread http://forum.bdp.betfair.com/showthr...=8984#post8984 and you should hopefully have enough to get you going and then create a much better App then I could possibly produce
      Hope this helps and Sorry if you have Eye Strain lol
      Dave
      Attached Files

      Comment

      • Guest

        #4
        Thanks

        Hi Dave

        Sorry for the delay - busy week at work

        Mate thanks for the code which had a look at.

        I was playing around with betfairs Account API-NG Visualiser and managed to create my two applicaton keys (a live one and delayed one). Somehow I also managed to get my session token (ssoid) but now can't remember

        Anyway using the API-NG code and passing in the 2 command line arguments app_key and ssoid, the app logs in for me and returns a heap of JSON strings - YAY.


        I was then wondering whether my app keys and ssoid stay the same for ever? The answer is the app keys remain the same BUT the ssoid changes. Hmmm how to get a new ssoid ?

        Using your basic app, I see my using the login a session token (ssoid) is returned however it doesn't bring up any races. Could be cause i am in AUS and not UK, but at least the code I can look at and try and learn. I have VS2010 and 2013


        I will get back to you if I learn anything but it is slow going.


        You think the betfair guys would just put some code together which shows how to login, fill a TV view with markets and then when we select the market then fill the text boxes with back and lay market. Then we can use the code to build on.




        Hey quick question about betfair in the UK. Are you guys allowed to make live (inplay) bets over the internet or do you have to use the phone like us in AUS? We can only make bets over the internet prior to an event starting

        Comment

        • davecon
          Junior Member
          • Dec 2010
          • 86

          #5
          Hi Troy
          Wish we had some of your Hot weather here mate lol
          It seems the App Keys are permanent so embed them in your app along with your UserName and Password if only you are going to be using it
          The session Token though needs to be renewed with each Login (the basic bot I gave you does that as you seem to have discovered) If you want to use the Visualizer as well you can Copy and Paste the one generated in basic bot – Saves you trawling through site page Cookies to retrieve one
          There exists a Keep Alive Call to keep it in play after 20 mins but don’t be concerned about it with Desktop bots as you will have a Timer making market calls a lot faster than that! And if you don’t use any timers whilst testing you may as well just Login again if it was to expire – Ive Never had to use it!
          Ive used the same Session Token for Days while I was playing with the Excel sample while also using the Site and the Old API at the same time with Different Tokens!
          Just a few Minor Adjustments for OZ
          In the Function CreateRequest Just Change the line
          Dim Url As String = https://api.betfair.com/exchange/betting/json-rpc/v1/
          TO Url As String = https://api-au.betfair.com/exchange/betting/json-rpc/v1
          Then in the Function GetMarketCatalogue()
          Swap ""marketCountries"":[""GB""] to ""marketCountries"":[""AU""]
          Also at the End of this String I think you also change ""id"": 1} to ""id"": 2}
          It seems to work with both doing just the Catalogue but as below all your Market ID’s start with 2. While UK start with 1. So I suppose it seems logical to change that as well
          Finally in Private Sub tvMarkets_AfterSelect – Change the MarketID prefix
          If e.Node.Text.Contains("1.") TO If e.Node.Text.Contains("2.")
          Then all should work fine
          Yes we can Bet in Running on all events Racing Football Tennis Bla bla to the death with API and Site betting
          We Can also Bet in running on Aus stuff as well once we are verified– I thought you were allowed to do that now with the Betfair API? Not just Phone (Thought it was all sorted with your Gov and Betfair?)
          Hope this helps
          Dave

          Comment

          • Trickie13
            Junior Member
            • Jan 2014
            • 7

            #6
            Hi Dave

            Thank you for providing this program. I am using vb2008 express and found that your program would not open up, however I was able to open the form in notepad+ and from there have now written several sports and accounts calls which all work fine.

            One problem I have had though is I can't seem to make KeepAlive or Logout work. Should be really easy but I've been scratching my head for hours now lol! I know neither is probably necessary strictly speaking but for the sake of completeness and so that it doesn't beat me I would like to have working calls to these.

            There is a KeepAlive vb sample on the net somewhere, but it doesn't work, or at least it doesn't seem to return the SUCCESS or FAIL status. Do you think you could post a working KeepAlive and Logout sub if you have them?

            Thanks

            Rich

            Comment

            • davecon
              Junior Member
              • Dec 2010
              • 86

              #7
              Hi Rich
              Firstly Install Windows for Desktop 2013 from here Its same as 2008/10 but a miles better version
              http://www.visualstudio.com/download...d-2013-express
              On the other issue I have no Idea how to Logout and I did a Keep alive here though dont know if it actually works lol
              http://forum.bdp.betfair.com/showpos...36&postcount=8
              I dont see any reason to use Keep Alive with a Bot so is it for Web Stuff I dont know? Why would your Bot be Inactive for 20 mins? Just log in again if you do everything Manually on your App or just use the site?
              Dont know how to Log Out and I never Log out of anything anyway even my bank Why? All this stuff would only be necessary if somebody else is using your Computer or App or 3rd Party stuff or Something
              Emptying Cookies, History Cache and other Paranoia
              I'm afraid I dont even know how to get the Accounts so why not just use the Old API for Login Logout KeepAlive and Accounts if it should bother you at this stage mate?
              If anybody could please Explain just what and WHEN this Keep Alive is For? Ive never had to use it and the Session Token lasts for Days sometimes (If you dont log out lol)
              The site never Times Out so why should your Bot?
              Hope this Helps (But probably not Sorry lol)
              Dave

              Comment

              • Guest

                #8
                Thanks mate

                works like a dream

                Last edited by Guest; 29-05-2020, 01:22 AM.

                Comment

                • Trickie13
                  Junior Member
                  • Jan 2014
                  • 7

                  #9
                  Hi Dave

                  Thanks for your speedy response!

                  Regarding installing vb2013, it's probably not advisable for me. My PC is a few years old and runs XP. When I first put vb2010 on it, it "worked" but was so slow it was basically unusable. Trouble was, vb2008 no longer worked, even after uninstalling vb2010, so I had to reinstall windows and then vb2008 again which was a pain! I've no doubt that vb2013 is good, but until I know that it will work on my XP machine OR that I will be able to continue using vb2008 alongside it, I don't want to risk having to reinstall windows again if I don't have to.

                  On the api, both my sports and accounts calls are working fine, they were easy to write after adapting your code. As for KeepAlive and Logout, it's partly for completeness and partly because if I don't manage to get some working code now that I've tried then it will bug me for ever more! Your post you linked to is the one I saw before, but it doesn't work as it should. The "status" you obtain is the status of the web response rather than the result of the KeepAlive from the api, and if you look at the header you will see that the response is just a png image, whereas it should be a json string showing status as SUCCESS or FAIL. I also adapted this code for Logout, but was able to continue making api calls even after executing the "Logout" so clearly it didn't work!

                  Sometimes I will be more than an hour between bets which is why I wanted to use the KeepAlive. I guess I could just use something simple like getAccountFunds, but as I said above it will bug me if I don't manage to successfully program KeepAlive and Logout calls. I also would prefer to Logout when I finish a session, again for completeness and "neatness", it will bug me if I don't.

                  One other thing - writing the json strings in vb is not "easy" because you have to use double quotes and ideally try to keep things on one line, which doesn't make it easy to see any mistakes. I decided to write my strings in a separate .txt file, so that I could use single quotes and multiple lines and easily see if and where I've gone wrong. All I needed to do then was read in the file and strip out the carriage returns and extra spaces - much easier. In your listMarketCatalogue string, both the marketStartTime and venues filters are outside the filter curly brackets so they would be ignored even if you had values in them, plus marketStatus is not a part of listMarketCatalogue so this is also ignored.

                  Thanks for your time.

                  Rich

                  Comment

                  • davecon
                    Junior Member
                    • Dec 2010
                    • 86

                    #10
                    Originally posted by Trickie13 View Post
                    Hi Rich
                    No it wont work on XP its a memory thingy - Once Installed though you can still use with 2008/10 when you do decide to upgrade your "Shed" - Whatever you do dont fall for that Abomination called Windows 8 get a Custom machine from Amazon with Windows 7!
                    So how do you Call Account Funds please? Would be grateful if you can show
                    I know what you mean about having to find the Answer at all costs even if its not required! I'm the same!
                    Reason why I dont want to get too involved with Account Funds etc lol
                    I have all the rest of the Info to build any sort of Bot now but I will be keeping it on Hold now until April to see if they are going to try and charge for this! I dont want to waste my time building something worthwhile and then dumping it later because there is no way on this Earth I am going to pay for API access along with there already Rip Off Commission Rates!
                    On the Other bit about LogOff and Keep Alive have a look at this excellent post that is tucked away at the End of this forum in "Others"
                    This Guy has it all Conquered in a very professional way using some sort of Google Code
                    https://forum.bdp.betfair.com/showth...=8900#post8900
                    Here is one of the Docs - You should be able to pick the bones out of it when you couple it along with the rest
                    https://github.com/aded/betfair/blob/master/auth.go
                    Ive sorted all the Request String stuff now btw Thanks
                    Cheers
                    Dave
                    Last edited by davecon; 23-01-2014, 09:36 AM. Reason: Ooops Forgot

                    Comment

                    • davecon
                      Junior Member
                      • Dec 2010
                      • 86

                      #11
                      Hi Troy
                      Dont think that would work although we can open up multiple Sub Accounts I dont think your Gov would even let you do that!
                      I am intrigued though - Are you sure this is not just a "Grey Area" because although we use the term "In Running" that is not really practical as there is a 1 Sec Delay in Horse Racing and 5 Sec for the rest - Normal use is for Example placing "In Play" Bets such as A $10 Win at Odds of Say 20's if it hits this Price in Running as a crude example!
                      The API allows you to place Persistence Bets "Keep" and as we use the same API who is to stop you lol - Is it Betfair itself?
                      When you place an Unmatched bet on the Site do you get the same Options as we get --- Please see the Image Below - I have Placed an Unmatched Lay Bet on an Aussie Race and I have a "Keep" Option DO YOU??
                      Cheers
                      Dave

                      Originally posted by troyedwards8 View Post
                      Thanks mate

                      works like a dream

                      With regards to AUS live inplay betting the Aus government won't allow it (we have to phone up )

                      One day it may change. I wouldn't mind finding out whether its possible to get a uk betfair account

                      I guess I would need to live there first and then set one up.
                      Attached Files

                      Comment

                      • Trickie13
                        Junior Member
                        • Jan 2014
                        • 7

                        #12
                        The json strings for accounts are really easy:

                        {"jsonrpc": "2.0", "method": "AccountAPING/v1.0/getAccountFunds", "id": 1}
                        {"jsonrpc": "2.0", "method": "AccountAPING/v1.0/getAccountDetails", "id": 1}

                        and you just send them to the accounts endpoint instead of the betting one: https://api.betfair.com/exchange/account/json-rpc/v1. The responses are very straight forward.

                        I'm afraid I wouldn't have a scooby how to translate that guy's google code into VB, not even going to try!

                        And yes, I'm sure betfair will introduce charges for the new api - but there will no doubt also be free access which will be throttled like the previous versions, it just remains to be seen how medieval they get!

                        Regards

                        Rich

                        Comment

                        • davecon
                          Junior Member
                          • Dec 2010
                          • 86

                          #13
                          Thanks Rich
                          Cant believe its that straightforward
                          I tried all sorts of elaborate strings then put the whole thing on hold
                          Bit like you with your Keep alive at the mo hehe
                          Why they cant just show these samples in the documentation is beyond me
                          (That Includes Keep Alive and Logout of course)
                          Also add They should also make it clear whether ANY charges are in the pipeline - Throttled access is no problem
                          Calling the prices every Second is fast enough for me in any circumstance
                          Cheers mate
                          Dave
                          Last edited by davecon; 24-01-2014, 08:06 AM. Reason: Ooops

                          Comment

                          • davecon
                            Junior Member
                            • Dec 2010
                            • 86

                            #14
                            KeepAlive and LogOut

                            Hey Rich
                            Now this is doing my head in as well now - Spent hours on it!
                            The VBA Code Works perfectly for KeepAlive and Logout but why is there no "Accept" Equivalent with Net
                            Ive tried the first 2 which throw an Error then went through all the others but they just get the png returned as before
                            Code:
                             request.Headers.Add("Accept", "application/json") 'ERROR :mad:
                             request.Headers.Add(HttpRequestHeader.Accept, "application/json")'ERROR :mad:
                             request.Headers.Add(HttpRequestHeader.Allow, "application/json") 'Same png thingy
                            This is no Fixed and will put Keep Alive and Logout Code here shortly
                            Dave

                            Originally posted by Trickie13 View Post
                            The json strings for accounts are really easy:

                            I'm afraid I wouldn't have a scooby how to translate that guy's google code into VB, not even going to try!
                            Regards

                            Rich
                            Last edited by davecon; 25-01-2014, 11:17 AM. Reason: Sorted It

                            Comment

                            • Trickie13
                              Junior Member
                              • Jan 2014
                              • 7

                              #15
                              BRILLIANT Dave - I now have working KeepAlive and Logout functions and will be able to sleep at night again !

                              Comment

                              Working...
                              X