What you do when you’re forced to stay indoors? Develop and train an AI Trading Bot and start making some real money. And I’m giving it away for free!
I spent 2020 developing and training my BITMEX AI Trading Bot algorithm I built in Python. The AI Bot uses a BITMEX demo account – for the training part, and a BITMEX live account for some real buying & selling action.
My configuration is more on the conservative side, but you can experiment with more aggressive settings and/or volatile pairs.
As you’ll see, my AI Trading Bot code is clean and well documented. I run the script 24×7 on AWS Cloud on a FreeBSD machine with minimal settings and with little to no maintenance. Of course, you can run your script on your home PC as long as you have an internet connection.
Note: You can run my AI Trading Bot on any OS (Windows, macOS, Linux, BSD) as long as Python 3.6 or newer is installed.
Now, let’s see how we can get the AI Trading Bot up and running.
IMPORTANT: During the installation, make sure to checkmark the “Install launcher for all users” and “Add Python 3.x to PATH.” This step is vital to ensuring the integration with your compiler/editor (IDE).
I personally use a compiler/editor called Pycharm (IDE) for most of my work for Python. Suppose you want to be on the same page with me, head over to Jetbrains and download Pycharm community edition for your operating system.
Go ahead and install it.
Download the AI Trading Bot
Head over to GitHub and download the BITMEX AI Trading Bot. The bot consists of two Python scripts:
bitmex_crypto_ml_stops_limits.py and model.py.
Create a new folder on your computer and extract the files in it.
Open Pycharm, go to File > Open and select the directory containing the bitmex_crypto_ml_stops_limits.py and model.py files.
Importing The Necessary Libraries
You need to import all of the libraries used in the algorithms before being able to run the AI Trading Bot. The following libraries need to be imported in order to execute the script: Pandas, JSON, Datetime, Time, Operator, Threading, Sklearn, Bitmex.
The easiest way to import these libraries into Pycharm is to follow the tutorial HERE:
Running The AI Trading Bot
Create a new project in Pycharm, create a new Python file, and pasted my code into it. Again, this is just one option to run the AI Bot, but I have found it to be the most user friendly.
Don’t run the script just yet; we’ll have to create our BITMEX API key first.
Bitmex Login Setup & API Key Generation
Head over to BITMEX and create a demo account for the Testnet client – see links below. Upon doing so, you will need to generate an API ID and API SECRET KEY through their site: go to Account Dashboard > API Keys (under Account & Preferences). Take note of your API ID and API Secret.
You will input this ID and SECRET key within the two green hashes on lines 18-19 of the script, bitmex_crypto_ml_stops_limits.py file. Notice I have left them blank for you to do so.
Testnet Demo Trading Login: https://testnet.bitmex.com
Now, let’s understand how exactly the AI Trading Bot algorithm works.
AI Bot Algorithm Primary Objective
To optimize Alpha on a portfolio of chosen client stocks using different machine learning classifiers and hyperparameters through different time frames and crypto symbols.
If you are new to AI/ML and want to know more about the model that was utilized in my algorithm, I highly recommend you to diligently read the following resources:
Essentially, this model consists of a 3 layer stacked ensemble model combined into one final master model – all outlined in the 3 links above.
I utilized this model on two other scripts I made and had great results in the past year in multiple markets for live trading purposes.
Running The BITMEX AI Bot Algorithm
Essentially, there are two scripts for the code to function. The primary script that you will run to get the algorithm is bitmex_crypto_ml_stops_limits.py
The second script, model.py, is simply the model that the first script embeds into the code to run the machine learning AI structure.
IMPORTANT: When creating a new project in Pycharm, make sure both of these scripts are saved right next to one another, in the same working directory, in order for the algorithm to function properly.
Configure The BITMEX Trading AI Bot
All configurable parameters are located in the bitmex_crypto_ml_stops_limits.py file. Notice on line 255, I have defaulted the crypto pair of choice to trade XBTUSD. Feel free to change this ticker to any other pair of desire when testing out different strategies, assuming BITMEX offers the pair you change it to.
The “10” in the line 255 refers to the number of units to trade – you can change this parameter as well.
Along with the “5m” specifies that we are trading on 5-minute bars. I wrote the code to allow this parameter to be changed as well to the other time frames BITMEX offers, which are on lines 84 – 87. The supported timeframes are 1m, 1h, or 1d.
I have seen nice success on the 5m timeframe, so I have defaulted to that for now. But as you optimize your desired strategies, obviously feel free to try different timeframes and crypto pairs.
And that is pretty much it. I have coded the algorithm in an immaculate fashion so that we are only entering one trade at a time, with a limit and target of 50 bps away from entry (line 256). You can change the target limit and stop the limit to whatever you desire as well. But for risk management purposes, we definitely will want to have some stops and limits attached to our orders as we optimize the strategy – keep this in mind!
Next Development Steps
My plans for 2021 focus on adding Technical Analysis as an Added Layer for Trade Conviction, meaning adding a technical indicators layer to the present neural network as a potential extra added layer of conviction for the trades.
In other words, in addition to the current machine learning signals, we can add Technical Analysis that must align to the signals before a trade can be taken. These technical indicators can be anything such as SMAs, Bollinger Bands, RSI, Momentum, etc.
Go ahead and play with this algorithm for a while. If you feel that there may be a powerful purpose for such a thing and you would like to contribute to the research and development, I would be happy to add such technical indicators to the machine learning framework and classification techniques for you.
Additionally, if there are other machine learning frameworks you would like to suggest, I can pursue those too. Based on experience, the one I have chosen for this particular project has shown me the most promise in numerous markets so far.
Make sure you are, of course, log into your BITMEX Testnet account before running the code and that your keys have been properly inserted on lines 18-19 of our algorithm.
Try different pairs and/or time frames. I would recommend you test each of these various combinations for at least a few weeks before jumping to conclusions based on personal experience when it comes to running such models in all types of markets.
Many times, you will notice my Alpha completely change from a week to week basis, and testing it for longer periods of time helps you best assess whether the model is showing true intrinsic promise or not.
In short, do not give up on a particular pair and time frame only after a week or two of testing it in live markets.
My BITMEX AI Trading Bot is 100% free to download, use, modify, and share. You can return this favor by simply sharing this post on your social media.
Looking forward to your feedback and continuing our AI trading journey together in 2021!