Tags
Hopefully this will be a painless step by step introduction in how to get stated programming the Betfair API-NG. Our chosen language of attack will be Python. Don’t worry if you have never written a line of Python code before, neither have I. You will need to have a little programming knowledge however eg I will assume you know what an IF statement is. We will be using and building upon some useful sample Python code accessible via the Betfair Developers forum. You might want to consider joining this forum at https://developer.betfair.com/
OK first things first, before we start worrying about OpenSSL and APP keys lets download and install Python
First be aware of what type of PC you are running, is it 32 bit or 64 bit. If you are in doubt go to start>computer>System Properties and check.
Step 1 Now you need to navigate in your web browser to http://www.python.org/download/
Step 2 Choose the appropriate download link eg for my 64 bit PC running windows 8 I chose ‘windows x86 – 64 MSI Installer’ and click
Step 3 The installer should download and appear at the bottom left of your screen, double click it to run the installation. Unless you have good reason not to, accept the default options when the installer is running, also answer ‘yes’ when asked if you want to allow it to update your computer. Click ‘finish’ when completed.
Step 4 Goto your c drive and locate the python34 folder. Take a look inside the ‘scripts’ folder, you will see a script called easy_install. We will be using that later to install one or two libraries that we need.
Step 5 We will use IDLE to develop Python programs so lets put it on the desktop. In Windows explorer go to c:\python34\Lib\idlelib. Copy the file idle.py and paste it to your desktop
Step 6 We will need a folder to store our python programs in. Create a folder in your area called pythonstuff or whatever name you prefer
Step 7 Double click on the IDLE desktop icon and the IDLE program should spring to life
Step 8 Click on the file tab in IDLE and select New file. A second window should appear.
Step 9 In the second window type in
print (“Hello World”)
Dont forget the brackets
Step 10 Now click RUN, you will be prompted to save the file, click OK and then navigate to your Pythonstuff folder and save with a file name of helloworld. Your program should run and the output will appear in the first IDLE window.
Well done you have written your first Python program. In the next blog we will move further towards getting Betfair data, placing bets etc through the new API
Goncalo said:
Hi! Excuse me my question but may I ask Why you are chosing Phyton? Why not VBA, Entrocandero, VS, or Java? I’m asking this because I’m trying myself to get started on an aplication and the main issue here is wether to choose one over the others! I’m quite decided on going to VBA/excel but still in doubt about this choice! I’m afraid of delay times and aplication responses to betfair at shortest time? Do you have any information about this is phyton better then others?
smartersig said:
Hi
No concrete reason for using Python other than I thought it would be useful to try a new language, I also tend to prefer open source stuff to Microsoft. Performance wise I have no idea whether there are issues across different vehicles. I would have preferred to use Perl as I am fluent in that language but there does not seem to be any starter code around so I plumped for Python. The blog is an attempt to save you from some of the head scratching time wasting moments that are inevitable with the poor documentation offered by Betfair
Malcolm Smith said:
Thanks ever so much for this series, Mark.
I have always wanted an excuse to look at Python considering that if it’s good enough for CCP Games then it’s good enough for me.
I appreciate what you are saying about open source code; I’ve been caught in the Microsoft trap with all of my racing stuff being written in a mixture of C++, VB, VBA and ASP and I don’t particularly wish to get caught in another snare with .Net.
Thanks again for this, I am going to look forward to the journey.
– Malc
Goncalo said:
Thanks for the answer! I, particulary have no kind of knowledge in these languages except for BASIC with Spectrum 48 (Lolol – I’m not old!!! It’s the IT that travel at speed of the light). I’m getting my spare time to watch excel/VBA youtube’s and see if I can launch some of the sheet features, but it’s hard time. I’ll follow your blog about programing carefully. I’m genuinly interested in doing something and as you said betfair blog although being very informative lacks updates to this new APN-NG and detailed step by step! Will you be able to integrate integrate in your future aplication a excel button? I hope so! @Malc I wonder as well what kind of troubles did Malc had with .Net is not reliable?? Thanks for sharing.
Malcolm Smith said:
Sorry, I didn’t make myself clear. .Net is reliable and is, for the moment, one of the major industry standards so it ought to be here for years.
The problem is that I have heavily invested in code which was written in Visual Studio 6 which came out in the era of NT4. VS6 works extremely well with NT4 and XP but if the projects are large then they don’t migrate to Win7/8 platforms.
Yes, I could migrate all 200,000+ lines of code and a whole website to got the latest .Net offering but that will take me years of work. Years that I don’t wish to spend. And my thought is that who is to know how long MS will support .Net. After all, they have told us to use VS6 as that would be here for ever and large projects don’t even load on Win7 platforms to even attempt to comple, they told us to use IE6 and Active-X controls and I have a client who is stuck because MS told us that this would last forever, then there’s other things they have told us to do and ultimately drop. And I am sick and tired of it, so when Mark suggested that we use Python then I applaud his decision because I know that, like C, it will be here in twentry or fifty years time (the latter may not concern me too much and I hope that the former will).
So, in short: .Net is reliable, Microsoft less so. I used to be a fan of their development and back end platforms now I simply detest what they are doing and what they have become.
Anyway, if you’ve done Basic then you ought to be able to get on with Python. If you’re interested in knowing a little more about VBA development then there are some examples on my somewhat ancient http://www.dragondrop.com site.
Apologies for the rant, Mark, and the apparant hijacking of the thread. I just really wanted to say “Thank you and well done”.
– malc
Goncalo said:
Malcom that was inspiring and very elucidative. Thanks for giving me your insight. I will look at other languages with diferent eyes. Not saying that I shall not look at MS and .Net ever but truly, that was helpfull.
Arthur Pitt said:
hi mate, tried following these instructions but when i boot up IDLE it just opens what it called Python 3.5 Shell. There is no RUN button. It looks like a standard copy of R (console area and hit ENTER to run code). Is this because I’ve picked up a new version of python?
smartersig said:
Did you click ‘file’ followed by ‘new’ to invoke the second window which should have the ‘run’ tab at the top.
Arthur Pitt said:
Reinstalled and followed instructions again. Got it this time. Its very possible it was just me being very stupid, yes! Apologies. Thanks for these guides they are very useful. Do you have twitter?
smartersig said:
No twitter at the moment, lifes too short 🙂