tradear 0.1.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.
- tradear-0.1.0/PKG-INFO +160 -0
- tradear-0.1.0/README.md +122 -0
- tradear-0.1.0/pyproject.toml +68 -0
- tradear-0.1.0/src/tradear/__init__.py +34 -0
- tradear-0.1.0/src/tradear/backtest/__init__.py +3 -0
- tradear-0.1.0/src/tradear/backtest/_build.py +454 -0
- tradear-0.1.0/src/tradear/backtest/_runner.py +628 -0
- tradear-0.1.0/src/tradear/backtest/_validation.py +35 -0
- tradear-0.1.0/src/tradear/backtest/engine.py +747 -0
- tradear-0.1.0/src/tradear/backtest/pool.py +1186 -0
- tradear-0.1.0/src/tradear/backtest/pool_adapter.py +83 -0
- tradear-0.1.0/src/tradear/connectors/__init__.py +6 -0
- tradear-0.1.0/src/tradear/connectors/_disclaimer.py +97 -0
- tradear-0.1.0/src/tradear/connectors/binance.py +301 -0
- tradear-0.1.0/src/tradear/connectors/bybit.py +1045 -0
- tradear-0.1.0/src/tradear/connectors/ccxt.py +1076 -0
- tradear-0.1.0/src/tradear/connectors/mt5.py +1125 -0
- tradear-0.1.0/src/tradear/core/__init__.py +36 -0
- tradear-0.1.0/src/tradear/core/broker.py +2013 -0
- tradear-0.1.0/src/tradear/core/constants.py +297 -0
- tradear-0.1.0/src/tradear/core/data_types.py +1703 -0
- tradear-0.1.0/src/tradear/data/__init__.py +34 -0
- tradear-0.1.0/src/tradear/data/_book_replay.py +222 -0
- tradear-0.1.0/src/tradear/data/_klines.py +450 -0
- tradear-0.1.0/src/tradear/data/_proxy.py +732 -0
- tradear-0.1.0/src/tradear/data/_ring.py +649 -0
- tradear-0.1.0/src/tradear/data/_store.py +120 -0
- tradear-0.1.0/src/tradear/data/_views.py +509 -0
- tradear-0.1.0/src/tradear/data/data.py +37 -0
- tradear-0.1.0/src/tradear/datasets/__init__.py +354 -0
- tradear-0.1.0/src/tradear/datasets/_data/AAPL_1d.csv +301 -0
- tradear-0.1.0/src/tradear/datasets/_data/ADAUSDT_1m.hdf5 +0 -0
- tradear-0.1.0/src/tradear/datasets/_data/ADAUSDT_book.hdf5 +0 -0
- tradear-0.1.0/src/tradear/datasets/_data/ADAUSDT_ticks.hdf5 +0 -0
- tradear-0.1.0/src/tradear/datasets/_data/BTCUSDT_1m.hdf5 +0 -0
- tradear-0.1.0/src/tradear/datasets/_data/GOOG_1d.csv +301 -0
- tradear-0.1.0/src/tradear/datasets/_data/MESU26_ticks.hdf5 +0 -0
- tradear-0.1.0/src/tradear/datasets/_data/MNQU26_ticks.hdf5 +0 -0
- tradear-0.1.0/src/tradear/exceptions.py +113 -0
- tradear-0.1.0/src/tradear/io/__init__.py +17 -0
- tradear-0.1.0/src/tradear/io/io.py +1399 -0
- tradear-0.1.0/src/tradear/live/__init__.py +5 -0
- tradear-0.1.0/src/tradear/live/_builder.py +738 -0
- tradear-0.1.0/src/tradear/live/_feed.py +712 -0
- tradear-0.1.0/src/tradear/live/_loop.py +337 -0
- tradear-0.1.0/src/tradear/live/_warmup.py +231 -0
- tradear-0.1.0/src/tradear/live/engine.py +574 -0
- tradear-0.1.0/src/tradear/logger.py +573 -0
- tradear-0.1.0/src/tradear/models/__init__.py +4 -0
- tradear-0.1.0/src/tradear/models/_warmup_policy.py +228 -0
- tradear-0.1.0/src/tradear/models/decorators.py +124 -0
- tradear-0.1.0/src/tradear/models/footprint/__init__.py +13 -0
- tradear-0.1.0/src/tradear/models/footprint/_compute.py +105 -0
- tradear-0.1.0/src/tradear/models/footprint/_config.py +62 -0
- tradear-0.1.0/src/tradear/models/footprint/_construction.py +186 -0
- tradear-0.1.0/src/tradear/models/footprint/_proxy.py +138 -0
- tradear-0.1.0/src/tradear/models/footprint/_ring.py +128 -0
- tradear-0.1.0/src/tradear/models/footprint/_store.py +70 -0
- tradear-0.1.0/src/tradear/models/footprint/_types.py +58 -0
- tradear-0.1.0/src/tradear/models/strategy.py +1525 -0
- tradear-0.1.0/src/tradear/optimize/__init__.py +13 -0
- tradear-0.1.0/src/tradear/optimize/grid_search.py +48 -0
- tradear-0.1.0/src/tradear/optimize/optimizer.py +82 -0
- tradear-0.1.0/src/tradear/optimize/random_search.py +36 -0
- tradear-0.1.0/src/tradear/optimize/reporter.py +68 -0
- tradear-0.1.0/src/tradear/optimize/result.py +175 -0
- tradear-0.1.0/src/tradear/optimize/space.py +141 -0
- tradear-0.1.0/src/tradear/optimize/task.py +156 -0
- tradear-0.1.0/src/tradear/playback/__init__.py +15 -0
- tradear-0.1.0/src/tradear/playback/base.py +1174 -0
- tradear-0.1.0/src/tradear/plotting/__init__.py +3 -0
- tradear-0.1.0/src/tradear/plotting/_fig_factory.py +111 -0
- tradear-0.1.0/src/tradear/plotting/_layout.py +830 -0
- tradear-0.1.0/src/tradear/plotting/_util.py +851 -0
- tradear-0.1.0/src/tradear/plotting/chart.py +16 -0
- tradear-0.1.0/src/tradear/plotting/config.py +253 -0
- tradear-0.1.0/src/tradear/plotting/js/__init__.py +0 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_equity.js +19 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_indicator.js +24 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_ohlc.js +59 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_ohlc_live.js +64 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_primitives.js +60 -0
- tradear-0.1.0/src/tradear/plotting/js/autoscale_volume.js +15 -0
- tradear-0.1.0/src/tradear/plotting/js/fp_lazy.js +24 -0
- tradear-0.1.0/src/tradear/plotting/js/fp_lazy_live.js +24 -0
- tradear-0.1.0/src/tradear/plotting/js/fp_yaxis_populate.js +11 -0
- tradear-0.1.0/src/tradear/plotting/js/lazy_labels.js +21 -0
- tradear-0.1.0/src/tradear/plotting/js/lazy_labels_group.js +15 -0
- tradear-0.1.0/src/tradear/plotting/js/legend_toggle.js +8 -0
- tradear-0.1.0/src/tradear/plotting/js/ylock_reset.js +7 -0
- tradear-0.1.0/src/tradear/plotting/js/ylock_watch.js +12 -0
- tradear-0.1.0/src/tradear/plotting/plotting.py +616 -0
- tradear-0.1.0/src/tradear/plotting/render/__init__.py +12 -0
- tradear-0.1.0/src/tradear/plotting/render/_annotations.py +11 -0
- tradear-0.1.0/src/tradear/plotting/render/_equity.py +153 -0
- tradear-0.1.0/src/tradear/plotting/render/_indicators.py +230 -0
- tradear-0.1.0/src/tradear/plotting/render/_ohlc_volume.py +167 -0
- tradear-0.1.0/src/tradear/plotting/render/_panels.py +225 -0
- tradear-0.1.0/src/tradear/plotting/render/_tools.py +407 -0
- tradear-0.1.0/src/tradear/plotting/render/_trades.py +237 -0
- tradear-0.1.0/src/tradear/plotting/sources.py +610 -0
- tradear-0.1.0/src/tradear/plotting/theme/__init__.py +31 -0
- tradear-0.1.0/src/tradear/plotting/theme/dark.py +50 -0
- tradear-0.1.0/src/tradear/plotting/theme/light.py +50 -0
- tradear-0.1.0/src/tradear/plotting/theme/registry.py +41 -0
- tradear-0.1.0/src/tradear/session/__init__.py +18 -0
- tradear-0.1.0/src/tradear/session/base.py +1238 -0
- tradear-0.1.0/src/tradear/session/fake_live_sesh.py +745 -0
- tradear-0.1.0/src/tradear/signal.py +566 -0
- tradear-0.1.0/src/tradear/stats/__init__.py +2 -0
- tradear-0.1.0/src/tradear/stats/stats.py +1382 -0
- tradear-0.1.0/src/tradear/streaming/__init__.py +65 -0
- tradear-0.1.0/src/tradear/streaming/_protocol.py +292 -0
- tradear-0.1.0/src/tradear/streaming/base.py +420 -0
- tradear-0.1.0/src/tradear/streaming/ccxt_pro.py +397 -0
- tradear-0.1.0/src/tradear/streaming/fake.py +73 -0
- tradear-0.1.0/src/tradear/streaming/replay_feed.py +157 -0
- tradear-0.1.0/src/tradear/ta/__init__.py +63 -0
- tradear-0.1.0/src/tradear/ta/_volume_profile.py +1204 -0
- tradear-0.1.0/src/tradear/ta/annotations.py +1857 -0
- tradear-0.1.0/src/tradear/ta/base.py +479 -0
- tradear-0.1.0/src/tradear/ta/bill_williams.py +439 -0
- tradear-0.1.0/src/tradear/ta/draw.py +137 -0
- tradear-0.1.0/src/tradear/ta/momentum.py +2133 -0
- tradear-0.1.0/src/tradear/ta/order_flow/__init__.py +79 -0
- tradear-0.1.0/src/tradear/ta/order_flow/_core.py +2891 -0
- tradear-0.1.0/src/tradear/ta/order_flow/large_trades.py +398 -0
- tradear-0.1.0/src/tradear/ta/pattern/__init__.py +87 -0
- tradear-0.1.0/src/tradear/ta/pattern/pivot_mixin.py +87 -0
- tradear-0.1.0/src/tradear/ta/structure/__init__.py +10 -0
- tradear-0.1.0/src/tradear/ta/structure/_utils.py +33 -0
- tradear-0.1.0/src/tradear/ta/structure/hhll.py +173 -0
- tradear-0.1.0/src/tradear/ta/structure/nbs.py +264 -0
- tradear-0.1.0/src/tradear/ta/structure/pivots.py +334 -0
- tradear-0.1.0/src/tradear/ta/structure/swings.py +454 -0
- tradear-0.1.0/src/tradear/ta/structure/zigzag.py +145 -0
- tradear-0.1.0/src/tradear/ta/tool/__init__.py +56 -0
- tradear-0.1.0/src/tradear/ta/tool/base.py +136 -0
- tradear-0.1.0/src/tradear/ta/tool/draw.py +82 -0
- tradear-0.1.0/src/tradear/ta/tool/fibonacci.py +209 -0
- tradear-0.1.0/src/tradear/ta/tool/volume_profile.py +368 -0
- tradear-0.1.0/src/tradear/ta/trend.py +542 -0
- tradear-0.1.0/src/tradear/ta/volatility.py +237 -0
- tradear-0.1.0/src/tradear/ta/volume.py +703 -0
tradear-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tradear
|
|
3
|
+
Version: 0.1.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: ipython>=9.10.0
|
|
10
|
+
Requires-Dist: keyboard>=0.13.5
|
|
11
|
+
Requires-Dist: numpy>=2.2.5
|
|
12
|
+
Requires-Dist: pandas>=3.0,<4
|
|
13
|
+
Requires-Dist: pintar>=0.7.3
|
|
14
|
+
Requires-Dist: plotext>=5.3.2
|
|
15
|
+
Requires-Dist: tables>=3.11.1
|
|
16
|
+
Requires-Dist: tqdm>=4.67.3
|
|
17
|
+
Requires-Dist: metatrader5>=5.0.5488 ; extra == 'all'
|
|
18
|
+
Requires-Dist: ccxt>=4.4.0 ; extra == 'all'
|
|
19
|
+
Requires-Dist: pybit>=5.7.0 ; extra == 'all'
|
|
20
|
+
Requires-Dist: pyarrow>=17.0.0 ; extra == 'all'
|
|
21
|
+
Requires-Dist: pybit>=5.7.0 ; extra == 'bybit'
|
|
22
|
+
Requires-Dist: ccxt>=4.4.0 ; extra == 'ccxt'
|
|
23
|
+
Requires-Dist: mkdocs-material>=9.5.0 ; extra == 'docs'
|
|
24
|
+
Requires-Dist: mkdocstrings[python]>=0.26.0 ; extra == 'docs'
|
|
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/tradear-pro/
|
|
29
|
+
Project-URL: Homepage, https://github.com/michiTrader/tradear-pro
|
|
30
|
+
Project-URL: Repository, https://github.com/michiTrader/tradear-pro
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Provides-Extra: bybit
|
|
33
|
+
Provides-Extra: ccxt
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Provides-Extra: mt5
|
|
36
|
+
Provides-Extra: parquet
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# Tradear
|
|
40
|
+
|
|
41
|
+
A professional backtesting and live trading framework for algorithmic trading
|
|
42
|
+
strategies, with first-class support for footprint analysis and market
|
|
43
|
+
microstructure.
|
|
44
|
+
|
|
45
|
+
Write a strategy once and run it unchanged across **backtest**, **live** and
|
|
46
|
+
**replay** - the engine differences are a transport detail behind the same
|
|
47
|
+
`Strategy` API.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Backtesting engine** over candles or ticks with realistic order simulation.
|
|
52
|
+
- **Live trading** over WebSockets (CCXT Pro) and MetaTrader 5.
|
|
53
|
+
- **Order flow and footprint**: large trades, Deep Trades (L2/L3 absorption and
|
|
54
|
+
sweeps), cumulative delta, COT, volume profile and liquidity overlays.
|
|
55
|
+
- **Indicator library**: the classic studies plus market-structure tools, all
|
|
56
|
+
through one declarative contract.
|
|
57
|
+
- **Optimization and pools**, **Monte Carlo robustness** and interactive
|
|
58
|
+
**Bokeh plotting**.
|
|
59
|
+
- **Data management** with CSV/HDF5/Parquet IO and bundled sample datasets.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install tradear
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The base install includes everything for backtesting, plotting and data IO.
|
|
68
|
+
Broker integrations and Parquet are optional extras:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install tradear[mt5] # MetaTrader 5
|
|
72
|
+
pip install tradear[ccxt] # CCXT crypto exchanges (live + streaming)
|
|
73
|
+
pip install tradear[bybit] # Bybit (pybit)
|
|
74
|
+
pip install tradear[parquet] # Parquet IO (pyarrow)
|
|
75
|
+
pip install tradear[all] # all runtime extras
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quickstart
|
|
79
|
+
|
|
80
|
+
Every loader in `tradear.datasets` returns ready-to-use data, so this runs with
|
|
81
|
+
no data files or API keys:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from tradear import Strategy, BacktestEngine
|
|
85
|
+
from tradear.ta import SMA
|
|
86
|
+
from tradear.datasets import load_btcusd_1m
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class SmaCross(Strategy):
|
|
90
|
+
def init(self):
|
|
91
|
+
self.btc = self.subscribe_ohlc('BTCUSD', '1m', window_size=200)
|
|
92
|
+
self.fast = self.add_indicator(self.btc.close, SMA(10))
|
|
93
|
+
self.slow = self.add_indicator(self.btc.close, SMA(30))
|
|
94
|
+
|
|
95
|
+
def on_data(self):
|
|
96
|
+
if self.fast[-1] > self.slow[-1]:
|
|
97
|
+
if not self.sesh.positions('BTCUSD'):
|
|
98
|
+
self.sesh.buy('BTCUSD', volume=1)
|
|
99
|
+
else:
|
|
100
|
+
for pos in self.sesh.positions('BTCUSD'):
|
|
101
|
+
self.sesh.position_close(pos.ticket)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
engine = BacktestEngine.by_klines(SmaCross(), data=(load_btcusd_1m(),))
|
|
105
|
+
engine.run()
|
|
106
|
+
print(engine.stats)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
More runnable scripts are in [`examples/`](examples/).
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
Full documentation - user guide and API reference - is at
|
|
114
|
+
**https://michiTrader.github.io/tradear-pro/**.
|
|
115
|
+
|
|
116
|
+
- [Installation](https://michiTrader.github.io/tradear-pro/getting-started/installation/)
|
|
117
|
+
- [Quickstart](https://michiTrader.github.io/tradear-pro/getting-started/quickstart/)
|
|
118
|
+
- [Core concepts](https://michiTrader.github.io/tradear-pro/guide/concepts/)
|
|
119
|
+
- [Working with data](https://michiTrader.github.io/tradear-pro/guide/data/)
|
|
120
|
+
- [Indicators](https://michiTrader.github.io/tradear-pro/guide/indicators/) and
|
|
121
|
+
[Order flow and L2](https://michiTrader.github.io/tradear-pro/guide/order-flow/)
|
|
122
|
+
- [Live trading](https://michiTrader.github.io/tradear-pro/guide/live/),
|
|
123
|
+
[Replay](https://michiTrader.github.io/tradear-pro/guide/replay/) and
|
|
124
|
+
[Monte Carlo robustness](https://michiTrader.github.io/tradear-pro/guide/robustness/)
|
|
125
|
+
|
|
126
|
+
To build the docs locally:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install tradear[docs]
|
|
130
|
+
mkdocs serve
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Contributing
|
|
134
|
+
|
|
135
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Development setup:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
git clone https://github.com/michiTrader/tradear-pro.git
|
|
139
|
+
cd tradear-pro
|
|
140
|
+
uv sync
|
|
141
|
+
uv run pytest
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Risk disclaimer
|
|
145
|
+
|
|
146
|
+
Tradear is provided "AS IS", without warranty of any kind. Trading financial
|
|
147
|
+
instruments involves risk of loss of capital - you may lose part or all of your
|
|
148
|
+
funds. Always test first on a demo / testnet / paper account and verify that
|
|
149
|
+
orders, positions and balances behave as expected before trading with real
|
|
150
|
+
money. Broker and exchange APIs may change without notice and break a connector.
|
|
151
|
+
The authors and contributors are not responsible for any losses, damages or
|
|
152
|
+
execution failures arising from the use of this software. This is not financial,
|
|
153
|
+
investment or legal advice, and you are responsible for complying with the laws
|
|
154
|
+
of your jurisdiction and your broker/exchange terms of service.
|
|
155
|
+
|
|
156
|
+
The full disclaimer is available at runtime as `tradear.LIVE_DISCLAIMER`.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT - see [LICENSE](LICENSE).
|
tradear-0.1.0/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Tradear
|
|
2
|
+
|
|
3
|
+
A professional backtesting and live trading framework for algorithmic trading
|
|
4
|
+
strategies, with first-class support for footprint analysis and market
|
|
5
|
+
microstructure.
|
|
6
|
+
|
|
7
|
+
Write a strategy once and run it unchanged across **backtest**, **live** and
|
|
8
|
+
**replay** - the engine differences are a transport detail behind the same
|
|
9
|
+
`Strategy` API.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Backtesting engine** over candles or ticks with realistic order simulation.
|
|
14
|
+
- **Live trading** over WebSockets (CCXT Pro) and MetaTrader 5.
|
|
15
|
+
- **Order flow and footprint**: large trades, Deep Trades (L2/L3 absorption and
|
|
16
|
+
sweeps), cumulative delta, COT, volume profile and liquidity overlays.
|
|
17
|
+
- **Indicator library**: the classic studies plus market-structure tools, all
|
|
18
|
+
through one declarative contract.
|
|
19
|
+
- **Optimization and pools**, **Monte Carlo robustness** and interactive
|
|
20
|
+
**Bokeh plotting**.
|
|
21
|
+
- **Data management** with CSV/HDF5/Parquet IO and bundled sample datasets.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install tradear
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The base install includes everything for backtesting, plotting and data IO.
|
|
30
|
+
Broker integrations and Parquet are optional extras:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install tradear[mt5] # MetaTrader 5
|
|
34
|
+
pip install tradear[ccxt] # CCXT crypto exchanges (live + streaming)
|
|
35
|
+
pip install tradear[bybit] # Bybit (pybit)
|
|
36
|
+
pip install tradear[parquet] # Parquet IO (pyarrow)
|
|
37
|
+
pip install tradear[all] # all runtime extras
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
Every loader in `tradear.datasets` returns ready-to-use data, so this runs with
|
|
43
|
+
no data files or API keys:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from tradear import Strategy, BacktestEngine
|
|
47
|
+
from tradear.ta import SMA
|
|
48
|
+
from tradear.datasets import load_btcusd_1m
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class SmaCross(Strategy):
|
|
52
|
+
def init(self):
|
|
53
|
+
self.btc = self.subscribe_ohlc('BTCUSD', '1m', window_size=200)
|
|
54
|
+
self.fast = self.add_indicator(self.btc.close, SMA(10))
|
|
55
|
+
self.slow = self.add_indicator(self.btc.close, SMA(30))
|
|
56
|
+
|
|
57
|
+
def on_data(self):
|
|
58
|
+
if self.fast[-1] > self.slow[-1]:
|
|
59
|
+
if not self.sesh.positions('BTCUSD'):
|
|
60
|
+
self.sesh.buy('BTCUSD', volume=1)
|
|
61
|
+
else:
|
|
62
|
+
for pos in self.sesh.positions('BTCUSD'):
|
|
63
|
+
self.sesh.position_close(pos.ticket)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
engine = BacktestEngine.by_klines(SmaCross(), data=(load_btcusd_1m(),))
|
|
67
|
+
engine.run()
|
|
68
|
+
print(engine.stats)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
More runnable scripts are in [`examples/`](examples/).
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
Full documentation - user guide and API reference - is at
|
|
76
|
+
**https://michiTrader.github.io/tradear-pro/**.
|
|
77
|
+
|
|
78
|
+
- [Installation](https://michiTrader.github.io/tradear-pro/getting-started/installation/)
|
|
79
|
+
- [Quickstart](https://michiTrader.github.io/tradear-pro/getting-started/quickstart/)
|
|
80
|
+
- [Core concepts](https://michiTrader.github.io/tradear-pro/guide/concepts/)
|
|
81
|
+
- [Working with data](https://michiTrader.github.io/tradear-pro/guide/data/)
|
|
82
|
+
- [Indicators](https://michiTrader.github.io/tradear-pro/guide/indicators/) and
|
|
83
|
+
[Order flow and L2](https://michiTrader.github.io/tradear-pro/guide/order-flow/)
|
|
84
|
+
- [Live trading](https://michiTrader.github.io/tradear-pro/guide/live/),
|
|
85
|
+
[Replay](https://michiTrader.github.io/tradear-pro/guide/replay/) and
|
|
86
|
+
[Monte Carlo robustness](https://michiTrader.github.io/tradear-pro/guide/robustness/)
|
|
87
|
+
|
|
88
|
+
To build the docs locally:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install tradear[docs]
|
|
92
|
+
mkdocs serve
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Contributing
|
|
96
|
+
|
|
97
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Development setup:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
git clone https://github.com/michiTrader/tradear-pro.git
|
|
101
|
+
cd tradear-pro
|
|
102
|
+
uv sync
|
|
103
|
+
uv run pytest
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Risk disclaimer
|
|
107
|
+
|
|
108
|
+
Tradear is provided "AS IS", without warranty of any kind. Trading financial
|
|
109
|
+
instruments involves risk of loss of capital - you may lose part or all of your
|
|
110
|
+
funds. Always test first on a demo / testnet / paper account and verify that
|
|
111
|
+
orders, positions and balances behave as expected before trading with real
|
|
112
|
+
money. Broker and exchange APIs may change without notice and break a connector.
|
|
113
|
+
The authors and contributors are not responsible for any losses, damages or
|
|
114
|
+
execution failures arising from the use of this software. This is not financial,
|
|
115
|
+
investment or legal advice, and you are responsible for complying with the laws
|
|
116
|
+
of your jurisdiction and your broker/exchange terms of service.
|
|
117
|
+
|
|
118
|
+
The full disclaimer is available at runtime as `tradear.LIVE_DISCLAIMER`.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT - see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tradear"
|
|
3
|
+
version = "0.1.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 tradear` gives you the full
|
|
13
|
+
# backtesting, plotting, indicator and data-IO stack. Broker/venue integrations
|
|
14
|
+
# and Parquet IO are optional extras (see [project.optional-dependencies]).
|
|
15
|
+
dependencies = [
|
|
16
|
+
"bokeh>=3.8,<4",
|
|
17
|
+
"ipython>=9.10.0",
|
|
18
|
+
"keyboard>=0.13.5",
|
|
19
|
+
"numpy>=2.2.5",
|
|
20
|
+
"pandas>=3.0,<4",
|
|
21
|
+
"pintar>=0.7.3",
|
|
22
|
+
"plotext>=5.3.2",
|
|
23
|
+
"tables>=3.11.1",
|
|
24
|
+
"tqdm>=4.67.3",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
# Broker / venue connectors (each pulls only what that integration needs).
|
|
29
|
+
mt5 = ["MetaTrader5>=5.0.5488"]
|
|
30
|
+
ccxt = ["ccxt>=4.4.0"]
|
|
31
|
+
bybit = ["pybit>=5.7.0"]
|
|
32
|
+
|
|
33
|
+
# Optional Parquet support for tradear.io (read_*/save_* with format='parquet').
|
|
34
|
+
parquet = ["pyarrow>=17.0.0"]
|
|
35
|
+
|
|
36
|
+
# Everything above in one shot (runtime extras only; docs excluded).
|
|
37
|
+
all = [
|
|
38
|
+
"MetaTrader5>=5.0.5488",
|
|
39
|
+
"ccxt>=4.4.0",
|
|
40
|
+
"pybit>=5.7.0",
|
|
41
|
+
"pyarrow>=17.0.0",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
# Documentation site toolchain (MkDocs Material + API autodoc).
|
|
45
|
+
docs = [
|
|
46
|
+
"mkdocs-material>=9.5.0",
|
|
47
|
+
"mkdocstrings[python]>=0.26.0",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://github.com/michiTrader/tradear-pro"
|
|
52
|
+
Documentation = "https://michiTrader.github.io/tradear-pro/"
|
|
53
|
+
Repository = "https://github.com/michiTrader/tradear-pro"
|
|
54
|
+
|
|
55
|
+
# Development-only tooling (installed by `uv sync`, not shipped to users).
|
|
56
|
+
[dependency-groups]
|
|
57
|
+
dev = [
|
|
58
|
+
"pytest>=9.0.2",
|
|
59
|
+
"pytest-benchmark>=5.2.3",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[build-system]
|
|
63
|
+
requires = ["uv_build>=0.9.11,<0.10.0"]
|
|
64
|
+
build-backend = "uv_build"
|
|
65
|
+
|
|
66
|
+
# The bundled sample datasets in src/tradear/datasets/_data/ (*.hdf5, *.csv)
|
|
67
|
+
# live inside the module root, so the uv build backend includes them in both
|
|
68
|
+
# the sdist and the wheel automatically (only __pycache__/*.pyc are excluded).
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from tradear import exceptions
|
|
2
|
+
from tradear.backtest import BacktestEngine, PoolBacktestEngine
|
|
3
|
+
from tradear.live import LiveEngine
|
|
4
|
+
from tradear.connectors._disclaimer import LIVE_DISCLAIMER
|
|
5
|
+
from tradear.models import Strategy, FootprintConfig
|
|
6
|
+
from tradear.session import SeshSimulatorBase
|
|
7
|
+
from tradear.core import TickData, KlineData, parse_timeframe, TIMEFRAME_PRESETS
|
|
8
|
+
from tradear.stats import Stats, compute_stats
|
|
9
|
+
from tradear.plotting import plot, PlotConfig
|
|
10
|
+
from tradear.ta import (
|
|
11
|
+
Indicator,
|
|
12
|
+
IndicatorPlotConfig,
|
|
13
|
+
SMA,
|
|
14
|
+
EMA,
|
|
15
|
+
MACD,
|
|
16
|
+
RSI,
|
|
17
|
+
ATR,
|
|
18
|
+
BollingerBands,
|
|
19
|
+
VolumeProfile,
|
|
20
|
+
RollingVolumeProfile,
|
|
21
|
+
VolumeNode,
|
|
22
|
+
detect_volume_nodes,
|
|
23
|
+
ZigZag,
|
|
24
|
+
ConfirmedPivot,
|
|
25
|
+
PivotHighLow,
|
|
26
|
+
SwingHL,
|
|
27
|
+
EqualHL,
|
|
28
|
+
FairValueGap,
|
|
29
|
+
OrderBlock,
|
|
30
|
+
MarketSessions,
|
|
31
|
+
SessionLevels,
|
|
32
|
+
KillZones,
|
|
33
|
+
LargeTrades,
|
|
34
|
+
)
|