intelligent-trading-bot 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. intelligent_trading_bot-0.8.0/CHANGELOG.md +56 -0
  2. intelligent_trading_bot-0.8.0/LICENSE +19 -0
  3. intelligent_trading_bot-0.8.0/MANIFEST.in +26 -0
  4. intelligent_trading_bot-0.8.0/PKG-INFO +202 -0
  5. intelligent_trading_bot-0.8.0/README.md +159 -0
  6. intelligent_trading_bot-0.8.0/pyproject.toml +102 -0
  7. intelligent_trading_bot-0.8.0/setup.cfg +4 -0
  8. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/PKG-INFO +202 -0
  9. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/SOURCES.txt +59 -0
  10. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/dependency_links.txt +1 -0
  11. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/entry_points.txt +11 -0
  12. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/requires.txt +20 -0
  13. intelligent_trading_bot-0.8.0/src/intelligent_trading_bot.egg-info/top_level.txt +1 -0
  14. intelligent_trading_bot-0.8.0/src/itb/__init__.py +1 -0
  15. intelligent_trading_bot-0.8.0/src/itb/common/__init__.py +0 -0
  16. intelligent_trading_bot-0.8.0/src/itb/common/analyzer.py +272 -0
  17. intelligent_trading_bot-0.8.0/src/itb/common/backtesting.py +117 -0
  18. intelligent_trading_bot-0.8.0/src/itb/common/classifier_gb.py +82 -0
  19. intelligent_trading_bot-0.8.0/src/itb/common/classifier_lc.py +84 -0
  20. intelligent_trading_bot-0.8.0/src/itb/common/classifier_nn.py +161 -0
  21. intelligent_trading_bot-0.8.0/src/itb/common/classifier_svc.py +91 -0
  22. intelligent_trading_bot-0.8.0/src/itb/common/gen_features.py +700 -0
  23. intelligent_trading_bot-0.8.0/src/itb/common/gen_features_rolling_agg.py +268 -0
  24. intelligent_trading_bot-0.8.0/src/itb/common/gen_labels_highlow.py +162 -0
  25. intelligent_trading_bot-0.8.0/src/itb/common/gen_labels_topbot.py +341 -0
  26. intelligent_trading_bot-0.8.0/src/itb/common/gen_signals.py +440 -0
  27. intelligent_trading_bot-0.8.0/src/itb/common/generators.py +278 -0
  28. intelligent_trading_bot-0.8.0/src/itb/common/model_store.py +238 -0
  29. intelligent_trading_bot-0.8.0/src/itb/common/my_feature_example.py +45 -0
  30. intelligent_trading_bot-0.8.0/src/itb/common/types.py +30 -0
  31. intelligent_trading_bot-0.8.0/src/itb/common/utils.py +497 -0
  32. intelligent_trading_bot-0.8.0/src/itb/common/workflow.py +109 -0
  33. intelligent_trading_bot-0.8.0/src/itb/inputs/__init__.py +26 -0
  34. intelligent_trading_bot-0.8.0/src/itb/inputs/collector.py +147 -0
  35. intelligent_trading_bot-0.8.0/src/itb/inputs/collector_binance.py +347 -0
  36. intelligent_trading_bot-0.8.0/src/itb/inputs/collector_mt5.py +563 -0
  37. intelligent_trading_bot-0.8.0/src/itb/inputs/collector_yahoo.py +93 -0
  38. intelligent_trading_bot-0.8.0/src/itb/inputs/utils_binance.py +83 -0
  39. intelligent_trading_bot-0.8.0/src/itb/inputs/utils_mt5.py +147 -0
  40. intelligent_trading_bot-0.8.0/src/itb/outputs/__init__.py +41 -0
  41. intelligent_trading_bot-0.8.0/src/itb/outputs/notifier_diagram.py +329 -0
  42. intelligent_trading_bot-0.8.0/src/itb/outputs/notifier_scores.py +155 -0
  43. intelligent_trading_bot-0.8.0/src/itb/outputs/notifier_trades.py +247 -0
  44. intelligent_trading_bot-0.8.0/src/itb/outputs/trader_binance.py +413 -0
  45. intelligent_trading_bot-0.8.0/src/itb/outputs/trader_mt5.py +430 -0
  46. intelligent_trading_bot-0.8.0/src/itb/scripts/__init__.py +0 -0
  47. intelligent_trading_bot-0.8.0/src/itb/scripts/download.py +48 -0
  48. intelligent_trading_bot-0.8.0/src/itb/scripts/features.py +133 -0
  49. intelligent_trading_bot-0.8.0/src/itb/scripts/labels.py +138 -0
  50. intelligent_trading_bot-0.8.0/src/itb/scripts/merge.py +111 -0
  51. intelligent_trading_bot-0.8.0/src/itb/scripts/output.py +75 -0
  52. intelligent_trading_bot-0.8.0/src/itb/scripts/predict.py +182 -0
  53. intelligent_trading_bot-0.8.0/src/itb/scripts/predict_rolling.py +361 -0
  54. intelligent_trading_bot-0.8.0/src/itb/scripts/signals.py +134 -0
  55. intelligent_trading_bot-0.8.0/src/itb/scripts/simulate.py +227 -0
  56. intelligent_trading_bot-0.8.0/src/itb/scripts/train.py +147 -0
  57. intelligent_trading_bot-0.8.0/src/itb/service/App.py +234 -0
  58. intelligent_trading_bot-0.8.0/src/itb/service/server.py +286 -0
  59. intelligent_trading_bot-0.8.0/tests/__init__.py +0 -0
  60. intelligent_trading_bot-0.8.0/tests/test_label_generation.py +60 -0
  61. intelligent_trading_bot-0.8.0/tests/test_utils.py +83 -0
@@ -0,0 +1,56 @@
1
+ # Change Log
2
+
3
+ * v0.8.0 (2026-12-05)
4
+ * Specification of data windows train_size and predict_size with past and future horizons
5
+ * Two different train and predict modes
6
+ * Possibility to use models from any feature generator and not only those in the train section
7
+ * Refactor and improve managing data in the server
8
+ * Introduce a centralized model store with new structure and using it from feature generators
9
+ * Unify generators signatures used for different purposes (features, labels, train, predict, signals etc.)
10
+ * Refactor and unify data collector functions
11
+ * Refactor Analyzer by removing intermediate klines and managing directly data frame
12
+ * Refactor trained features by separating train and predict steps
13
+ * Added MT5 data collector
14
+
15
+ * v0.7.0 (2025-04-27)
16
+ * introduce a generic format for output functions like notifiers and traders
17
+ * make server and the scripts work with different frequencies rather than only 1 minute
18
+ * restructure config for ML-features making their configuration closer to normal features and normal generators
19
+ * possibility to reference arbitrary external functions as generators
20
+ * support for parquet storage format for intermediate files
21
+ * all data including features, predicted scores and signals are stored in the context and available for further processing
22
+ * Improved visualization of historic data in on-line mode by using this common data context
23
+ * refactor and improve train signals based on the new structure
24
+ * introduce a section with signal generators
25
+ * refactoring: implement aggregations and trade logic to conventional column generators
26
+
27
+ * v0.6.0 (2023-10-05)
28
+ * add visualization of previous transactions
29
+ * move algorithm configurations from source code to configuration file algorithms section
30
+ * add a feature generator based on TA-lib technical analysis library
31
+ * add configurations to feature generators instead of global parameters
32
+ * add configuration parameters to label generators
33
+ * refactor aggregation logic
34
+
35
+ * v0.5.0 (2023-03-26)
36
+ * refactor and improve signal training (grid search) by taking into account the new rule model and external config file
37
+ * introduce rules with multiple inputs (currently only two dimensional rules with two thresholds)
38
+ * introduce a new rule model with different rule type
39
+ * introduce multiple aggregation sets
40
+ * generalize the aggregation model by separating it from the rule model, refactoring the logic of score combination and other improvements
41
+ * implement a new labeling function
42
+
43
+ * v0.4.0 (2022-09-04)
44
+ * Unified specifications of data_sources, feature_sets and label_sets
45
+ * Introduce buy labels and sell labels
46
+ * Logging trade transactions and computing performance of the service
47
+ * Support for daily data frequency and Yahoo data source (only in batch mode)
48
+
49
+ * v0.3.0 (2022-07-09)
50
+
51
+ * v0.2.0 (2022-03-19)
52
+
53
+ * v0.1.0 (2021-11-01)
54
+
55
+ * v0.0.0 (2020-02-23)
56
+ * initial commit
@@ -0,0 +1,19 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # MANIFEST.in
2
+
3
+ # Required / strongly recommended
4
+ include pyproject.toml
5
+ include README.md
6
+ include LICENSE*
7
+ include CHANGELOG*
8
+ include MANIFEST.in
9
+
10
+ # Source code
11
+ graft src
12
+
13
+ # Optional but commonly included
14
+ graft tests
15
+
16
+ # Explicitly exclude
17
+ prune docs
18
+ prune notebooks
19
+ prune configs
20
+ prune .github
21
+ prune .venv
22
+ prune dist
23
+ prune build
24
+ prune *.egg-info
25
+
26
+ global-exclude *.py[cod] __pycache__ *.so .DS_Store
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: intelligent-trading-bot
3
+ Version: 0.8.0
4
+ Summary: Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering
5
+ Author-email: Alexandr Savinov <savinov@conceptoriented.org>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/asavinov/intelligent-trading-bot
8
+ Project-URL: Repository, https://github.com/asavinov/intelligent-trading-bot
9
+ Project-URL: Documentation, https://asavinov.github.io/intelligent-trading-bot
10
+ Project-URL: Bug Tracker, https://github.com/asavinov/intelligent-trading-bot/issues
11
+ Keywords: machine-learning,crypto,bitcoin,trading,artificial-intelligence,cryptocurrency,feature-engineering,algorithmic-trading,crypto-trading,trading-bots
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: Science/Research
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Software Development
21
+ Requires-Python: >=3.12
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: apscheduler
25
+ Requires-Dist: click
26
+ Requires-Dist: tqdm
27
+ Requires-Dist: numpy==2.*
28
+ Requires-Dist: pandas==3.*
29
+ Requires-Dist: pyarrow==25.*
30
+ Requires-Dist: python-binance
31
+ Requires-Dist: numba
32
+ Requires-Dist: ta-lib
33
+ Requires-Dist: scikit-learn
34
+ Requires-Dist: lightgbm
35
+ Requires-Dist: tensorflow
36
+ Requires-Dist: keras
37
+ Provides-Extra: docs
38
+ Requires-Dist: mkdocs>=1.6; extra == "docs"
39
+ Requires-Dist: mkdocs-material>=9.5; extra == "docs"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=9.0; extra == "dev"
42
+ Dynamic: license-file
43
+
44
+ ```
45
+ ___ _ _ _ _ _ _____ _ _ ____ _
46
+ |_ _|_ __ | |_ ___| | (_) __ _ ___ _ __ | |_ |_ _| __ __ _ __| (_)_ __ __ _ | __ ) ___ | |_
47
+ | || '_ \| __/ _ \ | | |/ _` |/ _ \ '_ \| __| | || '__/ _` |/ _` | | '_ \ / _` | | _ \ / _ \| __|
48
+ | || | | | || __/ | | | (_| | __/ | | | |_ | || | | (_| | (_| | | | | | (_| | | |_) | (_) | |_
49
+ |___|_| |_|\__\___|_|_|_|\__, |\___|_| |_|\__| |_||_| \__,_|\__,_|_|_| |_|\__, | |____/ \___/ \__|
50
+ |___/ |___/
51
+ ₿ Ξ ₳ ₮ ✕ ◎ ● Ð Ł Ƀ Ⱥ ∞ ξ ◈ ꜩ ɱ ε ɨ Ɓ Μ Đ ⓩ Ο Ӿ Ɍ ȿ
52
+ ```
53
+
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/asavinov/prosto/blob/master/LICENSE)
55
+ [![PyPI](https://img.shields.io/pypi/v/intelligent-trading-bot)](https://pypi.python.org/pypi/intelligent-trading-bot)
56
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/intelligent-trading-bot)](https://github.com/asavinov/intelligent-trading-bot)
57
+ [![Tests](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/tests.yml/badge.svg)](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/tests.yml)
58
+ [![Docs](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/docs.yml/badge.svg)](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/docs.yml)
59
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://asavinov.github.io/intelligent-trading-bot/)
60
+
61
+ > [![https://t.me/intelligent_trading_signals](https://img.shields.io/badge/Telegram-2CA5E0?logo=telegram&style=for-the-badge&logoColor=white)](https://t.me/intelligent_trading_signals) 📈 **<span style="font-size:1.5em;">[Intelligent Trading Signals](https://t.me/intelligent_trading_signals)</span>** 📉 **<https://t.me/intelligent_trading_signals>**
62
+
63
+ # Intelligent trading bot
64
+
65
+ The aim of the project is to develop a generic forecasting framework that combines machine learning (ML) and feature engineering (FE). It can be applied to almost any kind of time-series and domain including crypto-currencies, classical stock markets, trading futures, energy markets and so on. It is important only that enough historic data is available to train ML models (like ARIMA or neural networks) and domain-knowledge is encoded in custom features using feature engineering (similar to moving averages but taking into account specifics of the problem domain).
66
+
67
+ The project provides the following major functionalities:
68
+
69
+ - Principled separation between *two modes*: *Offline* (or batch) and *Online* (or stream). The challange is to avoid duplication of artifacts by defining the elements only one time and, on the other hand, ensuring the correct and consistent behavior when switching the modes.
70
+
71
+ - *Offline* mode is intended for automatically extracting knowledge from historic data, particularly for training ML models or determining statistical parameters
72
+
73
+ - *Online* mode is intended for making forecasts based on the knowledge (models) extracted from historic data as well as (expert) knowledge encoded in domain-specific features via feature engineering
74
+
75
+ - *Extensible design* that provides an easy way to define and use *derived features* via (Python) functions. This includes both standard technical indicators and arbitrary [custom features](docs/features.md). Features can be encoded and parameterized by both expert domain-specific knowledge and knowledge extracted from historic data. The feature-engineering layer relies on the [column-oriented approach](docs/column-oriented-design.md), where new features are defined in terms of previously defined features, so that all features form a directed acyclic graph (DAG) of definitions
76
+
77
+ - Support for different *trade frequencies* (time rasters or sample rates). For example, it is possible to develop a trading bot for 1 minute analysis, 1 hour analysis, or daily analysis.
78
+
79
+ - Integration with the external environment through input and output adapters:
80
+ - *Input* data is provided via custom data collectors that fetch data from an external data source in online mode or download historic data in offline mode
81
+ - *Output* results are sent to consumers via custom functions that send forecasts (such as signals or predictions in online mode) to external consumers, for example Telegram channels, API endpoints, databases, or systems that execute real transactions
82
+
83
+ - [Scripts](docs/scripts.md) for *backtesting* and measuring trade performance on historic data. In particular, walk-forward prediction can be performed by regularly re-training ML models and hence changing the behavior of the system.
84
+
85
+ - A *[trading service](docs/server.md)* for online mode that uses a [configuration file](docs/configuration.md) to regularly retrieve data updates, perform analysis, and send signals or execute trade transactions
86
+
87
+ # Intelligent trading signals
88
+
89
+ It is a cloud signaling service demonstrating how this project can be used. It regulary sends its signals to this Telegram channel:
90
+
91
+ 📈 **[Intelligent Trading Signals](https://t.me/intelligent_trading_signals)** 📉 **<https://t.me/intelligent_trading_signals>**
92
+
93
+ Everybody can subscribe to the channel to get the impression about how this project can be used.
94
+
95
+ Currently, the bot is configured using the following parameters:
96
+ * Exchange: Binance
97
+ * Cryptocurrency: ₿ Bitcoin (BTCUSDT)
98
+ * Analysis frequency: 1 minute
99
+ * Intelligent indicator between -1 and +1. Negative values mean decrease, and positive values mean increase of the price
100
+
101
+ Example notification:
102
+
103
+ > ₿ 24.518 📉📉📉 Score: -0.26
104
+
105
+ 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.
106
+
107
+ If the intelligent indicator exceeds some threshold specified in the model then buy or sell signal is generated:
108
+
109
+ > 〉〉〉📈 ₿ 74,896 Indicator: +0.12 ↑ BUY ZONE 1min
110
+
111
+ Here three arrows mean buy signal for bitcoin at the current price 74,896 and the indicator value 0.12. `1min` frequence (analysis every minute). Such messages can be customized using Python functions including diagrams.
112
+
113
+ # Training machine learning models (offline)
114
+
115
+ ![Batch data processing pipeline](docs/images/fig_1.png)
116
+
117
+ 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.
118
+
119
+ If everything is configured, then the following scripts have to be executed:
120
+ * `python -m itb.scripts.download -c config.json`
121
+ * `python -m itb.scripts.merge -c config.json`
122
+ * `python -m itb.scripts.features -c config.json`
123
+ * `python -m itb.scripts.labels -c config.json`
124
+ * `python -m itb.scripts.train -c config.json`
125
+ * `python -m itb.scripts.predict -c config.json`
126
+ * `python -m itb.scripts.signals -c config.json`
127
+ * `python -m itb.scripts.output -c config.json`
128
+
129
+ All necessary parameters are provided in the configuration file. The project provides some sample configuration files in the `configs` folder.
130
+
131
+ Some common parameters of the configuration file:
132
+ * `data_folder` - location of data files which are needed only for batch offline mode
133
+ * `symbol` it is a trading pair like `BTCUSDT`
134
+ * `description` Any text helping understand the purpose of this configuration file
135
+ * `freq` data frequency according to `pandas` conventions
136
+
137
+ ## Download data
138
+
139
+ This batch script will download historic data from one or more data sources and store them in separate files. The data sources are listed in the `data_sources` section. 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. Currently data sources are not extendable and it is possible only to download from Binance and Yahoo.
140
+
141
+ ## Merging source data
142
+
143
+ The downloaded data are stored in multiple files. The system however works with only one data table therefore all these data entries (like candle lines) must be merged into one table. This is done by the `merge` script. It aligns all data entries according to their time stamp, that is, one record in the output file will merge records with the same time stamp from all input files. In addition, it will produce continuous raster in case there are gaps in the input files.
144
+
145
+ ## Generate features
146
+
147
+ This script is intended for computing derived features. These features will be added as additional columns to the data table. Feature definitions are provided in the `feature_sets` section of the configuration file. Each entry in this list specifies a *feature generator* as well as its parameters. The script loads one merged input file, applies feature generation procedures and stores all derived features in an output file.
148
+
149
+ Here are some notes on the current implementation:
150
+ * Not all generated features must be used for training and prediction. Some of them can be used as input to next features. Other feature could be used only for the feature selection process where we want to find which of them have better predictive power. For the train/predict phases, a separate explicit list of features is specified
151
+ * Currently it runs in non-incremental model by computing features for *all* available input records (and not only for the latest update), and hence it may take hours for complex configurations. Yet, in online (stream) mode, features can be computed more efficiently if it is supported by the feature generator
152
+ * Feature generation functions get additional parameters like windows from the config section
153
+ * The same features must be used in online (stream) mode (in the service when they are applied to a micro-batch) and offline mode. This is guaranteed by design
154
+
155
+ Here are some pre-defined feature generators (although it is possible to define custom feature generation functions):
156
+ * `talib` feature generator relies on the TA-lib technical analysis library. Here an example of its configuration: `"config": {"columns": ["close"], "functions": ["SMA"], "windows": [5, 10, 15]}`
157
+ * `itbstats` feature generator implements functions which can be found in tsfresh like `scipy_skew`, `scipy_kurtosis`, `lsbm` (longest strike below mean), `fmax` (first location of maximum), `mean`, `std`, `area`, `slope`. Here are typical parameters: `"config": {"columns": ["close"], "functions": ["skew", "fmax"], "windows": [5, 10, 15]}`
158
+ * `itblib` feature generator implemented in ITB but most of its features can be generated (much faster) via talib
159
+ * `tsfresh` generates functions from the tsfresh library
160
+
161
+ ## Generate labels
162
+
163
+ 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. In other words, features are computed from previous (historic) data while labels are computed from future data which are not visible in online mode yet. For example, a label could find maximum price increase during next hour in percent. Computationally it is the same as computing features but this step is separate because we do not need (and cannot compute) this in online mode. This script will apply all labels defined in the `label_sets` section, add them as new columns and store the result in the output file. Just like for features, not all labels must be really used -- they could be generated for exploratory purposes. The really used labels are listed in the `labels` section.
164
+
165
+ Here are some pre-defined label generators:
166
+ * `highlow` label generator returns True if the price is higher than the specified threshold within some future horizon
167
+ * `highlow2` Computes future increases (decreases) with the conditions that there are no significant decreases (increases) before that. Here is its typical configuration: `"config": {"columns": ["close", "high", "low"], "function": "high", "thresholds": [1.0, 1.5, 2.0], "tolerance": 0.2, "horizon": 10080, "names": ["first_high_10", "first_high_15", "first_high_20"]}`
168
+ * `topbot` Deprecated
169
+ * `topbot2` Computes maximum and minimum values (labeled as True). Every labelled maximum (minimum) is guaranteed to be surrounded by minimums (maximums) lower (higher) than the specified level. The required minimum difference between adjacent minimums and maximums is specified via `level` parameters. The tolerance parameter allows for including also points close to the maximum/minimum. Here is a typical configuration: `"config": {"columns": "close", "function": "bot", "level": 0.02, "tolerances": [0.1, 0.2], "names": ["bot2_1", "bot2_2"]}`
170
+
171
+ ## Train prediction models
172
+
173
+ This script is needed only in batch (offline) mode and its purpose is to analyze historic data and produce ML models as output files. These ML models store in a condensed form some knowledge about the time series and they are used then in online (stream) model for forecasting. More specifically, one ML model is trained to predict some label based on the generated features. When this model is applied to the latest data in online mode, it will predict the value of this label which is normally used to make some trade decision.
174
+
175
+ The parameters for the train script are specified in the `train_feature_sets` section. Currently classification and regression algorithms can be used. They can automatically scale input features if specified in the configuration. The trained models are applied to the train data set and the prediction scores are stored in this file `prediction-metrics.txt`.
176
+
177
+ ## Post-processing
178
+
179
+ After ML models were applied and some predictions were generated as new columns (in online mode), we might want to compute something else based on these predictions. It is very similar to normal feature generation with the difference that it is done after predictions. Frequently we want to aggregate the predictions generated by ML algorithms for different labels and produce one *intelligent indicator* which is supposed to be used for making trade decisions. These computations are performed according to parameters in the `signal_sets` section which has same structure as feature generators. The result is one or more new columns.
180
+
181
+ ## Output signal generation
182
+
183
+ Each previous step adds new columns to the data table with historic (in batch mode) or latest (in stream model) data table. Yet, we need to provide some functions for interacting with external systems, for example, sending messages, storing signals in the database or executing real transactions (buying or selling some assets). How it is done is configured in the `output_sets`. Each entry in this list specifies a function which is supposed to do some interaction with an external system. For example, the generator `score_notification_model` will send a message to the configured Telegram channel.
184
+
185
+ ## Backtesting
186
+
187
+ When training ML models we need to find the best hyper-parameters. This is done in some traditional ways and is not explicitly supported by this framework. Yet, even if we find good hyper-parameters this does not guarantee that our trade performance will be good. The ultimate criterion for choosing among various features, labels, ML algorithms and their hyper-parameters is trade performance. Computing real (or close to real) trade performance is supported by the following two scripts working with historic data and helping to estimate trade performance of the whole pipeline.
188
+
189
+ The `predict_rolling` script applies prediction to some data (similar to the `predict` script) but does it by regularly re-training ML models. This makes the predictions much more realistic because the models are applied to unseen data only (data which is was not used for training) but the models are regularly re-trained after enough new data was collected. It is precisely what is done in real system but this script applies this to historic data. The scripts implements rolling walk-forward splits by training the models for each using previous data and applying them for predicting the next predict interval.
190
+
191
+ The `simulate` script applies some (pre-defined) logic of trading to historic data which includes all data expected in online mode. Essentially, it scans the historic data by applying the trade rules and produces buy-sell transactions which are then aggregated.
192
+
193
+ # Online service
194
+
195
+ This script starts a service: `python -m service.server -c config.json`
196
+
197
+ The service will periodically (for example, every minute) execute these tasks:
198
+ * Retrieve the latest data from the server and update the current data window which includes some history (the history length is defined by a configuration parameter)
199
+ * Compute derived features based on the nearest history collected (which now includes the latest data). The features to be computed are described in the configuration file and are exactly the same as used in batch mode during model training
200
+ * Apply several (previously trained) ML models by predicting values of the labels which are also treated as (more complex) derived features. Trained models are loaded from the `MODELS` folder specified in the configuration file
201
+ * Aggregate the results of forecasting produced by different ML models and compute the final signal score which reflects the strength of the upward or downward trend. Here we use many previously computed scores as inputs and derive one output score.
202
+ * Execute functions for interacting with external systems, for example, by sending notifications to a Telegram channel. It is also possible to configure a real trader which will execute buy or sell transactions
@@ -0,0 +1,159 @@
1
+ ```
2
+ ___ _ _ _ _ _ _____ _ _ ____ _
3
+ |_ _|_ __ | |_ ___| | (_) __ _ ___ _ __ | |_ |_ _| __ __ _ __| (_)_ __ __ _ | __ ) ___ | |_
4
+ | || '_ \| __/ _ \ | | |/ _` |/ _ \ '_ \| __| | || '__/ _` |/ _` | | '_ \ / _` | | _ \ / _ \| __|
5
+ | || | | | || __/ | | | (_| | __/ | | | |_ | || | | (_| | (_| | | | | | (_| | | |_) | (_) | |_
6
+ |___|_| |_|\__\___|_|_|_|\__, |\___|_| |_|\__| |_||_| \__,_|\__,_|_|_| |_|\__, | |____/ \___/ \__|
7
+ |___/ |___/
8
+ ₿ Ξ ₳ ₮ ✕ ◎ ● Ð Ł Ƀ Ⱥ ∞ ξ ◈ ꜩ ɱ ε ɨ Ɓ Μ Đ ⓩ Ο Ӿ Ɍ ȿ
9
+ ```
10
+
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/asavinov/prosto/blob/master/LICENSE)
12
+ [![PyPI](https://img.shields.io/pypi/v/intelligent-trading-bot)](https://pypi.python.org/pypi/intelligent-trading-bot)
13
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/intelligent-trading-bot)](https://github.com/asavinov/intelligent-trading-bot)
14
+ [![Tests](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/tests.yml/badge.svg)](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/tests.yml)
15
+ [![Docs](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/docs.yml/badge.svg)](https://github.com/asavinov/intelligent-trading-bot/actions/workflows/docs.yml)
16
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://asavinov.github.io/intelligent-trading-bot/)
17
+
18
+ > [![https://t.me/intelligent_trading_signals](https://img.shields.io/badge/Telegram-2CA5E0?logo=telegram&style=for-the-badge&logoColor=white)](https://t.me/intelligent_trading_signals) 📈 **<span style="font-size:1.5em;">[Intelligent Trading Signals](https://t.me/intelligent_trading_signals)</span>** 📉 **<https://t.me/intelligent_trading_signals>**
19
+
20
+ # Intelligent trading bot
21
+
22
+ The aim of the project is to develop a generic forecasting framework that combines machine learning (ML) and feature engineering (FE). It can be applied to almost any kind of time-series and domain including crypto-currencies, classical stock markets, trading futures, energy markets and so on. It is important only that enough historic data is available to train ML models (like ARIMA or neural networks) and domain-knowledge is encoded in custom features using feature engineering (similar to moving averages but taking into account specifics of the problem domain).
23
+
24
+ The project provides the following major functionalities:
25
+
26
+ - Principled separation between *two modes*: *Offline* (or batch) and *Online* (or stream). The challange is to avoid duplication of artifacts by defining the elements only one time and, on the other hand, ensuring the correct and consistent behavior when switching the modes.
27
+
28
+ - *Offline* mode is intended for automatically extracting knowledge from historic data, particularly for training ML models or determining statistical parameters
29
+
30
+ - *Online* mode is intended for making forecasts based on the knowledge (models) extracted from historic data as well as (expert) knowledge encoded in domain-specific features via feature engineering
31
+
32
+ - *Extensible design* that provides an easy way to define and use *derived features* via (Python) functions. This includes both standard technical indicators and arbitrary [custom features](docs/features.md). Features can be encoded and parameterized by both expert domain-specific knowledge and knowledge extracted from historic data. The feature-engineering layer relies on the [column-oriented approach](docs/column-oriented-design.md), where new features are defined in terms of previously defined features, so that all features form a directed acyclic graph (DAG) of definitions
33
+
34
+ - Support for different *trade frequencies* (time rasters or sample rates). For example, it is possible to develop a trading bot for 1 minute analysis, 1 hour analysis, or daily analysis.
35
+
36
+ - Integration with the external environment through input and output adapters:
37
+ - *Input* data is provided via custom data collectors that fetch data from an external data source in online mode or download historic data in offline mode
38
+ - *Output* results are sent to consumers via custom functions that send forecasts (such as signals or predictions in online mode) to external consumers, for example Telegram channels, API endpoints, databases, or systems that execute real transactions
39
+
40
+ - [Scripts](docs/scripts.md) for *backtesting* and measuring trade performance on historic data. In particular, walk-forward prediction can be performed by regularly re-training ML models and hence changing the behavior of the system.
41
+
42
+ - A *[trading service](docs/server.md)* for online mode that uses a [configuration file](docs/configuration.md) to regularly retrieve data updates, perform analysis, and send signals or execute trade transactions
43
+
44
+ # Intelligent trading signals
45
+
46
+ It is a cloud signaling service demonstrating how this project can be used. It regulary sends its signals to this Telegram channel:
47
+
48
+ 📈 **[Intelligent Trading Signals](https://t.me/intelligent_trading_signals)** 📉 **<https://t.me/intelligent_trading_signals>**
49
+
50
+ Everybody can subscribe to the channel to get the impression about how this project can be used.
51
+
52
+ Currently, the bot is configured using the following parameters:
53
+ * Exchange: Binance
54
+ * Cryptocurrency: ₿ Bitcoin (BTCUSDT)
55
+ * Analysis frequency: 1 minute
56
+ * Intelligent indicator between -1 and +1. Negative values mean decrease, and positive values mean increase of the price
57
+
58
+ Example notification:
59
+
60
+ > ₿ 24.518 📉📉📉 Score: -0.26
61
+
62
+ 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.
63
+
64
+ If the intelligent indicator exceeds some threshold specified in the model then buy or sell signal is generated:
65
+
66
+ > 〉〉〉📈 ₿ 74,896 Indicator: +0.12 ↑ BUY ZONE 1min
67
+
68
+ Here three arrows mean buy signal for bitcoin at the current price 74,896 and the indicator value 0.12. `1min` frequence (analysis every minute). Such messages can be customized using Python functions including diagrams.
69
+
70
+ # Training machine learning models (offline)
71
+
72
+ ![Batch data processing pipeline](docs/images/fig_1.png)
73
+
74
+ 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.
75
+
76
+ If everything is configured, then the following scripts have to be executed:
77
+ * `python -m itb.scripts.download -c config.json`
78
+ * `python -m itb.scripts.merge -c config.json`
79
+ * `python -m itb.scripts.features -c config.json`
80
+ * `python -m itb.scripts.labels -c config.json`
81
+ * `python -m itb.scripts.train -c config.json`
82
+ * `python -m itb.scripts.predict -c config.json`
83
+ * `python -m itb.scripts.signals -c config.json`
84
+ * `python -m itb.scripts.output -c config.json`
85
+
86
+ All necessary parameters are provided in the configuration file. The project provides some sample configuration files in the `configs` folder.
87
+
88
+ Some common parameters of the configuration file:
89
+ * `data_folder` - location of data files which are needed only for batch offline mode
90
+ * `symbol` it is a trading pair like `BTCUSDT`
91
+ * `description` Any text helping understand the purpose of this configuration file
92
+ * `freq` data frequency according to `pandas` conventions
93
+
94
+ ## Download data
95
+
96
+ This batch script will download historic data from one or more data sources and store them in separate files. The data sources are listed in the `data_sources` section. 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. Currently data sources are not extendable and it is possible only to download from Binance and Yahoo.
97
+
98
+ ## Merging source data
99
+
100
+ The downloaded data are stored in multiple files. The system however works with only one data table therefore all these data entries (like candle lines) must be merged into one table. This is done by the `merge` script. It aligns all data entries according to their time stamp, that is, one record in the output file will merge records with the same time stamp from all input files. In addition, it will produce continuous raster in case there are gaps in the input files.
101
+
102
+ ## Generate features
103
+
104
+ This script is intended for computing derived features. These features will be added as additional columns to the data table. Feature definitions are provided in the `feature_sets` section of the configuration file. Each entry in this list specifies a *feature generator* as well as its parameters. The script loads one merged input file, applies feature generation procedures and stores all derived features in an output file.
105
+
106
+ Here are some notes on the current implementation:
107
+ * Not all generated features must be used for training and prediction. Some of them can be used as input to next features. Other feature could be used only for the feature selection process where we want to find which of them have better predictive power. For the train/predict phases, a separate explicit list of features is specified
108
+ * Currently it runs in non-incremental model by computing features for *all* available input records (and not only for the latest update), and hence it may take hours for complex configurations. Yet, in online (stream) mode, features can be computed more efficiently if it is supported by the feature generator
109
+ * Feature generation functions get additional parameters like windows from the config section
110
+ * The same features must be used in online (stream) mode (in the service when they are applied to a micro-batch) and offline mode. This is guaranteed by design
111
+
112
+ Here are some pre-defined feature generators (although it is possible to define custom feature generation functions):
113
+ * `talib` feature generator relies on the TA-lib technical analysis library. Here an example of its configuration: `"config": {"columns": ["close"], "functions": ["SMA"], "windows": [5, 10, 15]}`
114
+ * `itbstats` feature generator implements functions which can be found in tsfresh like `scipy_skew`, `scipy_kurtosis`, `lsbm` (longest strike below mean), `fmax` (first location of maximum), `mean`, `std`, `area`, `slope`. Here are typical parameters: `"config": {"columns": ["close"], "functions": ["skew", "fmax"], "windows": [5, 10, 15]}`
115
+ * `itblib` feature generator implemented in ITB but most of its features can be generated (much faster) via talib
116
+ * `tsfresh` generates functions from the tsfresh library
117
+
118
+ ## Generate labels
119
+
120
+ 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. In other words, features are computed from previous (historic) data while labels are computed from future data which are not visible in online mode yet. For example, a label could find maximum price increase during next hour in percent. Computationally it is the same as computing features but this step is separate because we do not need (and cannot compute) this in online mode. This script will apply all labels defined in the `label_sets` section, add them as new columns and store the result in the output file. Just like for features, not all labels must be really used -- they could be generated for exploratory purposes. The really used labels are listed in the `labels` section.
121
+
122
+ Here are some pre-defined label generators:
123
+ * `highlow` label generator returns True if the price is higher than the specified threshold within some future horizon
124
+ * `highlow2` Computes future increases (decreases) with the conditions that there are no significant decreases (increases) before that. Here is its typical configuration: `"config": {"columns": ["close", "high", "low"], "function": "high", "thresholds": [1.0, 1.5, 2.0], "tolerance": 0.2, "horizon": 10080, "names": ["first_high_10", "first_high_15", "first_high_20"]}`
125
+ * `topbot` Deprecated
126
+ * `topbot2` Computes maximum and minimum values (labeled as True). Every labelled maximum (minimum) is guaranteed to be surrounded by minimums (maximums) lower (higher) than the specified level. The required minimum difference between adjacent minimums and maximums is specified via `level` parameters. The tolerance parameter allows for including also points close to the maximum/minimum. Here is a typical configuration: `"config": {"columns": "close", "function": "bot", "level": 0.02, "tolerances": [0.1, 0.2], "names": ["bot2_1", "bot2_2"]}`
127
+
128
+ ## Train prediction models
129
+
130
+ This script is needed only in batch (offline) mode and its purpose is to analyze historic data and produce ML models as output files. These ML models store in a condensed form some knowledge about the time series and they are used then in online (stream) model for forecasting. More specifically, one ML model is trained to predict some label based on the generated features. When this model is applied to the latest data in online mode, it will predict the value of this label which is normally used to make some trade decision.
131
+
132
+ The parameters for the train script are specified in the `train_feature_sets` section. Currently classification and regression algorithms can be used. They can automatically scale input features if specified in the configuration. The trained models are applied to the train data set and the prediction scores are stored in this file `prediction-metrics.txt`.
133
+
134
+ ## Post-processing
135
+
136
+ After ML models were applied and some predictions were generated as new columns (in online mode), we might want to compute something else based on these predictions. It is very similar to normal feature generation with the difference that it is done after predictions. Frequently we want to aggregate the predictions generated by ML algorithms for different labels and produce one *intelligent indicator* which is supposed to be used for making trade decisions. These computations are performed according to parameters in the `signal_sets` section which has same structure as feature generators. The result is one or more new columns.
137
+
138
+ ## Output signal generation
139
+
140
+ Each previous step adds new columns to the data table with historic (in batch mode) or latest (in stream model) data table. Yet, we need to provide some functions for interacting with external systems, for example, sending messages, storing signals in the database or executing real transactions (buying or selling some assets). How it is done is configured in the `output_sets`. Each entry in this list specifies a function which is supposed to do some interaction with an external system. For example, the generator `score_notification_model` will send a message to the configured Telegram channel.
141
+
142
+ ## Backtesting
143
+
144
+ When training ML models we need to find the best hyper-parameters. This is done in some traditional ways and is not explicitly supported by this framework. Yet, even if we find good hyper-parameters this does not guarantee that our trade performance will be good. The ultimate criterion for choosing among various features, labels, ML algorithms and their hyper-parameters is trade performance. Computing real (or close to real) trade performance is supported by the following two scripts working with historic data and helping to estimate trade performance of the whole pipeline.
145
+
146
+ The `predict_rolling` script applies prediction to some data (similar to the `predict` script) but does it by regularly re-training ML models. This makes the predictions much more realistic because the models are applied to unseen data only (data which is was not used for training) but the models are regularly re-trained after enough new data was collected. It is precisely what is done in real system but this script applies this to historic data. The scripts implements rolling walk-forward splits by training the models for each using previous data and applying them for predicting the next predict interval.
147
+
148
+ The `simulate` script applies some (pre-defined) logic of trading to historic data which includes all data expected in online mode. Essentially, it scans the historic data by applying the trade rules and produces buy-sell transactions which are then aggregated.
149
+
150
+ # Online service
151
+
152
+ This script starts a service: `python -m service.server -c config.json`
153
+
154
+ The service will periodically (for example, every minute) execute these tasks:
155
+ * Retrieve the latest data from the server and update the current data window which includes some history (the history length is defined by a configuration parameter)
156
+ * Compute derived features based on the nearest history collected (which now includes the latest data). The features to be computed are described in the configuration file and are exactly the same as used in batch mode during model training
157
+ * Apply several (previously trained) ML models by predicting values of the labels which are also treated as (more complex) derived features. Trained models are loaded from the `MODELS` folder specified in the configuration file
158
+ * Aggregate the results of forecasting produced by different ML models and compute the final signal score which reflects the strength of the upward or downward trend. Here we use many previously computed scores as inputs and derive one output score.
159
+ * Execute functions for interacting with external systems, for example, by sending notifications to a Telegram channel. It is also possible to configure a real trader which will execute buy or sell transactions
@@ -0,0 +1,102 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 80.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "intelligent-trading-bot"
7
+ version = "0.8.0"
8
+ description = "Intelligent Trading Bot: Automatically generating signals and trading based on machine learning and feature engineering"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ {name = "Alexandr Savinov", email = "savinov@conceptoriented.org"}
15
+ ]
16
+ keywords = ["machine-learning", "crypto", "bitcoin", "trading", "artificial-intelligence", "cryptocurrency", "feature-engineering", "algorithmic-trading", "crypto-trading", "trading-bots"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Operating System :: OS Independent",
23
+ "Intended Audience :: Developers",
24
+ "Intended Audience :: Science/Research",
25
+ "Topic :: Scientific/Engineering",
26
+ "Topic :: Software Development",
27
+ ]
28
+
29
+ dependencies = [
30
+ "apscheduler",
31
+ "click",
32
+ "tqdm",
33
+
34
+ "numpy==2.*",
35
+ "pandas==3.*",
36
+ "pyarrow==25.*",
37
+
38
+ "python-binance",
39
+
40
+ "numba",
41
+ "ta-lib",
42
+
43
+ "scikit-learn",
44
+ "lightgbm",
45
+ "tensorflow",
46
+ "keras",
47
+ ]
48
+
49
+ [project.optional-dependencies]
50
+ docs = [
51
+ "mkdocs>=1.6",
52
+ "mkdocs-material>=9.5",
53
+ ]
54
+ dev = [
55
+ "pytest>=9.0",
56
+ #"pytest-cov>=5.0",
57
+ #"ruff >= 0.6",
58
+ #"mypy >= 1.8",
59
+ ]
60
+
61
+ [dependency-groups]
62
+ docs = [
63
+ "mkdocs>=1.6",
64
+ "mkdocs-material>=9.5",
65
+ ]
66
+ dev = [
67
+ "pytest >= 9.0",
68
+ #"pytest-cov>=5.0",
69
+ #"ruff >= 0.6",
70
+ #"mypy >= 1.8",
71
+ ]
72
+
73
+ [project.scripts]
74
+ itb-download = "itb.scripts.download:main"
75
+ itb-merge = "itb.scripts.merge:main"
76
+ itb-features = "itb.scripts.features:main"
77
+ itb-labels = "itb.scripts.labels:main"
78
+ itb-train = "itb.scripts.train:main"
79
+ itb-predict = "itb.scripts.predict:main"
80
+ itb-predict_rolling = "itb.scripts.predict:main"
81
+ itb-signals = "itb.scripts.signals:main"
82
+ itb-output = "itb.scripts.output:main"
83
+ itb-simulate = "itb.scripts.simulate:main"
84
+
85
+ [project.urls]
86
+ Homepage = "https://github.com/asavinov/intelligent-trading-bot"
87
+ Repository = "https://github.com/asavinov/intelligent-trading-bot"
88
+ Documentation = "https://asavinov.github.io/intelligent-trading-bot"
89
+ "Bug Tracker" = "https://github.com/asavinov/intelligent-trading-bot/issues"
90
+
91
+ #[tool.setuptools]
92
+ #packages = ["common", "inputs", "outputs", "scripts", "service"]
93
+ #include-package-data = false
94
+
95
+ [tool.setuptools.packages.find]
96
+ where = ["src"]
97
+ include = ["itb*"]
98
+ #exclude = ["tests", "tests.*"]
99
+
100
+ # Optional: dynamic version from __version__ or git tag (needs setuptools-scm)
101
+ # [tool.setuptools.dynamic]
102
+ # version = {attr = "my_awesome_package.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+