mt5-mac 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.
mt5_mac-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdul Rafay Jiwani
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.
mt5_mac-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,369 @@
1
+ Metadata-Version: 2.4
2
+ Name: mt5_mac
3
+ Version: 0.1.0
4
+ Summary: MetaTrader 5 native Python library for macOS - control MT5 from Python scripts
5
+ Author: Abdul Rafay Jiwani
6
+ Author-email: Abdul Rafay Jiwani <abdulrafayjiwani@proton.me>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/AbdulRafayJiwani/mt5_mac
9
+ Project-URL: Repository, https://github.com/AbdulRafayJiwani/mt5_mac
10
+ Keywords: mt5,metatrader5,trading,forex,macos,metatrader
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Office/Business :: Financial :: Investment
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Dynamic: author
27
+ Dynamic: license-file
28
+ Dynamic: requires-python
29
+
30
+ <p align="center">
31
+ <img src="https://img.shields.io/pypi/v/mt5-mac" alt="PyPI">
32
+ <img src="https://img.shields.io/pypi/l/mt5-mac" alt="License">
33
+ <img src="https://img.shields.io/pypi/pyversions/mt5-mac" alt="Python">
34
+ <img src="https://img.shields.io/badge/platform-macOS-blue" alt="Platform">
35
+ </p>
36
+
37
+ # mt5_mac
38
+
39
+ **MetaTrader 5 native Python library for macOS.**
40
+
41
+ Control MetaTrader 5 installed on your Mac directly from Python — no Windows, no remote servers, no Docker. Uses the Wine runtime bundled inside MetaTrader 5.app to run the official `MetaTrader5` Python package.
42
+
43
+ ## Features
44
+
45
+ - Full API matching the official [MetaTrader5](https://pypi.org/project/MetaTrader5/) package
46
+ - Account info, tick data, historical rates, symbols
47
+ - Market orders, position management, pending orders
48
+ - Deal history and order history
49
+ - Auto-setup — downloads Python + dependencies on first use
50
+ - No Windows, no Docker, no remote servers needed
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install mt5_mac
56
+ ```
57
+
58
+ ## Requirements
59
+
60
+ - **macOS** (Intel or Apple Silicon)
61
+ - **MetaTrader 5** for macOS installed from [metatrader5.com](https://www.metatrader5.com/en/download)
62
+ - **Python 3.9+**
63
+
64
+ On first use, the library automatically downloads Python 3.9 for Windows and installs the `MetaTrader5` pip package inside MT5's bundled Wine environment. An internet connection is required for this one-time setup (~8 MB download).
65
+
66
+ ## Quick Start
67
+
68
+ ```python
69
+ import mt5_mac as mt5
70
+
71
+ # Initialize
72
+ if not mt5.initialize():
73
+ print("initialize() failed - is MetaTrader 5 installed?")
74
+ quit()
75
+
76
+ # Login
77
+ if not mt5.login(12345678, "your_password", "YourBroker-Server"):
78
+ print("login() failed - check your credentials")
79
+ mt5.shutdown()
80
+ quit()
81
+
82
+ # Account info
83
+ info = mt5.account_info()
84
+ print(f"Balance: {info.balance:.2f} {info.currency}")
85
+ print(f"Equity: {info.equity:.2f}")
86
+ print(f"Leverage: 1:{info.leverage}")
87
+
88
+ # Live tick data
89
+ tick = mt5.symbol_info_tick("EURUSD")
90
+ print(f"EURUSD: bid={tick.bid} ask={tick.ask}")
91
+
92
+ # Historical rates
93
+ rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_M1, 0, 10)
94
+ for r in rates:
95
+ print(f"[{r.time}] O={r.open} H={r.high} L={r.low} C={r.close}")
96
+
97
+ # Open positions
98
+ positions = mt5.positions_get()
99
+ print(f"Open positions: {len(positions) if positions else 0}")
100
+
101
+ # Place a market order
102
+ symbol = "EURUSD"
103
+ tick = mt5.symbol_info_tick(symbol)
104
+ request = {
105
+ "action": mt5.TRADE_ACTION_DEAL,
106
+ "symbol": symbol,
107
+ "volume": 0.01,
108
+ "type": mt5.ORDER_TYPE_BUY,
109
+ "price": tick.ask,
110
+ "sl": tick.ask - 0.0050,
111
+ "tp": tick.ask + 0.0100,
112
+ "deviation": 10,
113
+ "magic": 123456,
114
+ "comment": "mt5_mac",
115
+ "type_time": mt5.ORDER_TIME_GTC,
116
+ "type_filling": mt5.ORDER_FILLING_IOC,
117
+ }
118
+ result = mt5.order_send(request)
119
+ if result.retcode == mt5.RES_E_SUCCESS:
120
+ print(f"Order placed: #{result.order} @ {result.price}")
121
+ else:
122
+ print(f"Order failed: retcode={result.retcode}")
123
+
124
+ # Cleanup
125
+ mt5.shutdown()
126
+ ```
127
+
128
+ ## Complete API Reference
129
+
130
+ ### Initialization & Connection
131
+
132
+ | Function | Description |
133
+ |----------|-------------|
134
+ | `initialize(path=None, login=None, password=None, server="", quiet=False)` | Initialize connection to MT5 terminal. Optionally log in directly. |
135
+ | `shutdown()` | Disconnect from MT5 and release resources. |
136
+ | `login(login_id, password, server="")` | Log in to a trading account. |
137
+ | `last_error()` | Get the last error code (always 0 in current version). |
138
+
139
+ ### Account & Market Data
140
+
141
+ | Function | Returns | Description |
142
+ |----------|---------|-------------|
143
+ | `account_info()` | `MqlAccountInfo` | Balance, equity, margin, leverage, server, etc. |
144
+ | `symbols_get(symbol=None)` | `tuple[MqlSymbolInfo]` | All available symbols, or filter by name. |
145
+ | `symbol_info(symbol)` | `MqlSymbolInfo` | Detailed symbol specifications (spread, digits, etc.). |
146
+ | `symbol_info_tick(symbol)` | `MqlTick` | Latest tick: bid, ask, last, volume, time. |
147
+ | `symbol_select(symbol, enable=True)` | `bool` | Add/remove symbol from MarketWatch. |
148
+
149
+ ### Historical Data
150
+
151
+ | Function | Returns | Description |
152
+ |----------|---------|-------------|
153
+ | `copy_rates_from_pos(symbol, tf, start, count)` | `tuple[MqlRates]` | Rates starting from a position index. |
154
+ | `copy_rates_from(symbol, tf, date_from, count)` | `tuple[MqlRates]` | Rates starting from a date (Unix timestamp). |
155
+ | `copy_rates_range(symbol, tf, date_from, date_to)` | `tuple[MqlRates]` | Rates for a date range. |
156
+
157
+ ### Trading
158
+
159
+ | Function | Returns | Description |
160
+ |----------|---------|-------------|
161
+ | `order_send(request)` | `MqlTradeResult` | Place/modify/close orders. |
162
+ | `positions_get(symbol="")` | `tuple[MqlPosition]` | Get open positions, optionally filtered by symbol. |
163
+ | `orders_get(symbol="")` | `tuple[MqlOrder]` | Get pending orders, optionally filtered by symbol. |
164
+ | `history_deals_get(from=0, to=0)` | `tuple[MqlDeal]` | Get deal history. |
165
+ | `history_orders_get(from=0, to=0)` | `tuple[MqlOrder]` | Get order history. |
166
+
167
+ ### Constants
168
+
169
+ **Timeframes:** `TIMEFRAME_M1`, `M5`, `M15`, `M30`, `H1`, `H4`, `D1`, `W1`, `MN1`
170
+
171
+ **Order Types:** `ORDER_TYPE_BUY`, `ORDER_TYPE_SELL`, `ORDER_TYPE_BUY_LIMIT`, `ORDER_TYPE_SELL_LIMIT`, `ORDER_TYPE_BUY_STOP`, `ORDER_TYPE_SELL_STOP`
172
+
173
+ **Trade Actions:** `TRADE_ACTION_DEAL`, `TRADE_ACTION_PENDING`, `TRADE_ACTION_SLTP`, `TRADE_ACTION_MODIFY`, `TRADE_ACTION_REMOVE`
174
+
175
+ **Order Fillings:** `ORDER_FILLING_FOK`, `ORDER_FILLING_IOC`, `ORDER_FILLING_RETURN`
176
+
177
+ **Order Times:** `ORDER_TIME_GTC`, `ORDER_TIME_DAY`, `ORDER_TIME_SPECIFIED`
178
+
179
+ ### Data Classes
180
+
181
+ **`MqlTick`:** `time`, `bid`, `ask`, `last`, `volume`, `time_msc`, `flags`, `volume_real`
182
+
183
+ **`MqlRates`:** `time`, `open`, `high`, `low`, `close`, `tick_volume`, `spread`, `real_volume`
184
+
185
+ **`MqlAccountInfo`:** `login`, `trade_mode`, `leverage`, `balance`, `credit`, `profit`, `equity`, `margin`, `margin_free`, `margin_level`, `name`, `server`, `currency`, `company`
186
+
187
+ **`MqlTradeResult`:** `retcode`, `deal`, `order`, `volume`, `price`, `bid`, `ask`, `comment`, `request_id`
188
+
189
+ **`MqlPosition`:** `ticket`, `time`, `type`, `magic`, `identifier`, `symbol`, `volume`, `price_open`, `sl`, `tp`, `price_current`, `swap`, `profit`
190
+
191
+ **`MqlOrder`:** `ticket`, `time_setup`, `type`, `state`, `magic`, `symbol`, `volume_current`, `volume_initial`, `price_open`, `sl`, `tp`, `price_current`, `comment`
192
+
193
+ **`MqlDeal`:** `ticket`, `order`, `time`, `type`, `entry`, `magic`, `position`, `symbol`, `volume`, `price`, `commission`, `swap`, `profit`, `fee`
194
+
195
+ **`MqlSymbolInfo`:** `name`, `digits`, `spread`, `point`, `trade_mode`, `bid`, `ask`, `volume_min`, `volume_max`, `volume_step`, `contract_size`, `currency_base`, `currency_profit`, `description`, `path`
196
+
197
+ ## How It Works
198
+
199
+ MetaTrader 5 for macOS is the Windows version of MT5 running inside a bundled Wine (CrossOver) wrapper.
200
+
201
+ ```
202
+ ┌─────────────────────────────────────────────────┐
203
+ │ Your Python Script (macOS) │
204
+ │ import mt5_mac as mt5 │
205
+ │ mt5.initialize() │
206
+ │ mt5.login(123, "pwd", "server") │
207
+ │ info = mt5.account_info() │
208
+ │ mt5.shutdown() │
209
+ └──────────────┬──────────────────────────────────┘
210
+ │ JSON over stdin/stdout
211
+
212
+ ┌─────────────────────────────────────────────────┐
213
+ │ Wine Subprocess (inside MT5.app's bundled Wine) │
214
+ │ Python 3.9 for Windows │
215
+ │ import MetaTrader5 as mt5 │
216
+ │ mt5.initialize(path=...) │
217
+ │ mt5.login(...) │
218
+ │ mt5.account_info() │
219
+ └──────────────┬──────────────────────────────────┘
220
+ │ MT5 API
221
+
222
+ ┌─────────────────────────────────────────────────┐
223
+ │ MetaTrader 5 Terminal (Windows binary in Wine) │
224
+ │ terminal64.exe │
225
+ │ Connected to broker │
226
+ └─────────────────────────────────────────────────┘
227
+ ```
228
+
229
+ ### First-Run Setup
230
+
231
+ On the very first call to `initialize()`, the library:
232
+
233
+ 1. Locates `MetaTrader 5.app` in `/Applications`
234
+ 2. Finds the bundled Wine binaries
235
+ 3. Downloads **Python 3.9 embeddable for Windows** (~8 MB) from python.org
236
+ 4. Extracts it to the appropriate Wine prefix
237
+ 5. Installs **pip** and the **MetaTrader5** package
238
+ 6. Launches the agent and connects to MT5
239
+
240
+ This setup happens once. Subsequent connections are instant.
241
+
242
+ ## Project Structure
243
+
244
+ ```
245
+ mt5_mac/
246
+ ├── mt5_mac/
247
+ │ ├── __init__.py # Top-level API (initialize, login, order_send, etc.)
248
+ │ ├── agent.py # Agent script that runs inside Wine
249
+ │ ├── backend.py # Wine subprocess communication + auto-bootstrap
250
+ │ ├── bootstrap.py # Auto-download Python & MetaTrader5 in Wine
251
+ │ └── types.py # Data classes (MqlTick, MqlRates, etc.)
252
+ ├── examples/
253
+ │ ├── basic.py # Basic usage example
254
+ │ ├── streaming.py # Real-time tick streaming
255
+ │ └── trading.py # Market order placement
256
+ ├── pyproject.toml # Package configuration
257
+ ├── setup.py # Legacy setup for older pip
258
+ ├── LICENSE # MIT License
259
+ └── README.md # This file
260
+ ```
261
+
262
+ ## Example Scripts
263
+
264
+ ### Basic: `examples/basic.py`
265
+
266
+ ```python
267
+ import mt5_mac as mt5
268
+
269
+ mt5.initialize()
270
+ mt5.login(12345678, "password", "Broker-Server")
271
+
272
+ info = mt5.account_info()
273
+ print(f"{info.login} @ {info.server} | ${info.balance:.2f}")
274
+
275
+ tick = mt5.symbol_info_tick("EURUSD")
276
+ print(f"EURUSD: bid={tick.bid} ask={tick.ask}")
277
+
278
+ mt5.shutdown()
279
+ ```
280
+
281
+ ### Streaming: `examples/streaming.py`
282
+
283
+ ```python
284
+ import time
285
+ import mt5_mac as mt5
286
+
287
+ mt5.initialize()
288
+ mt5.login(12345678, "password", "Broker-Server")
289
+
290
+ symbols = ["EURUSD", "GBPUSD", "USDJPY"]
291
+ for sym in symbols:
292
+ mt5.symbol_select(sym, True)
293
+
294
+ try:
295
+ while True:
296
+ for sym in symbols:
297
+ tick = mt5.symbol_info_tick(sym)
298
+ if tick:
299
+ print(f"{sym}: {tick.bid:.5f} / {tick.ask:.5f}")
300
+ time.sleep(1)
301
+ except KeyboardInterrupt:
302
+ pass
303
+ finally:
304
+ mt5.shutdown()
305
+ ```
306
+
307
+ ### Trading: `examples/trading.py`
308
+
309
+ ```python
310
+ import mt5_mac as mt5
311
+
312
+ mt5.initialize()
313
+ mt5.login(12345678, "password", "Broker-Server")
314
+
315
+ tick = mt5.symbol_info_tick("EURUSD")
316
+ if not tick:
317
+ quit()
318
+
319
+ request = {
320
+ "action": mt5.TRADE_ACTION_DEAL,
321
+ "symbol": "EURUSD",
322
+ "volume": 0.01,
323
+ "type": mt5.ORDER_TYPE_BUY,
324
+ "price": tick.ask,
325
+ "sl": tick.ask - 0.0050,
326
+ "tp": tick.ask + 0.0100,
327
+ "deviation": 10,
328
+ "magic": 123456,
329
+ "comment": "mt5_mac",
330
+ "type_time": mt5.ORDER_TIME_GTC,
331
+ "type_filling": mt5.ORDER_FILLING_IOC,
332
+ }
333
+ result = mt5.order_send(request)
334
+ print(f"Order: #{result.order} retcode={result.retcode}")
335
+
336
+ mt5.shutdown()
337
+ ```
338
+
339
+ ## Troubleshooting
340
+
341
+ ### "MetaTrader 5.app not found"
342
+
343
+ Download and install MetaTrader 5 from [metatrader5.com](https://www.metatrader5.com/en/download). After installation, the app should be at `/Applications/MetaTrader 5.app`.
344
+
345
+ ### "Failed to download Python"
346
+
347
+ The first run downloads Python 3.9 embeddable for Windows (~8 MB). Check your internet connection. The download is cached after extraction.
348
+
349
+ ### "Login failed"
350
+
351
+ Verify your account credentials (login ID, password, server name). Some brokers require the full server name (e.g. `Exness-MT5Trial15`, not just `Exness`).
352
+
353
+ ### "Empty response from backend"
354
+
355
+ This usually means the MT5 terminal couldn't start inside Wine. Try launching `MetaTrader 5.app` manually once, let it fully load, then try again.
356
+
357
+ ## License
358
+
359
+ MIT License — see [LICENSE](LICENSE) for details.
360
+
361
+ ## Author
362
+
363
+ **Abdul Rafay Jiwani**
364
+
365
+ ---
366
+
367
+ <p align="center">
368
+ <sub>Built for macOS · No Windows required · No Docker · No remote servers</sub>
369
+ </p>