metatraderx 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.
- metatraderx-0.1.0/CHANGELOG.md +30 -0
- metatraderx-0.1.0/LICENSE +21 -0
- metatraderx-0.1.0/MANIFEST.in +7 -0
- metatraderx-0.1.0/PKG-INFO +133 -0
- metatraderx-0.1.0/README.md +87 -0
- metatraderx-0.1.0/metatraderx/__init__.py +82 -0
- metatraderx-0.1.0/metatraderx/__init__.pyi +580 -0
- metatraderx-0.1.0/metatraderx/__main__.py +9 -0
- metatraderx-0.1.0/metatraderx/_version.py +1 -0
- metatraderx-0.1.0/metatraderx/_worker.py +66 -0
- metatraderx-0.1.0/metatraderx/backends/__init__.py +7 -0
- metatraderx-0.1.0/metatraderx/backends/base.py +46 -0
- metatraderx-0.1.0/metatraderx/backends/mt4.py +290 -0
- metatraderx-0.1.0/metatraderx/backends/native.py +36 -0
- metatraderx-0.1.0/metatraderx/backends/remote.py +109 -0
- metatraderx-0.1.0/metatraderx/backends/wine.py +159 -0
- metatraderx-0.1.0/metatraderx/cache.py +80 -0
- metatraderx-0.1.0/metatraderx/cli.py +539 -0
- metatraderx-0.1.0/metatraderx/client.py +653 -0
- metatraderx-0.1.0/metatraderx/codec.py +152 -0
- metatraderx-0.1.0/metatraderx/config.py +75 -0
- metatraderx-0.1.0/metatraderx/constants.py +231 -0
- metatraderx-0.1.0/metatraderx/discovery.py +286 -0
- metatraderx-0.1.0/metatraderx/display.py +425 -0
- metatraderx-0.1.0/metatraderx/errors.py +46 -0
- metatraderx-0.1.0/metatraderx/export.py +94 -0
- metatraderx-0.1.0/metatraderx/installer.py +314 -0
- metatraderx-0.1.0/metatraderx/mql/MetaTraderXBridge.mq4 +269 -0
- metatraderx-0.1.0/metatraderx/offline.py +46 -0
- metatraderx-0.1.0/metatraderx/offline.pyi +551 -0
- metatraderx-0.1.0/metatraderx/py.typed +0 -0
- metatraderx-0.1.0/metatraderx/server.py +170 -0
- metatraderx-0.1.0/metatraderx/types.py +590 -0
- metatraderx-0.1.0/metatraderx/uninstall.py +250 -0
- metatraderx-0.1.0/metatraderx/util.py +38 -0
- metatraderx-0.1.0/metatraderx/wineenv.py +215 -0
- metatraderx-0.1.0/metatraderx.egg-info/PKG-INFO +133 -0
- metatraderx-0.1.0/metatraderx.egg-info/SOURCES.txt +42 -0
- metatraderx-0.1.0/metatraderx.egg-info/dependency_links.txt +1 -0
- metatraderx-0.1.0/metatraderx.egg-info/entry_points.txt +3 -0
- metatraderx-0.1.0/metatraderx.egg-info/requires.txt +21 -0
- metatraderx-0.1.0/metatraderx.egg-info/top_level.txt +1 -0
- metatraderx-0.1.0/pyproject.toml +94 -0
- metatraderx-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.0
|
|
6
|
+
- `import metatraderx as mt5` for Windows, Linux and macOS, with a local terminal backend (official package on Windows, an automatic Wine worker on Linux and macOS) and a remote backend for `mtx serve`.
|
|
7
|
+
- Added the `mtx` command: install, download, setup, terminal, login, info, symbols, symbol, fetch, serve, display, cache, config, mt4 and doctor.
|
|
8
|
+
- Added optional SQLite caching (`MTX_CACHE`) and offline mode (`import metatraderx.offline as mt5`, `MTX_OFFLINE`, `mtx --offline`) with `verbose` (bool or int, `MTX_VERBOSE`, `mtx -v`) notices.
|
|
9
|
+
- Added a read-only MetaTrader 4 bridge expert.
|
|
10
|
+
- Terminal search covers every drive on Windows and every Wine prefix with its mapped drives on Linux and macOS, plus `MTX_SEARCH` folders.
|
|
11
|
+
- `mtx symbols` lists names only by default, with `--first`, `--last` and `--full`.
|
|
12
|
+
- `mtx cache clear` asks for confirmation unless `-y` is given.
|
|
13
|
+
- `mtx display setup` installs Xpra, its HTML5 client and the other display requirements on Windows, Linux and macOS; `mtx display` offers it when something is missing.
|
|
14
|
+
- On Linux and macOS `initialize()` reports a missing `mtx setup` with a clear error (`SetupWarning`, or `SetupError` with `strict=True`) instead of a bare failure, and never falls back to cached data.
|
|
15
|
+
- Every public class, method and function has a docstring, and `__init__.pyi` / `offline.pyi` stubs (generated by `scripts/stubs.py`) give editors the signatures and docs of the module-level functions. Result records are typed `NamedTuple` classes with a description per field.
|
|
16
|
+
- Test suite covers the codec, cache, client, offline mode, server, remote, Wine and MT4 backends, discovery, installer, display and every `mtx` command.
|
|
17
|
+
- Documentation split into Python API, modes, server, display, command line, platforms, settings and troubleshooting, with the reference pages generated from the package.
|
|
18
|
+
- Added `mtx uninstall` and `metatraderx.uninstall` to remove a MetaTrader 4 or 5 terminal, including a broker's own build, with `--data`, `--prefix`, `--stop` and `--dry-run`.
|
|
19
|
+
- MetaTrader 4's `terminal.exe` is recognized as MetaTrader 4 and found after a headless install.
|
|
20
|
+
- Downloads are written to a `.part` file and renamed when complete, so an interrupted download is never reused.
|
|
21
|
+
- Headless Wine runs wait for, or stop, Wine's leftover processes before closing the virtual screen, which removes the "X connection broken" messages.
|
|
22
|
+
- `mtx setup` uses any Windows Python it finds in the Wine prefix, wherever it is installed, preferring one that already has MetaTrader5. When there is none, or MetaTrader5 cannot be installed into it, Python 3.12 is installed.
|
|
23
|
+
- `mtx install` on Linux installs headless by default: the Windows installer runs silently under Wine on a virtual screen, then the terminal it starts is stopped. `--method script` keeps the official MetaQuotes script.
|
|
24
|
+
- Added the `winedebug` setting (`MTX_WINEDEBUG`, `mtx --winedebug LEVEL`) with the levels `all`, `fixme` and `off`.
|
|
25
|
+
- `mtx display setup` adds the official xpra.org repository on Debian and Ubuntu and keeps it only when its packages install on the system; when xpra.org has no repository for the release (such as Ubuntu 25.04) or its packages do not fit, nearby releases are tried and a repository that does not fit is replaced.
|
|
26
|
+
- `mtx display` uses the first free port from 14500 when `--port` is not given, and reports a requested port that is in use.
|
|
27
|
+
- `mtx display` on Linux writes the terminal output to `logs/terminal.log` in the MetaTraderX home, refuses to start when the terminal is already running, and says where the log is when the terminal exits right away.
|
|
28
|
+
- Added `mtx display --force`, which closes a running terminal and anything else in its Wine prefix before the display starts, and `mtx serve` uses the first free port from 8765 when `--port` is not given.
|
|
29
|
+
- `mtx display` starts Xpra without an input method daemon, which stopped leaving `ibus-daemon` running after the display closed.
|
|
30
|
+
- Installer scripts and downloads run from and are saved in the MetaTraderX downloads folder instead of the current directory.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bradley Odimmasi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: metatraderx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal MetaTrader 5 and MetaTrader 4 Python API for Windows, Linux and macOS
|
|
5
|
+
Author: Bradley Odimmasi
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/KshRaven/metatraderx
|
|
8
|
+
Project-URL: Documentation, https://kshraven.github.io/metatraderx/
|
|
9
|
+
Project-URL: Source, https://github.com/KshRaven/metatraderx
|
|
10
|
+
Project-URL: Issues, https://github.com/KshRaven/metatraderx/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/KshRaven/metatraderx/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: metatrader,metatrader5,mt5,mt4,trading,forex,wine,linux
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: numpy>=1.21
|
|
31
|
+
Requires-Dist: MetaTrader5>=5.0.45; sys_platform == "win32"
|
|
32
|
+
Provides-Extra: pandas
|
|
33
|
+
Requires-Dist: pandas>=1.5; extra == "pandas"
|
|
34
|
+
Provides-Extra: docs
|
|
35
|
+
Requires-Dist: mkdocs<2,>=1.6; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
37
|
+
Provides-Extra: build
|
|
38
|
+
Requires-Dist: build>=1.0; extra == "build"
|
|
39
|
+
Requires-Dist: twine>=5.0; extra == "build"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: metatraderx[build,pandas]; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
44
|
+
Requires-Dist: ruff; extra == "dev"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# MetaTraderX
|
|
48
|
+
|
|
49
|
+
A universal MetaTrader 5 and MetaTrader 4 Python API for Windows, Linux and macOS. `import metatraderx as mt5` works
|
|
50
|
+
like `import MetaTrader5 as mt5`, with the same functions, constants and result types.
|
|
51
|
+
|
|
52
|
+
On Windows it drives the installed terminal through the official package. On Linux and macOS the terminal is the Wine
|
|
53
|
+
build MetaQuotes ships; MetaTraderX starts a worker inside the same Wine prefix and talks to it over an authenticated
|
|
54
|
+
loopback socket. The worker starts and stops with your program, so no RPyC server, container or separate process has to
|
|
55
|
+
be run by hand.
|
|
56
|
+
|
|
57
|
+
A device with no terminal can use the same API against a running `mtx serve` on another machine.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
pip install metatraderx
|
|
63
|
+
mtx install # MetaTrader 5; `mtx install 4` for MetaTrader 4
|
|
64
|
+
mtx setup # Linux and macOS: Wine, Windows Python and the MetaTrader5 package
|
|
65
|
+
mtx terminal list
|
|
66
|
+
mtx terminal select 0
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Broker builds with a custom executable are found too, and any executable can be selected by path.
|
|
70
|
+
|
|
71
|
+
## Use
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import metatraderx as mt5
|
|
75
|
+
|
|
76
|
+
if not mt5.initialize(login=12345678, password="...", server="Broker-Demo"):
|
|
77
|
+
raise SystemExit(mt5.last_error())
|
|
78
|
+
|
|
79
|
+
print(mt5.account_info())
|
|
80
|
+
print(mt5.to_frame(mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_H1, 0, 500)))
|
|
81
|
+
mt5.shutdown()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
A specific terminal or a server, with the `MetaTrader` class:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import metatraderx as mtx
|
|
88
|
+
|
|
89
|
+
mt = mtx.MetaTrader(terminal="/home/me/.mt5/drive_c/Program Files/MetaTrader 5/terminal64.exe")
|
|
90
|
+
mt = mtx.MetaTrader(url="mtx://trading-box:8765", token="...")
|
|
91
|
+
mt.initialize()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Command line
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
mtx symbols --first 20
|
|
98
|
+
mtx fetch rates EURUSD --tf M15 --from 2025-01-01 --to 2025-02-01 -o eurusd.csv
|
|
99
|
+
mtx fetch deals --from -30d -o deals.json
|
|
100
|
+
mtx serve --host 0.0.0.0 --auth auto --read-only
|
|
101
|
+
mtx display --tunnel
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The command line has no trading commands.
|
|
105
|
+
|
|
106
|
+
## Documentation
|
|
107
|
+
|
|
108
|
+
https://kshraven.github.io/metatraderx/
|
|
109
|
+
|
|
110
|
+
| | |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| [Installation](docs/install.md) | terminal, Wine and package setup |
|
|
113
|
+
| [Python API](docs/python/index.md) | functions, constants, result types, the `MetaTrader` class |
|
|
114
|
+
| [Cache](docs/modes/cache.md), [Offline mode](docs/modes/offline.md), [Verbosity](docs/modes/verbosity.md) | keeping data and working without a terminal |
|
|
115
|
+
| [Server](docs/server/hosting.md) and [clients](docs/server/clients.md) | sharing a terminal |
|
|
116
|
+
| [Terminal display](docs/display.md) | the terminal window in a browser |
|
|
117
|
+
| [Command line](docs/cli/index.md) | every `mtx` command |
|
|
118
|
+
| [Platforms](docs/platforms/windows.md) | Windows, Linux, macOS, MetaTrader 4 |
|
|
119
|
+
| [Settings](docs/reference/environment.md) | environment variables and saved settings |
|
|
120
|
+
|
|
121
|
+
## MetaTrader 4
|
|
122
|
+
|
|
123
|
+
MetaTrader 4 has no Python API. Read-only data (account, symbols, rates, positions, deal history) is available through
|
|
124
|
+
the bundled `MetaTraderXBridge` expert, which is experimental. See [MetaTrader 4](docs/platforms/mt4.md).
|
|
125
|
+
|
|
126
|
+
## Notice
|
|
127
|
+
|
|
128
|
+
MetaTraderX is an independent project and is not affiliated with or endorsed by MetaQuotes Ltd. MetaTrader is a
|
|
129
|
+
trademark of MetaQuotes Ltd. Trading carries risk, and the software is provided as is under the licence below.
|
|
130
|
+
|
|
131
|
+
## Licence
|
|
132
|
+
|
|
133
|
+
MIT
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# MetaTraderX
|
|
2
|
+
|
|
3
|
+
A universal MetaTrader 5 and MetaTrader 4 Python API for Windows, Linux and macOS. `import metatraderx as mt5` works
|
|
4
|
+
like `import MetaTrader5 as mt5`, with the same functions, constants and result types.
|
|
5
|
+
|
|
6
|
+
On Windows it drives the installed terminal through the official package. On Linux and macOS the terminal is the Wine
|
|
7
|
+
build MetaQuotes ships; MetaTraderX starts a worker inside the same Wine prefix and talks to it over an authenticated
|
|
8
|
+
loopback socket. The worker starts and stops with your program, so no RPyC server, container or separate process has to
|
|
9
|
+
be run by hand.
|
|
10
|
+
|
|
11
|
+
A device with no terminal can use the same API against a running `mtx serve` on another machine.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
pip install metatraderx
|
|
17
|
+
mtx install # MetaTrader 5; `mtx install 4` for MetaTrader 4
|
|
18
|
+
mtx setup # Linux and macOS: Wine, Windows Python and the MetaTrader5 package
|
|
19
|
+
mtx terminal list
|
|
20
|
+
mtx terminal select 0
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Broker builds with a custom executable are found too, and any executable can be selected by path.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import metatraderx as mt5
|
|
29
|
+
|
|
30
|
+
if not mt5.initialize(login=12345678, password="...", server="Broker-Demo"):
|
|
31
|
+
raise SystemExit(mt5.last_error())
|
|
32
|
+
|
|
33
|
+
print(mt5.account_info())
|
|
34
|
+
print(mt5.to_frame(mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_H1, 0, 500)))
|
|
35
|
+
mt5.shutdown()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
A specific terminal or a server, with the `MetaTrader` class:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
import metatraderx as mtx
|
|
42
|
+
|
|
43
|
+
mt = mtx.MetaTrader(terminal="/home/me/.mt5/drive_c/Program Files/MetaTrader 5/terminal64.exe")
|
|
44
|
+
mt = mtx.MetaTrader(url="mtx://trading-box:8765", token="...")
|
|
45
|
+
mt.initialize()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Command line
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
mtx symbols --first 20
|
|
52
|
+
mtx fetch rates EURUSD --tf M15 --from 2025-01-01 --to 2025-02-01 -o eurusd.csv
|
|
53
|
+
mtx fetch deals --from -30d -o deals.json
|
|
54
|
+
mtx serve --host 0.0.0.0 --auth auto --read-only
|
|
55
|
+
mtx display --tunnel
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The command line has no trading commands.
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
https://kshraven.github.io/metatraderx/
|
|
63
|
+
|
|
64
|
+
| | |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| [Installation](docs/install.md) | terminal, Wine and package setup |
|
|
67
|
+
| [Python API](docs/python/index.md) | functions, constants, result types, the `MetaTrader` class |
|
|
68
|
+
| [Cache](docs/modes/cache.md), [Offline mode](docs/modes/offline.md), [Verbosity](docs/modes/verbosity.md) | keeping data and working without a terminal |
|
|
69
|
+
| [Server](docs/server/hosting.md) and [clients](docs/server/clients.md) | sharing a terminal |
|
|
70
|
+
| [Terminal display](docs/display.md) | the terminal window in a browser |
|
|
71
|
+
| [Command line](docs/cli/index.md) | every `mtx` command |
|
|
72
|
+
| [Platforms](docs/platforms/windows.md) | Windows, Linux, macOS, MetaTrader 4 |
|
|
73
|
+
| [Settings](docs/reference/environment.md) | environment variables and saved settings |
|
|
74
|
+
|
|
75
|
+
## MetaTrader 4
|
|
76
|
+
|
|
77
|
+
MetaTrader 4 has no Python API. Read-only data (account, symbols, rates, positions, deal history) is available through
|
|
78
|
+
the bundled `MetaTraderXBridge` expert, which is experimental. See [MetaTrader 4](docs/platforms/mt4.md).
|
|
79
|
+
|
|
80
|
+
## Notice
|
|
81
|
+
|
|
82
|
+
MetaTraderX is an independent project and is not affiliated with or endorsed by MetaQuotes Ltd. MetaTrader is a
|
|
83
|
+
trademark of MetaQuotes Ltd. Trading carries risk, and the software is provided as is under the licence below.
|
|
84
|
+
|
|
85
|
+
## Licence
|
|
86
|
+
|
|
87
|
+
MIT
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""MetaTraderX: `import metatraderx as mt5` works like `import MetaTrader5 as mt5` on Windows, Linux and macOS."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ._version import __version__
|
|
8
|
+
from .backends.base import API
|
|
9
|
+
from .client import MetaTrader
|
|
10
|
+
from .constants import * # noqa: F403
|
|
11
|
+
from .constants import _export
|
|
12
|
+
from .errors import (
|
|
13
|
+
AuthError,
|
|
14
|
+
BackendError,
|
|
15
|
+
MTXError,
|
|
16
|
+
NotConnected,
|
|
17
|
+
RemoteError,
|
|
18
|
+
SetupError,
|
|
19
|
+
SetupWarning,
|
|
20
|
+
TerminalNotFound,
|
|
21
|
+
)
|
|
22
|
+
from .types import (
|
|
23
|
+
AccountInfo,
|
|
24
|
+
BookInfo,
|
|
25
|
+
OrderCheckResult,
|
|
26
|
+
OrderSendResult,
|
|
27
|
+
SymbolInfo,
|
|
28
|
+
TerminalInfo,
|
|
29
|
+
Tick,
|
|
30
|
+
TradeDeal,
|
|
31
|
+
TradeOrder,
|
|
32
|
+
TradePosition,
|
|
33
|
+
TradeRequest,
|
|
34
|
+
)
|
|
35
|
+
from .util import to_frame
|
|
36
|
+
from .wineenv import setup_problems
|
|
37
|
+
|
|
38
|
+
MetaTraderX = MetaTrader
|
|
39
|
+
|
|
40
|
+
_default = MetaTrader() # MTX_OFFLINE=1 makes this instance offline
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def default() -> MetaTrader:
|
|
44
|
+
"""The instance behind the module-level functions."""
|
|
45
|
+
return _default
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def set_default(instance: MetaTrader) -> MetaTrader:
|
|
49
|
+
"""Make an existing instance the one behind the module-level functions and return it."""
|
|
50
|
+
global _default
|
|
51
|
+
_default = instance
|
|
52
|
+
return instance
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def configure(**kwargs: Any) -> MetaTrader:
|
|
56
|
+
"""Replace the default instance, e.g. configure(url="mtx://host:8765", token="...", cache=True) or configure(offline=True, verbose=1)."""
|
|
57
|
+
return set_default(MetaTrader(**kwargs))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _bind(name: str) -> Any:
|
|
61
|
+
def fn(*args: Any, **kwargs: Any) -> Any:
|
|
62
|
+
return getattr(_default, name)(*args, **kwargs)
|
|
63
|
+
|
|
64
|
+
fn.__name__ = name
|
|
65
|
+
fn.__doc__ = getattr(MetaTrader, name).__doc__
|
|
66
|
+
return fn
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
EXTRAS = ("symbol_names", "to_frame")
|
|
70
|
+
|
|
71
|
+
for _n in (*API, "symbol_names"):
|
|
72
|
+
globals()[_n] = _bind(_n)
|
|
73
|
+
|
|
74
|
+
__all__ = sorted(
|
|
75
|
+
[
|
|
76
|
+
"__version__", "MetaTrader", "MetaTraderX", "default", "set_default", "configure", "to_frame", "symbol_names",
|
|
77
|
+
"MTXError", "BackendError", "NotConnected", "TerminalNotFound", "SetupError", "SetupWarning", "RemoteError",
|
|
78
|
+
"AuthError", "setup_problems",
|
|
79
|
+
"AccountInfo", "BookInfo", "OrderCheckResult", "OrderSendResult", "SymbolInfo", "TerminalInfo", "Tick",
|
|
80
|
+
"TradeDeal", "TradeOrder", "TradePosition", "TradeRequest", *API, *_export(),
|
|
81
|
+
]
|
|
82
|
+
) # fmt: skip
|