asavinov / intelligent-trading-bot

Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering
https://t.me/intelligent_trading_signals
MIT License
1.05k stars 224 forks source link
algorithmic-trading artificial-intelligence bitcoin crypto crypto-trading cryptocurrency feature-engineering machine-learning trading trading-bots
 ___       _       _ _ _                  _     _____              _ _               ____        _ 
|_ _|_ __ | |_ ___| | (_) __ _  ___ _ __ | |_  |_   _| __ __ _  __| (_)_ __   __ _  | __ )  ___ | |_
 | || '_ \| __/ _ \ | | |/ _` |/ _ \ '_ \| __|   | || '__/ _` |/ _` | | '_ \ / _` | |  _ \ / _ \| __|
 | || | | | ||  __/ | | | (_| |  __/ | | | |_    | || | | (_| | (_| | | | | | (_| | | |_) | (_) | |_ 
|___|_| |_|\__\___|_|_|_|\__, |\___|_| |_|\__|   |_||_|  \__,_|\__,_|_|_| |_|\__, | |____/ \___/ \__|
                         |___/                                               |___/                   
₿   Ξ   ₳   ₮   ✕   ◎   ●   Ð   Ł   Ƀ   Ⱥ   ∞   ξ   ◈   ꜩ   ɱ   ε   ɨ   Ɓ   Μ   Đ  ⓩ  Ο   Ӿ   Ɍ  ȿ

https://t.me/intelligent_trading_signals 📈 Intelligent Trading Signals 📉 https://t.me/intelligent_trading_signals

Intelligent trading bot

The project is aimed at developing an intelligent trading bot for automated trading cryptocurrencies using state-of-the-art machine learning (ML) algorithms and feature engineering. The project provides the following major functionalities:

Intelligent trading channel

The signaling service is running in cloud and sends its signals to this Telegram channel:

📈 Intelligent Trading Signals 📉 https://t.me/intelligent_trading_signals

Everybody can subscribe to the channel to get the impression about the signals this bot generates.

Currently, the bot is configured using the following parameters:

There are silent periods when the score in lower than the threshold and no notifications are sent to the channel. If the score is greater than the threshold, then every minute a notification is sent which looks like

₿ 24.518 📉📉📉 Score: -0.26

The first number is the latest close price. The score -0.26 means that it is very likely to see the price lower than the current close price.

If the score exceeds some threshold specified in the model then buy or sell signal is generated which means that it is a good time to do a trade. Such notifications look as follows:

🟢 BUY: ₿ 24,033 Score: +0.34

Training machine learning models (offline)

Batch data processing pipeline

For the signaler service to work, a number of ML models must be trained and the model files available for the service. All scripts run in batch mode by loading some input data and storing some output files. The batch scripts are located in the scripts module.

If everything is configured then the following scripts have to be executed:

Without a configuration file the scripts will use the default parameters which is useful for testing purposes and not intended for showing good performance. Use sample configuration files which are provided for each release like config-sample-v0.6.0.jsonc.

Downloading and merging source data

The main configuration parameter for the both scripts is a list of sources in data_sources. One entry in this list specifies a data source as well as column_prefix used to distinguish columns with the same name from different sources.

Generate features

This script is intended for computing derived features:

The list of features to be generated is configured via feature_sets list in the configuration file. How features are generated is defined by the feature generator each having some parameters specified in its config section.

Generate labels

This script is similar to feature generation because it adds new columns to the input file. However, these columns describe something that we want to predict and what is not known when executing in online mode. For example, it could be price increase in future:

The list of labels to be generated is configured via label_sets list in the configuration. One label set points to the function which generates additional columns. Their configuration is very similar to feature configurations.

Train prediction models

This script uses the specified input features and labels to train several ML models:

Configuration:

Aggregation and post-processing

The goal of this step is to aggregate the prediction scores generated by different algorithms for different labels. The result is one score which is supposed to be consumed by the signal rules on the next step. The aggregation parameters are specified in the score_aggregation section. The buy_labels and sell_labels specify input prediction scores processed by the aggregation procedure. window is the number of previous steps used for rolling aggregation and combine is a way how two score types (buy and labels) are combined into one output score.

Signal generation

The score generated by the aggregation procedure is some number and the goal of signal rules is to make the trading decisions: buy, sell or do nothing. The parameters of the signal rules are described in the trade_model.

Train signal models

This script simulates trades using many buy-sell signal parameters and then chooses the best performing signal parameters:

Prediction online based on trained models (service)

This script starts a service which periodically executes one and the same task: load latest data, generate features, make predictions, generate signals, notify subscribers:

Hyper-parameter tuning

There are two problems:

Configuration parameters

The configuration parameters are specified in two files:

Here are some most important fields (in both App.py and config.json):

See sample configuration files and comments in App.config for more details.

Signaler service

Every minute, the signaler performs the following steps to make a prediction about whether the price is likely to increase or decrease:

Notes:

Starting the service: python3 -m service.server -c config.json

Trader

The trader is working but not thoroughly debugged, particularly, not tested for stability and reliability. Therefore, it should be considered a prototype with basic functionality. It is currently integrated with the Signaler but in a better design should be a separate service.

Related projects

Backtesting

External integrations