This is the repository for a series of medium articles "How to create, backtest, optimize and sell a cryptocurrency trading bot":
- Part 1: "Create and backtest a trading bot"
- Part 2: "Optimize your trading bot"
- Part 3: Deploy your trading bot (coming soon)
- Part 4: Monetize your trading bot (coming soon)
Make sure that you install all the requirements of the project and download all the training data for the testing and optimization of your trading bot.
pip install -r requirements.txt
Read the medium article: "How to create and backtest your trading bot".
Use python3 download-kline.py -s BTCUSDT -i 1d -y 2021 2020 2019
to download the tutorial data.
You can use python download-kline.py
with the arguments below,
to download any data you want for your trading bot.
Argument | Explanation |
---|---|
-h | show help messages |
-s | Single symbol or multiple symbols separated by space |
-y | Single year or multiple years separated by space |
-m | Single month or multiple months separated by space |
-d | single date or multiple dates separated by space |
-startDate | Starting date to download in [YYYY-MM-DD] format |
-endDate | Ending date to download in [YYYY-MM-DD] format |
-folder | Directory to store the downloaded data |
-c | 1 to download checksum file, default 0 |
-i | single kline interval or multiple intervals separated by space |
-t | Trading type: spot, um (USD-M Futures), cm (COIN-M Futures) |
e.g download ETHUSDT BTCUSDT BNBBUSD kline of 1 week interval from year 2020, month of Feb and Dec with CHECKSUM file:
python3 download-kline.py -s ETHUSDT BTCUSDT BNBBUSD -i 1w -y 2020 -m 02 12 -c 1
e.g. download ETHUSDT kline from 2020-01-01 to 2021-02-02 to directory /Users/bob/Binance:
python3 download-kline.py -s ETHUSDT -startDate 2020-01-01 -endDate 2021-02-02 -folder '/Users/bob/Binance'
Read the medium article: "How to backtest your trading bot".
Read the medium article: coming soon.
For a production read trading bot production we use the investing algorithm framework. The trading bot uses trading data from BINANCE and also has its portfolio configured with BINANCE. If you would like to use a different broker, we recommend you to visit the documentation page of the investing algorithm framework.
For this article, two trading bots are made. One with the backtesting framework and the other with plain python.
Both have the same functionality and behavior, however in this way you can see that you can mix and match different frameworks and libraries with your trading bot.
You must provide your (Binance) Broker api key and secret key in order to have a properly functioning trading bot.
In the "main.py" file of the production trading bot folder you must replace the template values of the portfolio definition.
Replace 'API_KEY' and 'SECRET_KEY' with your keys found at Binance
app = App(
resource_directory=os.path.abspath(
os.path.join(os.path.realpath(__file__), os.pardir)
),
config={
"PORTFOLIOS": {
"PRODUCTION_PORTFOLIO": {
"API_KEY": "<YOUR_API_KEY>",
"SECRET_KEY": "<YOUR_SECRET_KEY>",
"TRADING_SYMBOL": "USDT",
"MARKET": "BINANCE",
"SQLITE": False
}
}
}
)
NOTE
The used values are dummy values.
app = App(
resource_directory=os.path.abspath(
os.path.join(os.path.realpath(__file__), os.pardir)
),
config={
"PORTFOLIOS": {
"PRODUCTION_PORTFOLIO": {
"API_KEY": "7p6voD97MqAvtSktyyJqiSHg5aRj3aPZ733rUJhU",
"SECRET_KEY": "7p6voD97MqAvtSktyyJqiSHg5aRj3aPZ733rUJhU",
"TRADING_SYMBOL": "USDT",
"MARKET": "BINANCE",
"SQLITE": False
}
}
}
)
The production ready trading bot made with the backtesting framework can be found at the location:
/production/backtesting_framework
You can start the trading bot by running:
python production/backtesting_framework/main.py
The production ready trading bot made with self-made metrics can be found at the location:
/production/base
Read the medium article: coming soon.
Parts of the code are based on https://github.com/binance/binance-public-data (MIT)
MIT