tradetropy 0.2.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 (146) hide show
  1. tradetropy-0.2.0/PKG-INFO +175 -0
  2. tradetropy-0.2.0/README.md +135 -0
  3. tradetropy-0.2.0/pyproject.toml +86 -0
  4. tradetropy-0.2.0/src/tradetropy/__init__.py +188 -0
  5. tradetropy-0.2.0/src/tradetropy/backtest/__init__.py +3 -0
  6. tradetropy-0.2.0/src/tradetropy/backtest/_build.py +495 -0
  7. tradetropy-0.2.0/src/tradetropy/backtest/_runner.py +673 -0
  8. tradetropy-0.2.0/src/tradetropy/backtest/_shm_bundle.py +131 -0
  9. tradetropy-0.2.0/src/tradetropy/backtest/_validation.py +35 -0
  10. tradetropy-0.2.0/src/tradetropy/backtest/engine.py +818 -0
  11. tradetropy-0.2.0/src/tradetropy/backtest/pool.py +1184 -0
  12. tradetropy-0.2.0/src/tradetropy/backtest/pool_adapter.py +122 -0
  13. tradetropy-0.2.0/src/tradetropy/connectors/__init__.py +6 -0
  14. tradetropy-0.2.0/src/tradetropy/connectors/_disclaimer.py +97 -0
  15. tradetropy-0.2.0/src/tradetropy/connectors/binance.py +301 -0
  16. tradetropy-0.2.0/src/tradetropy/connectors/bybit.py +1045 -0
  17. tradetropy-0.2.0/src/tradetropy/connectors/ccxt.py +1076 -0
  18. tradetropy-0.2.0/src/tradetropy/connectors/mt5.py +1125 -0
  19. tradetropy-0.2.0/src/tradetropy/core/__init__.py +36 -0
  20. tradetropy-0.2.0/src/tradetropy/core/broker.py +2195 -0
  21. tradetropy-0.2.0/src/tradetropy/core/constants.py +297 -0
  22. tradetropy-0.2.0/src/tradetropy/core/data_types.py +1724 -0
  23. tradetropy-0.2.0/src/tradetropy/data/__init__.py +34 -0
  24. tradetropy-0.2.0/src/tradetropy/data/_book_replay.py +222 -0
  25. tradetropy-0.2.0/src/tradetropy/data/_klines.py +450 -0
  26. tradetropy-0.2.0/src/tradetropy/data/_proxy.py +809 -0
  27. tradetropy-0.2.0/src/tradetropy/data/_ring.py +649 -0
  28. tradetropy-0.2.0/src/tradetropy/data/_store.py +120 -0
  29. tradetropy-0.2.0/src/tradetropy/data/_views.py +604 -0
  30. tradetropy-0.2.0/src/tradetropy/data/data.py +37 -0
  31. tradetropy-0.2.0/src/tradetropy/datasets/__init__.py +354 -0
  32. tradetropy-0.2.0/src/tradetropy/datasets/_data/AAPL_1d.csv +301 -0
  33. tradetropy-0.2.0/src/tradetropy/datasets/_data/ADAUSDT_1m.npz +0 -0
  34. tradetropy-0.2.0/src/tradetropy/datasets/_data/ADAUSDT_book.npz +0 -0
  35. tradetropy-0.2.0/src/tradetropy/datasets/_data/ADAUSDT_ticks.npz +0 -0
  36. tradetropy-0.2.0/src/tradetropy/datasets/_data/BTCUSDT_1m.npz +0 -0
  37. tradetropy-0.2.0/src/tradetropy/datasets/_data/GOOG_1d.csv +301 -0
  38. tradetropy-0.2.0/src/tradetropy/datasets/_data/MESU26_ticks.npz +0 -0
  39. tradetropy-0.2.0/src/tradetropy/datasets/_data/MNQU26_ticks.npz +0 -0
  40. tradetropy-0.2.0/src/tradetropy/exceptions.py +113 -0
  41. tradetropy-0.2.0/src/tradetropy/io/__init__.py +17 -0
  42. tradetropy-0.2.0/src/tradetropy/io/io.py +1721 -0
  43. tradetropy-0.2.0/src/tradetropy/live/__init__.py +5 -0
  44. tradetropy-0.2.0/src/tradetropy/live/_builder.py +738 -0
  45. tradetropy-0.2.0/src/tradetropy/live/_feed.py +713 -0
  46. tradetropy-0.2.0/src/tradetropy/live/_loop.py +337 -0
  47. tradetropy-0.2.0/src/tradetropy/live/_warmup.py +231 -0
  48. tradetropy-0.2.0/src/tradetropy/live/engine.py +579 -0
  49. tradetropy-0.2.0/src/tradetropy/logger.py +573 -0
  50. tradetropy-0.2.0/src/tradetropy/models/__init__.py +4 -0
  51. tradetropy-0.2.0/src/tradetropy/models/_warmup_policy.py +228 -0
  52. tradetropy-0.2.0/src/tradetropy/models/decorators.py +124 -0
  53. tradetropy-0.2.0/src/tradetropy/models/footprint/__init__.py +13 -0
  54. tradetropy-0.2.0/src/tradetropy/models/footprint/_compute.py +105 -0
  55. tradetropy-0.2.0/src/tradetropy/models/footprint/_config.py +62 -0
  56. tradetropy-0.2.0/src/tradetropy/models/footprint/_construction.py +186 -0
  57. tradetropy-0.2.0/src/tradetropy/models/footprint/_proxy.py +138 -0
  58. tradetropy-0.2.0/src/tradetropy/models/footprint/_ring.py +128 -0
  59. tradetropy-0.2.0/src/tradetropy/models/footprint/_store.py +70 -0
  60. tradetropy-0.2.0/src/tradetropy/models/footprint/_types.py +58 -0
  61. tradetropy-0.2.0/src/tradetropy/models/strategy.py +1525 -0
  62. tradetropy-0.2.0/src/tradetropy/optimize/__init__.py +13 -0
  63. tradetropy-0.2.0/src/tradetropy/optimize/grid_search.py +48 -0
  64. tradetropy-0.2.0/src/tradetropy/optimize/optimizer.py +82 -0
  65. tradetropy-0.2.0/src/tradetropy/optimize/random_search.py +36 -0
  66. tradetropy-0.2.0/src/tradetropy/optimize/reporter.py +68 -0
  67. tradetropy-0.2.0/src/tradetropy/optimize/result.py +175 -0
  68. tradetropy-0.2.0/src/tradetropy/optimize/space.py +141 -0
  69. tradetropy-0.2.0/src/tradetropy/optimize/task.py +156 -0
  70. tradetropy-0.2.0/src/tradetropy/playback/__init__.py +15 -0
  71. tradetropy-0.2.0/src/tradetropy/playback/base.py +1174 -0
  72. tradetropy-0.2.0/src/tradetropy/plotting/__init__.py +3 -0
  73. tradetropy-0.2.0/src/tradetropy/plotting/_fig_factory.py +111 -0
  74. tradetropy-0.2.0/src/tradetropy/plotting/_layout.py +829 -0
  75. tradetropy-0.2.0/src/tradetropy/plotting/_util.py +851 -0
  76. tradetropy-0.2.0/src/tradetropy/plotting/chart.py +16 -0
  77. tradetropy-0.2.0/src/tradetropy/plotting/config.py +250 -0
  78. tradetropy-0.2.0/src/tradetropy/plotting/js/__init__.py +0 -0
  79. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_equity.js +19 -0
  80. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_indicator.js +24 -0
  81. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_ohlc.js +59 -0
  82. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_ohlc_live.js +64 -0
  83. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_primitives.js +60 -0
  84. tradetropy-0.2.0/src/tradetropy/plotting/js/autoscale_volume.js +15 -0
  85. tradetropy-0.2.0/src/tradetropy/plotting/js/fp_lazy.js +24 -0
  86. tradetropy-0.2.0/src/tradetropy/plotting/js/fp_lazy_live.js +24 -0
  87. tradetropy-0.2.0/src/tradetropy/plotting/js/fp_yaxis_populate.js +11 -0
  88. tradetropy-0.2.0/src/tradetropy/plotting/js/lazy_labels.js +21 -0
  89. tradetropy-0.2.0/src/tradetropy/plotting/js/lazy_labels_group.js +15 -0
  90. tradetropy-0.2.0/src/tradetropy/plotting/js/legend_toggle.js +8 -0
  91. tradetropy-0.2.0/src/tradetropy/plotting/js/ylock_reset.js +7 -0
  92. tradetropy-0.2.0/src/tradetropy/plotting/js/ylock_watch.js +12 -0
  93. tradetropy-0.2.0/src/tradetropy/plotting/plotting.py +616 -0
  94. tradetropy-0.2.0/src/tradetropy/plotting/render/__init__.py +12 -0
  95. tradetropy-0.2.0/src/tradetropy/plotting/render/_annotations.py +11 -0
  96. tradetropy-0.2.0/src/tradetropy/plotting/render/_equity.py +153 -0
  97. tradetropy-0.2.0/src/tradetropy/plotting/render/_indicators.py +230 -0
  98. tradetropy-0.2.0/src/tradetropy/plotting/render/_ohlc_volume.py +167 -0
  99. tradetropy-0.2.0/src/tradetropy/plotting/render/_panels.py +225 -0
  100. tradetropy-0.2.0/src/tradetropy/plotting/render/_tools.py +407 -0
  101. tradetropy-0.2.0/src/tradetropy/plotting/render/_trades.py +237 -0
  102. tradetropy-0.2.0/src/tradetropy/plotting/sources.py +610 -0
  103. tradetropy-0.2.0/src/tradetropy/plotting/theme/__init__.py +31 -0
  104. tradetropy-0.2.0/src/tradetropy/plotting/theme/dark.py +50 -0
  105. tradetropy-0.2.0/src/tradetropy/plotting/theme/light.py +50 -0
  106. tradetropy-0.2.0/src/tradetropy/plotting/theme/registry.py +41 -0
  107. tradetropy-0.2.0/src/tradetropy/session/__init__.py +18 -0
  108. tradetropy-0.2.0/src/tradetropy/session/base.py +1256 -0
  109. tradetropy-0.2.0/src/tradetropy/session/fake_live_sesh.py +746 -0
  110. tradetropy-0.2.0/src/tradetropy/signal.py +566 -0
  111. tradetropy-0.2.0/src/tradetropy/stats/__init__.py +43 -0
  112. tradetropy-0.2.0/src/tradetropy/stats/_fast.py +517 -0
  113. tradetropy-0.2.0/src/tradetropy/stats/stats.py +1382 -0
  114. tradetropy-0.2.0/src/tradetropy/streaming/__init__.py +65 -0
  115. tradetropy-0.2.0/src/tradetropy/streaming/_protocol.py +292 -0
  116. tradetropy-0.2.0/src/tradetropy/streaming/base.py +420 -0
  117. tradetropy-0.2.0/src/tradetropy/streaming/ccxt_pro.py +397 -0
  118. tradetropy-0.2.0/src/tradetropy/streaming/fake.py +73 -0
  119. tradetropy-0.2.0/src/tradetropy/streaming/replay_feed.py +157 -0
  120. tradetropy-0.2.0/src/tradetropy/ta/__init__.py +63 -0
  121. tradetropy-0.2.0/src/tradetropy/ta/_volume_profile.py +1204 -0
  122. tradetropy-0.2.0/src/tradetropy/ta/annotations.py +1857 -0
  123. tradetropy-0.2.0/src/tradetropy/ta/base.py +479 -0
  124. tradetropy-0.2.0/src/tradetropy/ta/bill_williams.py +439 -0
  125. tradetropy-0.2.0/src/tradetropy/ta/draw.py +137 -0
  126. tradetropy-0.2.0/src/tradetropy/ta/momentum.py +2130 -0
  127. tradetropy-0.2.0/src/tradetropy/ta/order_flow/__init__.py +79 -0
  128. tradetropy-0.2.0/src/tradetropy/ta/order_flow/_core.py +2891 -0
  129. tradetropy-0.2.0/src/tradetropy/ta/order_flow/large_trades.py +398 -0
  130. tradetropy-0.2.0/src/tradetropy/ta/pattern/__init__.py +87 -0
  131. tradetropy-0.2.0/src/tradetropy/ta/pattern/pivot_mixin.py +87 -0
  132. tradetropy-0.2.0/src/tradetropy/ta/structure/__init__.py +10 -0
  133. tradetropy-0.2.0/src/tradetropy/ta/structure/_utils.py +33 -0
  134. tradetropy-0.2.0/src/tradetropy/ta/structure/hhll.py +173 -0
  135. tradetropy-0.2.0/src/tradetropy/ta/structure/nbs.py +264 -0
  136. tradetropy-0.2.0/src/tradetropy/ta/structure/pivots.py +334 -0
  137. tradetropy-0.2.0/src/tradetropy/ta/structure/swings.py +454 -0
  138. tradetropy-0.2.0/src/tradetropy/ta/structure/zigzag.py +145 -0
  139. tradetropy-0.2.0/src/tradetropy/ta/tool/__init__.py +56 -0
  140. tradetropy-0.2.0/src/tradetropy/ta/tool/base.py +136 -0
  141. tradetropy-0.2.0/src/tradetropy/ta/tool/draw.py +82 -0
  142. tradetropy-0.2.0/src/tradetropy/ta/tool/fibonacci.py +209 -0
  143. tradetropy-0.2.0/src/tradetropy/ta/tool/volume_profile.py +368 -0
  144. tradetropy-0.2.0/src/tradetropy/ta/trend.py +542 -0
  145. tradetropy-0.2.0/src/tradetropy/ta/volatility.py +237 -0
  146. tradetropy-0.2.0/src/tradetropy/ta/volume.py +704 -0
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: tradetropy
3
+ Version: 0.2.0
4
+ Summary: A professional backtesting and live trading framework for algorithmic trading strategies with footprint analysis and market microstructure.
5
+ Author: michiTrader
6
+ Author-email: michiTrader <iden.c63@gmail.com>
7
+ License-Expression: MIT
8
+ Requires-Dist: bokeh>=3.8,<4
9
+ Requires-Dist: keyboard>=0.13.5
10
+ Requires-Dist: numpy>=2.0,<2.5
11
+ Requires-Dist: pandas>=3.0,<4
12
+ Requires-Dist: pintar>=0.7.3
13
+ Requires-Dist: tqdm>=4.67.3
14
+ Requires-Dist: metatrader5>=5.0.5488 ; extra == 'all'
15
+ Requires-Dist: ccxt>=4.4.0 ; extra == 'all'
16
+ Requires-Dist: pybit>=5.7.0 ; extra == 'all'
17
+ Requires-Dist: pyarrow>=17.0.0 ; extra == 'all'
18
+ Requires-Dist: tables>=3.11.1 ; extra == 'all'
19
+ Requires-Dist: backtesting>=0.3.3 ; extra == 'bench'
20
+ Requires-Dist: pybit>=5.7.0 ; extra == 'bybit'
21
+ Requires-Dist: ccxt>=4.4.0 ; extra == 'ccxt'
22
+ Requires-Dist: mkdocs-material>=9.5.0 ; extra == 'docs'
23
+ Requires-Dist: mkdocstrings[python]>=0.26.0 ; extra == 'docs'
24
+ Requires-Dist: tables>=3.11.1 ; extra == 'hdf5'
25
+ Requires-Dist: metatrader5>=5.0.5488 ; extra == 'mt5'
26
+ Requires-Dist: pyarrow>=17.0.0 ; extra == 'parquet'
27
+ Requires-Python: >=3.12
28
+ Project-URL: Documentation, https://michiTrader.github.io/tradetropy/
29
+ Project-URL: Homepage, https://github.com/michiTrader/tradetropy
30
+ Project-URL: Repository, https://github.com/michiTrader/tradetropy
31
+ Provides-Extra: all
32
+ Provides-Extra: bench
33
+ Provides-Extra: bybit
34
+ Provides-Extra: ccxt
35
+ Provides-Extra: docs
36
+ Provides-Extra: hdf5
37
+ Provides-Extra: mt5
38
+ Provides-Extra: parquet
39
+ Description-Content-Type: text/markdown
40
+
41
+ <p align="center">
42
+ <img src="docs/assets/logo.svg" alt="Tradetropy logo" width="320">
43
+ </p>
44
+
45
+ # Tradetropy
46
+
47
+ [![PyPI](https://img.shields.io/pypi/v/tradetropy)](https://pypi.org/project/tradetropy/)
48
+
49
+ A professional backtesting and live trading framework for algorithmic trading
50
+ strategies, with first-class support for footprint analysis and market
51
+ microstructure.
52
+
53
+ Write a strategy once and run it unchanged across **backtest**, **live** and
54
+ **replay** - the engine differences are a transport detail behind the same
55
+ `Strategy` API.
56
+
57
+ ## Features
58
+
59
+ - **Backtesting engine** over candles or ticks with realistic order simulation.
60
+ - **Live trading** over WebSockets (CCXT Pro) and MetaTrader 5.
61
+ - **Order flow and footprint**: large trades, Deep Trades (L2/L3 absorption and
62
+ sweeps), cumulative delta, COT, volume profile and liquidity overlays.
63
+ - **Indicator library**: the classic studies plus market-structure tools, all
64
+ through one declarative contract.
65
+ - **Optimization and pools**, **Monte Carlo robustness** and interactive
66
+ **Bokeh plotting**.
67
+ - **Data management** with NumPy `.npz` / CSV IO built in (Parquet and HDF5
68
+ optional) and bundled sample datasets.
69
+
70
+ ## Installation
71
+
72
+ ```bash
73
+ pip install tradetropy
74
+ ```
75
+
76
+ The base install includes everything for backtesting, plotting and data IO.
77
+ Broker integrations and Parquet are optional extras:
78
+
79
+ ```bash
80
+ pip install tradetropy[mt5] # MetaTrader 5
81
+ pip install tradetropy[ccxt] # CCXT crypto exchanges (live + streaming)
82
+ pip install tradetropy[bybit] # Bybit (pybit)
83
+ pip install tradetropy[parquet] # Parquet IO (pyarrow)
84
+ pip install tradetropy[hdf5] # HDF5 IO (PyTables; not available on Termux)
85
+ pip install tradetropy[all] # all runtime extras
86
+ ```
87
+
88
+ On desktop (Windows/macOS/Linux) every dependency installs as a prebuilt wheel,
89
+ so no compiler is needed. **Termux (Android)** is the exception - the scientific
90
+ stack builds from source there; see the
91
+ [Termux install guide](https://michiTrader.github.io/tradetropy/getting-started/installation/#termux-android).
92
+
93
+ ## Quickstart
94
+
95
+ Every loader in `tradetropy.datasets` returns ready-to-use data, so this runs with
96
+ no data files or API keys:
97
+
98
+ ```python
99
+ from tradetropy import Strategy, BacktestEngine
100
+ from tradetropy.ta import SMA
101
+ from tradetropy.datasets import load_btcusd_1m
102
+
103
+
104
+ class SmaCross(Strategy):
105
+ def init(self):
106
+ self.btc = self.subscribe_ohlc('BTCUSD', '1m', window_size=200)
107
+ self.fast = self.add_indicator(self.btc.close, SMA(10))
108
+ self.slow = self.add_indicator(self.btc.close, SMA(30))
109
+
110
+ def on_data(self):
111
+ if self.fast[-1] > self.slow[-1]:
112
+ if not self.sesh.positions('BTCUSD'):
113
+ self.sesh.buy('BTCUSD', volume=1)
114
+ else:
115
+ for pos in self.sesh.positions('BTCUSD'):
116
+ self.sesh.position_close(pos.ticket)
117
+
118
+
119
+ engine = BacktestEngine.by_klines(SmaCross(), data=(load_btcusd_1m(),))
120
+ engine.run()
121
+ print(engine.stats)
122
+ ```
123
+
124
+ More runnable scripts are in [`examples/`](examples/).
125
+
126
+ ## Documentation
127
+
128
+ Full documentation - user guide and API reference - is at
129
+ **https://michiTrader.github.io/tradetropy/**.
130
+
131
+ - [Installation](https://michiTrader.github.io/tradetropy/getting-started/installation/)
132
+ - [Quickstart](https://michiTrader.github.io/tradetropy/getting-started/quickstart/)
133
+ - [Core concepts](https://michiTrader.github.io/tradetropy/guide/concepts/)
134
+ - [Working with data](https://michiTrader.github.io/tradetropy/guide/data/)
135
+ - [Indicators](https://michiTrader.github.io/tradetropy/guide/indicators/) and
136
+ [Order flow and L2](https://michiTrader.github.io/tradetropy/guide/order-flow/)
137
+ - [Live trading](https://michiTrader.github.io/tradetropy/guide/live/),
138
+ [Replay](https://michiTrader.github.io/tradetropy/guide/replay/) and
139
+ [Monte Carlo robustness](https://michiTrader.github.io/tradetropy/guide/robustness/)
140
+
141
+ To build the docs locally:
142
+
143
+ ```bash
144
+ pip install tradetropy[docs]
145
+ mkdocs serve
146
+ ```
147
+
148
+ ## Contributing
149
+
150
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Development setup:
151
+
152
+ ```bash
153
+ git clone https://github.com/michiTrader/tradetropy.git
154
+ cd tradetropy
155
+ uv sync
156
+ uv run pytest
157
+ ```
158
+
159
+ ## Risk disclaimer
160
+
161
+ Tradetropy is provided "AS IS", without warranty of any kind. Trading financial
162
+ instruments involves risk of loss of capital - you may lose part or all of your
163
+ funds. Always test first on a demo / testnet / paper account and verify that
164
+ orders, positions and balances behave as expected before trading with real
165
+ money. Broker and exchange APIs may change without notice and break a connector.
166
+ The authors and contributors are not responsible for any losses, damages or
167
+ execution failures arising from the use of this software. This is not financial,
168
+ investment or legal advice, and you are responsible for complying with the laws
169
+ of your jurisdiction and your broker/exchange terms of service.
170
+
171
+ The full disclaimer is available at runtime as `tradetropy.LIVE_DISCLAIMER`.
172
+
173
+ ## License
174
+
175
+ MIT - see [LICENSE](LICENSE).
@@ -0,0 +1,135 @@
1
+ <p align="center">
2
+ <img src="docs/assets/logo.svg" alt="Tradetropy logo" width="320">
3
+ </p>
4
+
5
+ # Tradetropy
6
+
7
+ [![PyPI](https://img.shields.io/pypi/v/tradetropy)](https://pypi.org/project/tradetropy/)
8
+
9
+ A professional backtesting and live trading framework for algorithmic trading
10
+ strategies, with first-class support for footprint analysis and market
11
+ microstructure.
12
+
13
+ Write a strategy once and run it unchanged across **backtest**, **live** and
14
+ **replay** - the engine differences are a transport detail behind the same
15
+ `Strategy` API.
16
+
17
+ ## Features
18
+
19
+ - **Backtesting engine** over candles or ticks with realistic order simulation.
20
+ - **Live trading** over WebSockets (CCXT Pro) and MetaTrader 5.
21
+ - **Order flow and footprint**: large trades, Deep Trades (L2/L3 absorption and
22
+ sweeps), cumulative delta, COT, volume profile and liquidity overlays.
23
+ - **Indicator library**: the classic studies plus market-structure tools, all
24
+ through one declarative contract.
25
+ - **Optimization and pools**, **Monte Carlo robustness** and interactive
26
+ **Bokeh plotting**.
27
+ - **Data management** with NumPy `.npz` / CSV IO built in (Parquet and HDF5
28
+ optional) and bundled sample datasets.
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install tradetropy
34
+ ```
35
+
36
+ The base install includes everything for backtesting, plotting and data IO.
37
+ Broker integrations and Parquet are optional extras:
38
+
39
+ ```bash
40
+ pip install tradetropy[mt5] # MetaTrader 5
41
+ pip install tradetropy[ccxt] # CCXT crypto exchanges (live + streaming)
42
+ pip install tradetropy[bybit] # Bybit (pybit)
43
+ pip install tradetropy[parquet] # Parquet IO (pyarrow)
44
+ pip install tradetropy[hdf5] # HDF5 IO (PyTables; not available on Termux)
45
+ pip install tradetropy[all] # all runtime extras
46
+ ```
47
+
48
+ On desktop (Windows/macOS/Linux) every dependency installs as a prebuilt wheel,
49
+ so no compiler is needed. **Termux (Android)** is the exception - the scientific
50
+ stack builds from source there; see the
51
+ [Termux install guide](https://michiTrader.github.io/tradetropy/getting-started/installation/#termux-android).
52
+
53
+ ## Quickstart
54
+
55
+ Every loader in `tradetropy.datasets` returns ready-to-use data, so this runs with
56
+ no data files or API keys:
57
+
58
+ ```python
59
+ from tradetropy import Strategy, BacktestEngine
60
+ from tradetropy.ta import SMA
61
+ from tradetropy.datasets import load_btcusd_1m
62
+
63
+
64
+ class SmaCross(Strategy):
65
+ def init(self):
66
+ self.btc = self.subscribe_ohlc('BTCUSD', '1m', window_size=200)
67
+ self.fast = self.add_indicator(self.btc.close, SMA(10))
68
+ self.slow = self.add_indicator(self.btc.close, SMA(30))
69
+
70
+ def on_data(self):
71
+ if self.fast[-1] > self.slow[-1]:
72
+ if not self.sesh.positions('BTCUSD'):
73
+ self.sesh.buy('BTCUSD', volume=1)
74
+ else:
75
+ for pos in self.sesh.positions('BTCUSD'):
76
+ self.sesh.position_close(pos.ticket)
77
+
78
+
79
+ engine = BacktestEngine.by_klines(SmaCross(), data=(load_btcusd_1m(),))
80
+ engine.run()
81
+ print(engine.stats)
82
+ ```
83
+
84
+ More runnable scripts are in [`examples/`](examples/).
85
+
86
+ ## Documentation
87
+
88
+ Full documentation - user guide and API reference - is at
89
+ **https://michiTrader.github.io/tradetropy/**.
90
+
91
+ - [Installation](https://michiTrader.github.io/tradetropy/getting-started/installation/)
92
+ - [Quickstart](https://michiTrader.github.io/tradetropy/getting-started/quickstart/)
93
+ - [Core concepts](https://michiTrader.github.io/tradetropy/guide/concepts/)
94
+ - [Working with data](https://michiTrader.github.io/tradetropy/guide/data/)
95
+ - [Indicators](https://michiTrader.github.io/tradetropy/guide/indicators/) and
96
+ [Order flow and L2](https://michiTrader.github.io/tradetropy/guide/order-flow/)
97
+ - [Live trading](https://michiTrader.github.io/tradetropy/guide/live/),
98
+ [Replay](https://michiTrader.github.io/tradetropy/guide/replay/) and
99
+ [Monte Carlo robustness](https://michiTrader.github.io/tradetropy/guide/robustness/)
100
+
101
+ To build the docs locally:
102
+
103
+ ```bash
104
+ pip install tradetropy[docs]
105
+ mkdocs serve
106
+ ```
107
+
108
+ ## Contributing
109
+
110
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Development setup:
111
+
112
+ ```bash
113
+ git clone https://github.com/michiTrader/tradetropy.git
114
+ cd tradetropy
115
+ uv sync
116
+ uv run pytest
117
+ ```
118
+
119
+ ## Risk disclaimer
120
+
121
+ Tradetropy is provided "AS IS", without warranty of any kind. Trading financial
122
+ instruments involves risk of loss of capital - you may lose part or all of your
123
+ funds. Always test first on a demo / testnet / paper account and verify that
124
+ orders, positions and balances behave as expected before trading with real
125
+ money. Broker and exchange APIs may change without notice and break a connector.
126
+ The authors and contributors are not responsible for any losses, damages or
127
+ execution failures arising from the use of this software. This is not financial,
128
+ investment or legal advice, and you are responsible for complying with the laws
129
+ of your jurisdiction and your broker/exchange terms of service.
130
+
131
+ The full disclaimer is available at runtime as `tradetropy.LIVE_DISCLAIMER`.
132
+
133
+ ## License
134
+
135
+ MIT - see [LICENSE](LICENSE).
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "tradetropy"
3
+ version = "0.2.0"
4
+ description = "A professional backtesting and live trading framework for algorithmic trading strategies with footprint analysis and market microstructure."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ authors = [
8
+ { name = "michiTrader", email = "iden.c63@gmail.com" }
9
+ ]
10
+ requires-python = ">=3.12"
11
+
12
+ # Core runtime dependencies. Installing `pip install tradetropy` gives you the full
13
+ # backtesting, plotting, indicator and data-IO stack. The base binary data
14
+ # format is NumPy .npz (no compiler needed, works everywhere - including
15
+ # Termux/Android). Broker/venue integrations, Parquet and HDF5 IO are optional
16
+ # extras (see [project.optional-dependencies]).
17
+ dependencies = [
18
+ "bokeh>=3.8,<4",
19
+ "keyboard>=0.13.5",
20
+ "numpy>=2.0,<2.5",
21
+ "pandas>=3.0,<4",
22
+ "pintar>=0.7.3",
23
+ "tqdm>=4.67.3",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ # Broker / venue connectors (each pulls only what that integration needs).
28
+ mt5 = ["MetaTrader5>=5.0.5488"]
29
+ ccxt = ["ccxt>=4.4.0"]
30
+ bybit = ["pybit>=5.7.0"]
31
+
32
+ # Optional Parquet support for tradetropy.io (read_*/save_* with format='parquet').
33
+ parquet = ["pyarrow>=17.0.0"]
34
+
35
+ # Optional HDF5 support for tradetropy.io (read_*/save_* with format='hdf5').
36
+ # PyTables links the HDF5 C library and cannot build on some platforms (notably
37
+ # Termux/Android); the base install uses the .npz format instead and does not
38
+ # need this.
39
+ hdf5 = ["tables>=3.11.1"]
40
+
41
+ # Everything above in one shot (runtime extras only; docs excluded).
42
+ all = [
43
+ "MetaTrader5>=5.0.5488",
44
+ "ccxt>=4.4.0",
45
+ "pybit>=5.7.0",
46
+ "pyarrow>=17.0.0",
47
+ "tables>=3.11.1",
48
+ ]
49
+
50
+ # Documentation site toolchain (MkDocs Material + API autodoc).
51
+ docs = [
52
+ "mkdocs-material>=9.5.0",
53
+ "mkdocstrings[python]>=0.26.0",
54
+ ]
55
+
56
+ # Benchmarking against backtesting.py (benchmarks/bench_vs_backtesting_py.py).
57
+ # Only needed to reproduce the numbers in docs/guide/performance.md.
58
+ bench = ["backtesting>=0.3.3"]
59
+
60
+ [project.urls]
61
+ Homepage = "https://github.com/michiTrader/tradetropy"
62
+ Documentation = "https://michiTrader.github.io/tradetropy/"
63
+ Repository = "https://github.com/michiTrader/tradetropy"
64
+
65
+ # Development-only tooling (installed by `uv sync`, not shipped to users).
66
+ # tables/pyarrow are runtime OPTIONAL extras for users, but the dev environment
67
+ # needs them so the full test suite (which exercises the HDF5 and Parquet IO
68
+ # paths) runs under `uv sync`.
69
+ [dependency-groups]
70
+ dev = [
71
+ "pytest>=9.0.2",
72
+ "pytest-benchmark>=5.2.3",
73
+ "tables>=3.11.1",
74
+ "pyarrow>=17.0.0",
75
+ ]
76
+
77
+ [build-system]
78
+ requires = ["uv_build>=0.9.11,<0.10.0"]
79
+ build-backend = "uv_build"
80
+
81
+ [tool.uv]
82
+ constraint-dependencies = ["numpy<2.5"]
83
+
84
+ # The bundled sample datasets in src/tradetropy/datasets/_data/ (*.npz, *.csv)
85
+ # live inside the module root, so the uv build backend includes them in both
86
+ # the sdist and the wheel automatically (only __pycache__/*.pyc are excluded).
@@ -0,0 +1,188 @@
1
+ """
2
+ tradetropy - professional backtesting and live trading framework.
3
+
4
+ The public API is exposed lazily (PEP 562). Importing ``tradetropy`` itself is
5
+ cheap: heavy subsystems (pandas via ``stats``/``io``, ``live``, ``plotting``,
6
+ ``robustness``) are only imported the first time one of their names is
7
+ accessed. This keeps the import cost of a pure backtest/optimize workflow -
8
+ and of every spawned optimize/pool worker on Windows/macOS - close to the
9
+ numpy floor, instead of paying for plotting, live and robustness that a
10
+ worker never touches.
11
+
12
+ The exported surface is unchanged; ``from tradetropy import BacktestEngine``,
13
+ ``tradetropy.SMA`` and ``from tradetropy import *`` all keep working exactly as
14
+ before.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import importlib
20
+ from typing import TYPE_CHECKING
21
+
22
+ # ``exceptions`` is tiny (no third-party imports) and is referenced as the
23
+ # submodule ``tradetropy.exceptions`` throughout the codebase, so it stays eager.
24
+ from tradetropy import exceptions
25
+
26
+ # ══════════════════════════════════════════════════════════════════════════════
27
+ # Lazy public-symbol registry: name -> (submodule, attribute)
28
+ # ══════════════════════════════════════════════════════════════════════════════
29
+ #
30
+ # Each entry maps a public name to the module that defines it. Nothing here is
31
+ # imported until the name is first accessed (see ``__getattr__`` below), so a
32
+ # process that only runs backtests never imports ``live``/``plotting``/
33
+ # ``robustness`` and only pays for ``pandas`` when it actually computes stats.
34
+ #
35
+ # The ``# >>> tier:N`` / ``# <<< tier:N`` marker blocks are consumed by
36
+ # tools/generate_tier.py to gate optional names out of lower-tier builds; keep
37
+ # each gated name's registry entry AND its ``__all__`` entry inside the markers.
38
+
39
+ _LAZY: dict[str, tuple[str, str]] = {
40
+ # -- Engines ---------------------------------------------------------------
41
+ "BacktestEngine": ("tradetropy.backtest", "BacktestEngine"),
42
+ "PoolBacktestEngine": ("tradetropy.backtest", "PoolBacktestEngine"),
43
+ "LiveEngine": ("tradetropy.live", "LiveEngine"),
44
+
45
+ # -- Disclaimer ------------------------------------------------------------
46
+ "LIVE_DISCLAIMER": ("tradetropy.connectors._disclaimer", "LIVE_DISCLAIMER"),
47
+
48
+ # -- Strategy / sessions ---------------------------------------------------
49
+ "Strategy": ("tradetropy.models", "Strategy"),
50
+ "FootprintConfig": ("tradetropy.models", "FootprintConfig"),
51
+ "SeshSimulatorBase": ("tradetropy.session", "SeshSimulatorBase"),
52
+
53
+ # -- Core data types -------------------------------------------------------
54
+ "TickData": ("tradetropy.core", "TickData"),
55
+ "KlineData": ("tradetropy.core", "KlineData"),
56
+ "parse_timeframe": ("tradetropy.core", "parse_timeframe"),
57
+ "TIMEFRAME_PRESETS": ("tradetropy.core", "TIMEFRAME_PRESETS"),
58
+
59
+ # -- Stats -----------------------------------------------------------------
60
+ "Stats": ("tradetropy.stats", "Stats"),
61
+ "compute_stats": ("tradetropy.stats", "compute_stats"),
62
+
63
+ # -- Robustness ------------------------------------------------------------
64
+
65
+ # -- Plotting --------------------------------------------------------------
66
+ "plot": ("tradetropy.plotting", "plot"),
67
+ "PlotConfig": ("tradetropy.plotting", "PlotConfig"),
68
+
69
+ # -- Indicators (tradetropy.ta) ----------------------------------------------
70
+ "Indicator": ("tradetropy.ta", "Indicator"),
71
+ "IndicatorPlotConfig": ("tradetropy.ta", "IndicatorPlotConfig"),
72
+ "SMA": ("tradetropy.ta", "SMA"),
73
+ "EMA": ("tradetropy.ta", "EMA"),
74
+ "MACD": ("tradetropy.ta", "MACD"),
75
+ "RSI": ("tradetropy.ta", "RSI"),
76
+ "ATR": ("tradetropy.ta", "ATR"),
77
+ "BollingerBands": ("tradetropy.ta", "BollingerBands"),
78
+ "VolumeProfile": ("tradetropy.ta", "VolumeProfile"),
79
+ "RollingVolumeProfile": ("tradetropy.ta", "RollingVolumeProfile"),
80
+ "VolumeNode": ("tradetropy.ta", "VolumeNode"),
81
+ "detect_volume_nodes": ("tradetropy.ta", "detect_volume_nodes"),
82
+ "ZigZag": ("tradetropy.ta", "ZigZag"),
83
+ "ConfirmedPivot": ("tradetropy.ta", "ConfirmedPivot"),
84
+ "PivotHighLow": ("tradetropy.ta", "PivotHighLow"),
85
+ "SwingHL": ("tradetropy.ta", "SwingHL"),
86
+ "EqualHL": ("tradetropy.ta", "EqualHL"),
87
+ "FairValueGap": ("tradetropy.ta", "FairValueGap"),
88
+ "OrderBlock": ("tradetropy.ta", "OrderBlock"),
89
+ "MarketSessions": ("tradetropy.ta", "MarketSessions"),
90
+ "SessionLevels": ("tradetropy.ta", "SessionLevels"),
91
+ "KillZones": ("tradetropy.ta", "KillZones"),
92
+ "LargeTrades": ("tradetropy.ta", "LargeTrades"),
93
+ }
94
+
95
+ __all__ = [
96
+ "exceptions",
97
+ "BacktestEngine",
98
+ "PoolBacktestEngine",
99
+ "LiveEngine",
100
+ "LIVE_DISCLAIMER",
101
+ "Strategy",
102
+ "FootprintConfig",
103
+ "SeshSimulatorBase",
104
+ "TickData",
105
+ "KlineData",
106
+ "parse_timeframe",
107
+ "TIMEFRAME_PRESETS",
108
+ "Stats",
109
+ "compute_stats",
110
+ "plot",
111
+ "PlotConfig",
112
+ "Indicator",
113
+ "IndicatorPlotConfig",
114
+ "SMA",
115
+ "EMA",
116
+ "MACD",
117
+ "RSI",
118
+ "ATR",
119
+ "BollingerBands",
120
+ "VolumeProfile",
121
+ "RollingVolumeProfile",
122
+ "VolumeNode",
123
+ "detect_volume_nodes",
124
+ "ZigZag",
125
+ "ConfirmedPivot",
126
+ "PivotHighLow",
127
+ "SwingHL",
128
+ "EqualHL",
129
+ "FairValueGap",
130
+ "OrderBlock",
131
+ "MarketSessions",
132
+ "SessionLevels",
133
+ "KillZones",
134
+ "LargeTrades",
135
+ ]
136
+
137
+
138
+ def __getattr__(name: str):
139
+ """
140
+ Resolve a public name lazily (PEP 562).
141
+
142
+ Looks the name up in the lazy registry, imports the owning submodule on
143
+ first access, caches the resolved object in the module globals (so later
144
+ lookups skip this path), and returns it. Falls back to importing a
145
+ same-named submodule, then raises AttributeError.
146
+ """
147
+ entry = _LAZY.get(name)
148
+ if entry is not None:
149
+ module_path, attr = entry
150
+ module = importlib.import_module(module_path)
151
+ value = getattr(module, attr)
152
+ globals()[name] = value
153
+ return value
154
+
155
+ # Fall back to a real submodule access (e.g. ``tradetropy.core``).
156
+ try:
157
+ module = importlib.import_module(f"{__name__}.{name}")
158
+ globals()[name] = module
159
+ return module
160
+ except ImportError:
161
+ pass
162
+
163
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
164
+
165
+
166
+ def __dir__() -> list[str]:
167
+ """Expose the full public surface to ``dir()`` and tab completion."""
168
+ return sorted(set(globals()) | set(_LAZY))
169
+
170
+
171
+ # Give static analysers / IDEs the real symbols without any runtime import cost.
172
+ if TYPE_CHECKING: # pragma: no cover
173
+ from tradetropy.backtest import BacktestEngine, PoolBacktestEngine
174
+ from tradetropy.live import LiveEngine, LivePool, Recorder
175
+ from tradetropy.connectors._disclaimer import LIVE_DISCLAIMER
176
+ from tradetropy.models import Strategy, FootprintConfig
177
+ from tradetropy.session import SeshSimulatorBase
178
+ from tradetropy.core import TickData, KlineData, parse_timeframe, TIMEFRAME_PRESETS
179
+ from tradetropy.stats import Stats, compute_stats
180
+ from tradetropy.robustness import MonteCarlo, MonteCarloConfig, MonteCarloResult
181
+ from tradetropy.plotting import plot, PlotConfig
182
+ from tradetropy.ta import (
183
+ Indicator, IndicatorPlotConfig, SMA, EMA, MACD, RSI, ATR,
184
+ BollingerBands, VolumeProfile, TickVolumeProfile, RollingVolumeProfile,
185
+ VolumeNode, detect_volume_nodes, ZigZag, ConfirmedPivot, PivotHighLow,
186
+ SwingHL, EqualHL, FairValueGap, OrderBlock, MarketSessions,
187
+ SessionLevels, KillZones, LargeTrades,
188
+ )
@@ -0,0 +1,3 @@
1
+ from tradetropy.backtest.engine import BacktestEngine
2
+ from tradetropy.backtest.pool import PoolBacktestEngine
3
+ from tradetropy.backtest.pool_adapter import PoolEvaluator