|Saturday 20th January 2018|
FREE gift schemes
Betfair Bots (API-NG)
Betfair API: SSL Certs
Linux: Botting Setup
Setting up a Linux botting environment
I often get asked lots of questions about setting up a botting environment, so have written the following guide to help would-be botters get started. I make no excuses for this being Linux orientated. Getting familiar with Linux is never a bad thing and will be highly beneficial if (or when!) you decide to step up a gear and run your bots from a dedicated or VPS server. Stability is excellent, running costs are lower and security is superior to Windows. A Windows based VPS server requires more maintenance than its Linux equivalent, thus increasing rental costs to the end user. The terminal commands in this guide are aimed at Debian based systems such as Mint, Ubuntu, SolydXK, Zorin OS, etc, however you can use your package manager to achieve the same results for all versions of Linux.
Note that if copying and pasting these commands into the terminal, you cannot use the keyboard shortcut ctrl+v. Instead, you must use shift+ctrl+v OR right-click your mouse and select paste.
Unless stated otherwise, all installation commands should be issued as ROOT (admin) user. To become root user, you should start a command terminal and run the following:
suEnter your root password when prompted. While typing, you will NOT see any characters in the command window. You will now be logged in as root user of the current command terminal, until you logout or close it. To logout, run:
exitYour command terminal will now return to your standard user privileges.
Setting Up Python
All Betfair bots found on this website are developed under Python 3.2. The code is written to be backwards compatible with Python 2.7 or greater, however it is recommended that you use Python 3.2. If you do not have Python 3.2, you can install it by running:
aptitude install python3.2Bot dependencies are minimal, however you will require the Python Requests library in order for your bots to interact with the Betfair API servers over https. You can install this using:
wget https://bootstrap.pypa.io/get-pip.py python3.2 get-pip.py pip3.2 install requests
Synchronizing Your PC Clock
Betfair's API uses the UTC/GMT time standard for all date and time objects such as market start times, bet placement times, etc. When calculating times such as "how many minutes until the market starts?", you should use Python's datetime.utcnow() function which returns the current time in UTC/GMT format. In order to ensure accurate calculations, your PC clock should be synchronized with an NTP server:
aptitude install ntpNo further configuration is required as the NTP daemon will automatically run in the background. The default NTP servers are sufficient.
Running Your Betfair Bot
Before running your bot, you will need to create the SSL certificates required by Betfair for secure Login. Please follow the guide HERE. Next you will need to create an Application Key. And finally, you will need to enter your Betfair username, password and LIVE app key in either manager.py OR settings.py, depending on which version of bot you are using.
All bots available on this website have a manager.py file which is the main startup script. It basically starts an infinite loop that will load the bot and handle any errors that are raised. This allows the bot to run 24/7, until you manually stop it. The following commands should be run in a default terminal, i.e. NOT as root user. Assuming that your bot is located in a folder named "gubber_ng" in your HOME directory, the launch command is:
python3.2 gubber_ng/manager.pyPressing ctrl+c or closing the terminal will stop the bot. To leave the bot running as a background process, you can detach it from the terminal. This is useful when running the bot on a remote VPS server as you do not want the bot to stop running when the terminal is closed or you logout of the server:
python3.2 gubber_ng/manager.py &You can now close the terminal if you wish - the bot will continue running. To stop the bot when it is a background process you will need to kill the process directly:
pkill -f manager.pyThis kills ALL processes named manager.py, which is obviously a problem if you are running multiple bots. Instead, you can use the path name included in the launch command:
pkill -f gubber_ng/manager.pyAgain, this kills ALL processes matching the pattern "gubber_ng/manager.py", so you will need to choose your bot names wisely.
Modifying Your Betfair Bot
In order to edit Python code, you will need a suitable text editor or IDE. Python enforces a 'pretty' coding standard so that no matter who wrote the code, it will always have the same layout, therefore making it easy to read. Part of the standard is to use 4 spaces for indentation rather than Tabs. If you are using a plain text editor, you will need to change the settings so that it will replace tabs with 4 spaces. For a lightweight Python editor, I highly recommend Editra, which can be configured as a Python IDE. To install, you should run the following command as ROOT user:
aptitude install editraWhen modifying your bot, the only file you should edit is the main strategy file, e.g. gubbins_ng.py. You MUST NOT edit any of the python files in the "betfair" folder as this is the API library and changing it will most likely break your bot.
If you are new to Python, the Dive Into Python series are an excellent resource to get you up to speed.
©2008 - 2018 BespokeBots.com. All Rights Reserved.