bbstrader 2.0.0__tar.gz → 2.0.2__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 (112) hide show
  1. bbstrader-2.0.2/PKG-INFO +394 -0
  2. bbstrader-2.0.2/README.md +344 -0
  3. bbstrader-2.0.2/VERSION.txt +1 -0
  4. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/__init__.py +1 -1
  5. bbstrader-2.0.2/bbstrader/api/__init__.py +96 -0
  6. bbstrader-2.0.2/bbstrader/assets/bbstrader.ico +0 -0
  7. bbstrader-2.0.2/bbstrader/assets/bbstrader.png +0 -0
  8. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/backtest.py +5 -5
  9. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/execution.py +2 -9
  10. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/strategy.py +5 -1
  11. bbstrader-2.0.2/bbstrader/core/__init__.py +27 -0
  12. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/core/strategy.py +6 -7
  13. bbstrader-2.0.2/bbstrader/metatrader/__init__.py +48 -0
  14. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/trade.py +7 -4
  15. bbstrader-2.0.2/bbstrader/models/__init__.py +39 -0
  16. bbstrader-2.0.2/bbstrader/trading/__init__.py +33 -0
  17. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/trading/execution.py +7 -7
  18. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/trading/strategy.py +4 -0
  19. {bbstrader-2.0.0 → bbstrader-2.0.2}/cmake/Helpers.cmake +1 -1
  20. bbstrader-2.0.2/docs/bbstrader.api.rst +23 -0
  21. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/bbstrader.btengine.rst +1 -10
  22. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/bbstrader.core.rst +3 -11
  23. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/bbstrader.metatrader.rst +3 -11
  24. bbstrader-2.0.2/docs/bbstrader.models.rst +31 -0
  25. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/bbstrader.rst +4 -5
  26. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/bbstrader.trading.rst +4 -12
  27. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/conf.py +17 -16
  28. bbstrader-2.0.2/docs/index.rst +14 -0
  29. {bbstrader-2.0.0 → bbstrader-2.0.2}/pyproject.toml +2 -2
  30. {bbstrader-2.0.0 → bbstrader-2.0.2}/src/metatrader.cpp +4 -2
  31. bbstrader-2.0.2/tcopier.spec +59 -0
  32. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/api/test_metatrader_client.py +1 -1
  33. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/test_execution.py +4 -0
  34. bbstrader-2.0.0/CHANGELOG.md +0 -67
  35. bbstrader-2.0.0/PKG-INFO +0 -234
  36. bbstrader-2.0.0/README.md +0 -184
  37. bbstrader-2.0.0/VERSION.txt +0 -1
  38. bbstrader-2.0.0/assets/backtest_results.jpg +0 -0
  39. bbstrader-2.0.0/assets/bbstrader.ico +0 -0
  40. bbstrader-2.0.0/assets/bbstrader.png +0 -0
  41. bbstrader-2.0.0/assets/bbstrader_logo.png +0 -0
  42. bbstrader-2.0.0/assets/qs_metrics_2.png +0 -0
  43. bbstrader-2.0.0/assets/qs_plots_1_.png +0 -0
  44. bbstrader-2.0.0/assets/qs_plots_2_.png +0 -0
  45. bbstrader-2.0.0/bbstrader/api/__init__.py +0 -63
  46. bbstrader-2.0.0/bbstrader/core/__init__.py +0 -1
  47. bbstrader-2.0.0/bbstrader/metatrader/__init__.py +0 -7
  48. bbstrader-2.0.0/bbstrader/models/__init__.py +0 -7
  49. bbstrader-2.0.0/bbstrader/trading/__init__.py +0 -11
  50. bbstrader-2.0.0/docs/bbstrader.models.rst +0 -64
  51. bbstrader-2.0.0/docs/index.rst +0 -485
  52. {bbstrader-2.0.0 → bbstrader-2.0.2}/.clang-format +0 -0
  53. {bbstrader-2.0.0 → bbstrader-2.0.2}/.clang-tidy +0 -0
  54. {bbstrader-2.0.0 → bbstrader-2.0.2}/.github/workflows/cpp_linux.yml +0 -0
  55. {bbstrader-2.0.0 → bbstrader-2.0.2}/.github/workflows/cpp_macos.yml +0 -0
  56. {bbstrader-2.0.0 → bbstrader-2.0.2}/.github/workflows/cpp_win.yml +0 -0
  57. {bbstrader-2.0.0 → bbstrader-2.0.2}/.github/workflows/python.yml +0 -0
  58. {bbstrader-2.0.0 → bbstrader-2.0.2}/.gitignore +0 -0
  59. {bbstrader-2.0.0 → bbstrader-2.0.2}/.readthedocs.yaml +0 -0
  60. {bbstrader-2.0.0 → bbstrader-2.0.2}/CMakeLists.txt +0 -0
  61. {bbstrader-2.0.0 → bbstrader-2.0.2}/LICENSE +0 -0
  62. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/__main__.py +0 -0
  63. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/api/handlers.py +0 -0
  64. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/api/metatrader_client.pyi +0 -0
  65. {bbstrader-2.0.0 → bbstrader-2.0.2/bbstrader}/assets/bbs_.png +0 -0
  66. {bbstrader-2.0.0 → bbstrader-2.0.2/bbstrader}/assets/qs_metrics_1.png +0 -0
  67. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/__init__.py +0 -0
  68. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/data.py +0 -0
  69. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/event.py +0 -0
  70. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/performance.py +0 -0
  71. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/btengine/portfolio.py +0 -0
  72. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/compat.py +0 -0
  73. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/config.py +0 -0
  74. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/core/data.py +0 -0
  75. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/_copier.py +0 -0
  76. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/account.py +0 -0
  77. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/broker.py +0 -0
  78. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/copier.py +0 -0
  79. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/rates.py +0 -0
  80. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/risk.py +0 -0
  81. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/metatrader/utils.py +0 -0
  82. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/models/nlp.py +0 -0
  83. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/models/optimization.py +0 -0
  84. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/scripts.py +0 -0
  85. {bbstrader-2.0.0 → bbstrader-2.0.2}/bbstrader/trading/utils.py +0 -0
  86. {bbstrader-2.0.0 → bbstrader-2.0.2}/cmake/Versions.cmake +0 -0
  87. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/Doxyfile.in +0 -0
  88. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/Makefile +0 -0
  89. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/make.bat +0 -0
  90. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/modules.rst +0 -0
  91. {bbstrader-2.0.0 → bbstrader-2.0.2}/docs/requirements.txt +0 -0
  92. {bbstrader-2.0.0 → bbstrader-2.0.2}/examples/strategies.py +0 -0
  93. {bbstrader-2.0.0 → bbstrader-2.0.2}/include/bbstrader/metatrader.hpp +0 -0
  94. {bbstrader-2.0.0 → bbstrader-2.0.2}/include/bbstrader/objects.hpp +0 -0
  95. {bbstrader-2.0.0 → bbstrader-2.0.2}/src/CMakeLists.txt +0 -0
  96. {bbstrader-2.0.0 → bbstrader-2.0.2}/src/bbstrader.cpp +0 -0
  97. {bbstrader-2.0.0 → bbstrader-2.0.2}/src/cmake/BbstraderConfig.cmake.in +0 -0
  98. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/CMakeLists.txt +0 -0
  99. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/__init__.py +0 -0
  100. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/api/__init__.py +0 -0
  101. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/__init__.py +0 -0
  102. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/test_backtest.py +0 -0
  103. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/test_data.py +0 -0
  104. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/test_events.py +0 -0
  105. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/btengine/test_portfolio.py +0 -0
  106. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/cpp/test_metatrader_client.cpp +0 -0
  107. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/metatrader/__init__.py +0 -0
  108. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/metatrader/test_account.py +0 -0
  109. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/metatrader/test_rates.py +0 -0
  110. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/metatrader/test_risk_management.py +0 -0
  111. {bbstrader-2.0.0 → bbstrader-2.0.2}/tests/metatrader/test_trade.py +0 -0
  112. {bbstrader-2.0.0 → bbstrader-2.0.2}/vcpkg.json +0 -0
@@ -0,0 +1,394 @@
1
+ Metadata-Version: 2.4
2
+ Name: bbstrader
3
+ Version: 2.0.2
4
+ Summary: Simplified Investment & Trading Toolkit with Python & C++
5
+ Keywords: Finance,Toolkit,Financial,Analysis,Fundamental,Quantitative,Database,Equities,Currencies,Economics,ETFs,Funds,Indices,Moneymarkets,Commodities,Futures,CFDs,Derivatives,Trading,Investing,Portfolio,Optimization,Performance
6
+ Author-Email: Bertin Balouki SIMYELI <bertin@bbs-trading.com>
7
+ Maintainer-Email: Bertin Balouki SIMYELI <bertin@bbs-trading.com>
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Office/Business :: Financial :: Investment
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: MacOS
16
+ Project-URL: Homepage, https://github.com/bbalouki/bbstrader
17
+ Project-URL: Download, https://pypi.org/project/bbstrader/
18
+ Project-URL: Documentation, https://bbstrader.readthedocs.io/en/latest/
19
+ Project-URL: Source Code, https://github.com/bbalouki/bbstrader
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: beautifulsoup4>=4.13.5
22
+ Requires-Dist: colorama>=0.4.6
23
+ Requires-Dist: dash>=3.2.0
24
+ Requires-Dist: eodhd>=1.0.32
25
+ Requires-Dist: exchange_calendars>=4.11.1
26
+ Requires-Dist: financetoolkit>=2.0.4
27
+ Requires-Dist: ipython>=9.5.0
28
+ Requires-Dist: nltk>=3.9.1
29
+ Requires-Dist: notify_py>=0.3.43
30
+ Requires-Dist: numpy>=2.2.6
31
+ Requires-Dist: praw>=7.8.1
32
+ Requires-Dist: pybind11>=3.0.1
33
+ Requires-Dist: pyfiglet>=1.0.4
34
+ Requires-Dist: pyportfolioopt>=1.5.6
35
+ Requires-Dist: python-dotenv>=1.1.1
36
+ Requires-Dist: python-telegram-bot>=22.3
37
+ Requires-Dist: PyYAML>=6.0.2
38
+ Requires-Dist: QuantStats>=0.0.77
39
+ Requires-Dist: seaborn>=0.13.2
40
+ Requires-Dist: spacy>=3.8.11
41
+ Requires-Dist: sumy>=0.11.0
42
+ Requires-Dist: tabulate>=0.9.0
43
+ Requires-Dist: textblob>=0.19.0
44
+ Requires-Dist: tweepy>=4.16.0
45
+ Requires-Dist: vaderSentiment>=3.3.2
46
+ Requires-Dist: yfinance>=0.2.65
47
+ Provides-Extra: mt5
48
+ Requires-Dist: MetaTrader5; extra == "mt5"
49
+ Description-Content-Type: text/markdown
50
+
51
+ # Simplified Investment & Trading Toolkit with Python & C++
52
+
53
+ [![Documentation Status](https://readthedocs.org/projects/bbstrader/badge/?version=latest)](https://bbstrader.readthedocs.io/en/latest/?badge=latest)
54
+ [![PYPI Version](https://img.shields.io/pypi/v/bbstrader)](https://pypi.org/project/bbstrader/)
55
+ [![PyPi status](https://img.shields.io/pypi/status/bbstrader.svg?maxAge=60)](https://pypi.python.org/pypi/bbstrader)
56
+ [![Supported Python Versions](https://img.shields.io/pypi/pyversions/bbstrader)](https://pypi.org/project/bbstrader/)
57
+ [![Linux](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_linux.yml/badge.svg)](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_linux.yml)
58
+ [![macOS](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_macos.yml/badge.svg)](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_macos.yml)
59
+ [![Windows](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_win.yml/badge.svg)](https://github.com/bbalouki/bbstrader/actions/workflows/cpp_win.yml)
60
+ [![C++20](https://img.shields.io/badge/C++-20-blue.svg)](https://isocpp.org/std/the-standard)
61
+ [![CMake](https://img.shields.io/badge/CMake-3.20+-blue.svg)](https://cmake.org/)
62
+ [![PyPI Downloads](https://static.pepy.tech/badge/bbstrader)](https://pepy.tech/projects/bbstrader)
63
+ [![CodeFactor](https://www.codefactor.io/repository/github/bbalouki/bbstrader/badge)](https://www.codefactor.io/repository/github/bbalouki/bbstrader)
64
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-grey?logo=Linkedin&logoColor=white)](https://www.linkedin.com/in/bertin-balouki-s-15b17a1a6)
65
+
66
+ ## Welcome to `bbstrader` – The Ultimate C++ & Python Trading Powerhouse!
67
+
68
+ ## Table of Contents
69
+
70
+ - [Overview](#overview)
71
+ - [Why `bbstrader` Stands Out](#why-bbstrader-stands-out)
72
+ - [Trusted by Traders Worldwide](#trusted-by-traders-worldwide)
73
+ - [The `bbstrader` Edge: Uniting C++ Speed with Python Flexibility](#the-bbstrader-edge-uniting-c-speed-with-python-flexibility)
74
+ - [Overcoming the MQL5 Bottleneck](#overcoming-the-mql5-bottleneck)
75
+ - [Key Modules](#key-modules)
76
+ - [1. `btengine`: Event-Driven Backtesting Beast](#1-btengine-event-driven-backtesting-beast)
77
+ - [2. `metatrader`: The C++/Python Bridge to MT5](#2-metatrader-the-cpython-bridge-to-mt5)
78
+ - [Pattern 1: C++ Core, Python Orchestrator (Maximum Performance)](#pattern-1-c-core-python-orchestrator-maximum-performance)
79
+ - [Pattern 2: Python-Driven with C++ Acceleration](#pattern-2-python-driven-with-c-acceleration)
80
+ - [3. `trading`: Live Execution & Strategy Orchestrator](#3-trading-live-execution--strategy-orchestrator)
81
+ - [4. `models`: Quant Toolkit for Signals & Risk](#4-models-quant-toolkit-for-signals--risk)
82
+ - [Getting Started](#getting-started)
83
+ - [Prerequisites](#prerequisites)
84
+ - [Installation](#installation)
85
+ - [For the Python Quant](#for-the-python-quant)
86
+ - [For the C++ Developer](#for-the-c-developer)
87
+ - [CLI workflow](#cli-workflow)
88
+ - [Community & Support](#-community--support)
89
+ - [Professional Services](#professional-services)
90
+
91
+ ### Overview
92
+
93
+ Imagine having the raw, blistering speed of C++ for your high-frequency trades, combined with Python's ecosystem for lightning-fast prototyping, advanced AI models, and seamless data analysis. That's `bbstrader` – not just a library, but a game-changing toolkit designed for quants, algo traders, and institutional pros who demand an edge in volatile markets. Whether you're scalping forex pairs, backtesting complex strategies, or copying trades across accounts in real-time, `bbstrader` empowers you to build, test, and deploy with unmatched efficiency.
94
+
95
+ Forget the frustrations of slow Python bottlenecks or MQL5's rigid sandbox. `bbstrader` bridges worlds: C++ for mission-critical performance and Python for intelligent orchestration. It's open-source, battle-tested across platforms, and ready to supercharge your trading arsenal.
96
+
97
+ ## **Why `bbstrader` Stands Out**
98
+
99
+ In a crowded field of trading libraries, `bbstrader` is architected to solve the most challenging problems in algorithmic trading: performance, flexibility, and platform limitations.
100
+
101
+ - **Blazing Speed with C++ Core**: Compile your strategy logic in native C++ for deterministic, low-latency execution. Perfect for HFT, arbitrage, or compute-heavy models that Python alone can't handle.
102
+ - **Python's Powerhouse Ecosystem**: Leverage `NumPy`, `pandas`, `scikit-learn`, `TensorFlow`, and more for research, ML-driven signals, and backtesting – all seamlessly integrated with your C++ core.
103
+ - **Institutional-Grade Architecture:** From its event-driven backtester to its modular design, `bbstrader` is built with the principles of professional trading systems in mind, providing a robust foundation for serious strategy development.
104
+ In today's hyper-fast financial landscape, every microsecond counts. `bbstrader` isn't another lightweight wrapper – it's an institutional-grade powerhouse engineered to tackle real-world trading challenges head-on.
105
+ - **Break Free from MQL5 Limits**: Ditch interpreted code and ecosystem constraints. Build multi-threaded, AI-infused strategies that execute orders in microseconds via MetaTrader 5 (MT5) integration.
106
+ **Flexible Interface**: CLI & GUI
107
+ `bbstrader` adapts to your workflow.
108
+ - **Automation Fanatics**: Use the CLI for headless scripts, cron jobs, and server deployments.
109
+ - **Visual Traders**: Launch the Desktop GUI (currently for Copy Trading) to monitor your master and slave accounts, check replication status, and manage connections visually.
110
+ - **Cross-Platform & Future-Proof**: Works on Windows, macOS, Linux. (IBKR integration in development).
111
+
112
+ ## **Trusted by Traders Worldwide**
113
+
114
+ With thousands of downloads, `bbstrader` is trusted by traders worldwide. It's not just code – it's your ticket to profitable, scalable strategies.
115
+
116
+ ## **The `bbstrader` Edge: Uniting C++ Speed with Python Flexibility**
117
+
118
+ bbstrader's hybrid design is its secret weapon. At the heart is a bidirectional C++/Python bridge via `metatrader_client` module:
119
+
120
+ 1. **C++ for Speed**: Core classes like `MetaTraderClient` handle high-performance tasks. Inject Python handlers for MT5 interactions, enabling native-speed signal generation and risk checks.
121
+ 2. **Python for Smarts**: Orchestrate everything with modules like `trading` and `btengine`.
122
+ 3. **The Data Flow:** The result is a clean, efficient, and powerful execution loop:
123
+ `Python (Orchestration & Analysis) -> C++ (High-Speed Signal Generation) -> Python (MT5 Communication) -> C++ (Receives Market Data)`
124
+
125
+ This setup crushes performance ceilings: Run ML models in Python, execute trades in C++, and backtest millions of bars in minutes.
126
+
127
+ ### **Overcoming the MQL5 Bottleneck**
128
+
129
+ MetaTrader 5 is a world-class trading platform, but its native MQL5 language presents significant limitations for complex, high-frequency strategies:
130
+
131
+ - **Performance Ceilings:** As an interpreted language, MQL5 struggles with the computationally intensive logic required for advanced statistical models, machine learning, and rapid-fire order execution.
132
+ - **Ecosystem Constraints:** MQL5 lacks access to the vast, mature ecosystems of libraries for numerical computation, data science, and AI that C++ and Python offer.
133
+ - **Architectural Rigidity:** Implementing sophisticated, multi-threaded, or event-driven architectures in MQL5 is often a complex and error-prone endeavor.
134
+
135
+ `bbstrader` eradicates these barriers. By moving your core strategy logic to C++, you can unlock the full potential of your trading ideas, executing them with the microsecond-level precision demanded by institutional trading.
136
+
137
+ ## **Key Modules**
138
+
139
+ bbstrader is modular, with each component laser-focused.
140
+
141
+ ### 1. **btengine**: Event-Driven Backtesting Beast
142
+
143
+ - **Purpose**: Simulate strategies with historical data, including slippage, commissions, and multi-asset portfolios. Optimizes parameters and computes metrics like Sharpe Ratio, Drawdown, and CAGR.
144
+ - **Features**: Event queue for ticks/orders, vectorized operations for speed, integration with models for signal generation.
145
+ - **Example**: Backtest a StockIndexSTBOTrading from the example strategies.
146
+
147
+ ```Python
148
+ # Inside the examples/
149
+ from strategies import test_strategy
150
+ if __name__ == '__main__':
151
+ # Run backtesting for Stock Index Short Term Buy Only Strategy
152
+ test_strategy(strategy='sistbo')
153
+ ```
154
+
155
+ ### Backtesting Results
156
+
157
+ ![Backtesting Results1](https://github.com/bbalouki/bbstrader/blob/main/bbstrader/assets/bbs_.png?raw=true)
158
+ ![Backtesting Results2](https://github.com/bbalouki/bbstrader/blob/main/bbstrader/assets/qs_metrics_1.png?raw=true)
159
+
160
+ ### 2. **metatrader**: The C++/Python Bridge to MT5
161
+
162
+ - **Purpose**: High-speed MT5 integration. C++ MetaTraderClient mirrors MT5 API for orders, rates, and account management.
163
+ - **Features**: Bidirectional callbacks, error handling, real-time tick processing.
164
+ - **Strategy Patterns**: Two main patterns to build strategies:
165
+
166
+ #### Pattern 1: C++ Core, Python Orchestrator (Maximum Performance)
167
+
168
+ This is the recommended pattern for latency-sensitive strategies, such as statistical arbitrage, market making, or any strategy where execution speed is a critical component of your edge. By compiling your core logic, you minimize interpretation overhead and gain direct control over memory and execution.
169
+
170
+ **Use this pattern when:**
171
+
172
+ - Your strategy involves complex mathematical calculations that are slow in Python.
173
+ - You need to react to market data in the shortest possible time.
174
+ - Your production environment demands deterministic, low-latency performance.
175
+
176
+ **C++ Side (`MovingAverageStrategy.cpp`):**
177
+
178
+ ```cpp
179
+ #include "bbstrader/metatrader.hpp"
180
+ #include <numeric>
181
+ #include <iostream>
182
+
183
+ class MovingAverageStrategy : public MT5::MetaTraderClient {
184
+ public:
185
+ using MetaTraderClient::MetaTraderClient;
186
+
187
+ void on_tick(const std::string& symbol) {
188
+ auto rates_opt = copy_rates_from_pos(symbol, 1, 0, 20);
189
+
190
+ if (!rates_opt || rates_opt->size() < 20) return;
191
+
192
+ const auto& rates = *rates_opt;
193
+
194
+ double sum = std::accumulate(rates.begin(), rates.end(), 0.0,
195
+ [](double a, const MT5::RateInfo& b) { return a + b.close; });
196
+ double sma = sum / rates.size();
197
+ double current_price = rates.back().close;
198
+
199
+ if (current_price > sma) {
200
+ std::cout << "Price is above SMA. Sending Buy Order for " << symbol << '\n';
201
+ MT5::TradeRequest request;
202
+ request.action = MT5::TradeAction::DEAL;
203
+ request.symbol = symbol;
204
+ request.volume = 0.1;
205
+ request.type = MT5::OrderType::BUY;
206
+ request.type_filling = MT5::OrderFilling::FOK;
207
+ request.type_time = MT5::OrderTime::GTC;
208
+ send_order(request);
209
+ }
210
+ }
211
+ };
212
+ ```
213
+
214
+ _This C++ class would then be exposed to Python using `pybind11`._
215
+
216
+ ```cpp
217
+ // Inside bindings.cpp
218
+ #include <pybind11/pybind11.h>
219
+ #include "MovingAverageStrategy.hpp"
220
+
221
+ namespace py = pybind11;
222
+
223
+ PYBIND11_MODULE(my_strategies, m){
224
+ py::class_<MovingAverageStrategy, MT5::MetaTraderClient>(m, "MovingAverageStrategy")
225
+ .def(py::init<MT5::MetaTraderClient::Handlers>())
226
+ .def("on_tick", &MovingAverageStrategy::on_tick);
227
+ }
228
+ ```
229
+
230
+ **Python Side (`main.py`):**
231
+
232
+ ```python
233
+ from bbstrader.api import Mt5Handlers
234
+ import MetaTrader5 as mt5
235
+ import time
236
+ from my_strategies import MovingAverageStrategy
237
+
238
+ # 1. Instantiate the C++ strategy, injecting the Python MT5 handlers
239
+ strategy = MovingAverageStrategy(Mt5Handlers)
240
+
241
+ # 2. Main execution loop
242
+ if strategy.initialize():
243
+ while True:
244
+ strategy.on_tick("EURUSD")
245
+ time.sleep(1)
246
+ ```
247
+
248
+ #### Pattern 2: Python-Driven with C++ Acceleration
249
+
250
+ This pattern is ideal for strategies that benefit from Python's rich ecosystem for data analysis, machine learning, or complex event orchestration, but still require high-performance access to market data and the trading API.
251
+
252
+ **Use this pattern when:**
253
+
254
+ - Your strategy relies heavily on Python libraries like `pandas`, `scikit-learn`, or `tensorflow`.
255
+ - Rapid prototyping and iteration are more important than absolute minimum latency.
256
+ - Your core logic is more about decision-making based on pre-processed data than it is about raw computation speed.
257
+
258
+ ```python
259
+ import MetaTrader5 as mt5
260
+ from bbstrader.api import Mt5Handlers
261
+ from bbstrader.api.metatrader_client import MetaTraderClient
262
+
263
+ # 1. Inherit from the C++ MetaTraderClient in Python
264
+ class MyStrategyClient(MetaTraderClient):
265
+ def __init__(self, handlers):
266
+ super().__init__(handlers)
267
+
268
+ # 2. Instantiate your client
269
+ strategy = MyStrategyClient(Mt5Handlers)
270
+
271
+ # 3. Interact with the MT5 terminal via the C++ bridge
272
+ if strategy.initialize():
273
+ rates = strategy.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M1, 0, 100)
274
+ print(f"Retrieved {len(rates)} rates via the C++ bridge.")
275
+ ```
276
+
277
+ ### 3. **`trading`: Live Execution & Strategy Orchestrator**
278
+
279
+ - **Purpose**: Manages live sessions, coordinates signals from strategies, risk from models, and execution via metatrader.
280
+ - **Features**: Multi-account support, position hedging, trailing stops.
281
+
282
+ ### 4. `models`: Quant Toolkit for Signals & Risk
283
+
284
+ - **Purpose**: Build/test models like NLP sentiment, VaR/CVaR risk, optimization.
285
+ - **Features**: Currently Sentiment analysis, and Topic Modeling.
286
+ - **Example**: Sentiment-Based Entry:
287
+
288
+ ```python
289
+ from bbstrader.models import SentimenSentimentAnalyzer
290
+
291
+ model = SentimenSentimentAnalyzer() # Loads pre-trained NLP
292
+ score = model.analyze_sentiment("Fed hikes rates – markets soar!")
293
+ if score > 0.7: # Bullish? Buy!
294
+ print("Go long!")
295
+ ```
296
+
297
+ ### **Other Modules:**
298
+
299
+ `core`: Utilities (data structs, logging).
300
+ `config`: Manages JSON configs in ~/.bbstrader/.
301
+ `api`: Handler injections for bridges.
302
+
303
+ ## Getting Started
304
+
305
+ ### Prerequisites
306
+
307
+ - **Python**: Python 3.12+ is required.
308
+ - **MetaTrader 5 (MT5)**: Required for live execution (Windows).
309
+ - **MT5 Broker**: [Admirals](https://one.justmarkets.link/a/tufvj0xugm/registration/trader), [JustMarkets](https://one.justmarkets.link/a/tufvj0xugm/registration/trader), [FTMO](https://trader.ftmo.com/?affiliates=JGmeuQqepAZLMcdOEQRp).
310
+
311
+ ## Installation
312
+
313
+ `bbstrader` is designed for both Python and C++ developers. Follow the instructions that best suit your needs.
314
+
315
+ ### For the Python Quant
316
+
317
+ Get started in minutes using `pip`. We strongly recommend using a virtual environment.
318
+
319
+ ```bash
320
+ # Create and activate a virtual environment
321
+ python -m venv venv
322
+ source venv/bin/activate # on Linux/macOS
323
+ venv\Scripts\activate # on Windows
324
+
325
+ # Install bbstrader
326
+ pip install bbstrader[MT5] # Windows
327
+ pip install bbstrader # Linux/macOS
328
+ ```
329
+
330
+ ### For the C++ Developer
331
+
332
+ To develop your own C++ strategies, you can use `vcpkg` to install the `bbstrader` library and its dependencies.
333
+
334
+ ```bash
335
+ # If you don't have vcpkg, clone and bootstrap it
336
+ git clone https://github.com/microsoft/vcpkg
337
+ ./vcpkg/bootstrap-vcpkg.sh or ./vcpkg/bootstrap-vcpkg.bat
338
+
339
+ # Install bbstrader
340
+ ./vcpkg/vcpkg install bbstrader
341
+ ```
342
+
343
+ ## CLI workflow
344
+
345
+ `bbstrader` shines via CLI – launch everything from one command!
346
+
347
+ | Action | Command |
348
+ | :----------------- | :-------------------------------------------------------------------------------------------------------------------- |
349
+ | **Run Backtest** | `python -m bbstrader --run backtest --strategy SMAStrategy --account MY_ACCOUNT --config backtest.json` |
350
+ | **Live Execution** | `python -m bbstrader --run execution --strategy KalmanFilter --account MY_ACCOUNT --config execution.json --parallel` |
351
+ | **Copy Trades** | `python -m bbstrader --run copier --source 123456 --targets 789012 --risk_multiplier 2.0` |
352
+ | **Get Help** | `python -m bbstrader --help` |
353
+
354
+ **Config Example** (`~/.bbstrader/execution/execution.json`):
355
+
356
+ ```json
357
+ {
358
+ "SMAStrategy": {
359
+ "MY_MT5_ACCOUNT_1": {
360
+ "symbol_list": ["EURUSD", "GBPUSD"],
361
+ "trades_kwargs": { "magic": 12345, "comment": "SMA_Live" },
362
+ "short_window": 20,
363
+ "long_window": 50
364
+ }
365
+ }
366
+ }
367
+ ```
368
+
369
+ ## 🌍 Community & Support
370
+
371
+ - **[Read the Docs](https://bbstrader.readthedocs.io/en/latest/)**: Full API reference and tutorials.
372
+ - **[GitHub Issues](https://github.com/bbalouki/bbstrader/issues)**: Report bugs or request features.
373
+ - **[LinkedIn](https://www.linkedin.com/in/bertin-balouki-s-15b17a1a6)**: Connect with the creator.
374
+
375
+ ---
376
+
377
+ ### Professional Services
378
+
379
+ If you need a custom trading strategy, a proprietary risk model, advanced data pipelines, or a dedicated copy trading server setup, professional services are available.
380
+
381
+ **Contact the Developer:**
382
+ 📧 [bertin@bbs-trading.com](mailto:bertin@bbs-trading.com)
383
+
384
+ ---
385
+
386
+ ### Support the Project
387
+
388
+ If you find this project useful and would like to support its continued development, you can contribute here:
389
+
390
+ ☕ [Support the Developer](https://paypal.me/bertinbalouki?country.x=SN&locale.x=en_US)
391
+
392
+ ---
393
+
394
+ _Disclaimer: Trading involves significant risk. `bbstrader` provides the tools, but you provide the strategy. Test thoroughly on demo accounts before deploying real capital._