pmt5api 1.0.0__py3-none-any.whl
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.
- pmt5api/__init__.py +34 -0
- pmt5api/__main__.py +78 -0
- pmt5api/_account.py +146 -0
- pmt5api/_base.py +24 -0
- pmt5api/_coverage.py +216 -0
- pmt5api/_events.py +147 -0
- pmt5api/_market.py +296 -0
- pmt5api/_native/CHANGELOG.md +284 -0
- pmt5api/_native/THIRD-PARTY-NOTICES.txt +92 -0
- pmt5api/_native/docs/ERRORS.md +143 -0
- pmt5api/_native/docs/LICENSING.md +67 -0
- pmt5api/_native/docs/SECURITY.md +50 -0
- pmt5api/_native/wmt5api.dll +0 -0
- pmt5api/_risk.py +116 -0
- pmt5api/_runtime.py +154 -0
- pmt5api/_session.py +175 -0
- pmt5api/_streams.py +238 -0
- pmt5api/_trading.py +367 -0
- pmt5api/_util.py +78 -0
- pmt5api/bars.py +98 -0
- pmt5api/client.py +129 -0
- pmt5api/diagnostics.py +38 -0
- pmt5api/docs/API.md +717 -0
- pmt5api/docs/FROM-CSHARP.md +131 -0
- pmt5api/errors.py +150 -0
- pmt5api/frames.py +21 -0
- pmt5api/models.py +522 -0
- pmt5api/py.typed +0 -0
- pmt5api/servers.py +73 -0
- pmt5api-1.0.0.dist-info/METADATA +339 -0
- pmt5api-1.0.0.dist-info/RECORD +33 -0
- pmt5api-1.0.0.dist-info/WHEEL +4 -0
- pmt5api-1.0.0.dist-info/licenses/LICENSE.txt +29 -0
pmt5api/docs/API.md
ADDED
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
# pmt5api — API reference
|
|
2
|
+
|
|
3
|
+
Generated from the code (`tools/gen_docs.py`); do not edit by hand. Times are naive `datetime` values in the broker's server time. Every call that needs a connection raises `NotConnectedError` when there is none, and every error is a subclass of `pmt5api.WmtError`.
|
|
4
|
+
|
|
5
|
+
## Constructing a client
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
Client(login, password, host, port=443, *, api_key=None, token_url=None, dll_path=None, connect_timeout=None, cluster_member_timeout=None, token_timeout=None, execution_timeout=None, quote_timeout=None, history_timeout=None, bars_timeout=None, ping_interval=None, no_message_timeout=None, auto_reconnect=False, reconnect_backoff=None, reconnect_max_backoff=None, reconnect_max_attempts=None, proxy=None, certificate=None, certificate_password=None, common_key=None, placed_type=None, all_order_updates=False)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
A connection to one MetaTrader 5 account through the licensed core.
|
|
12
|
+
|
|
13
|
+
>>> with Client(login, password, host, port, api_key="wk_...") as c:
|
|
14
|
+
... print(c.quote("EURUSD"))
|
|
15
|
+
|
|
16
|
+
Credentials and library: `api_key` falls back to the `WMTAPI_KEY` environment variable and `token_url` to
|
|
17
|
+
`WMTAPI_TOKEN_URL` (the core reads both itself); `dll_path` falls back to `WMTAPI_DLL`, then to the core
|
|
18
|
+
bundled in the wheel.
|
|
19
|
+
|
|
20
|
+
Timeouts are in seconds: `connect_timeout` (one connect attempt on one server), `cluster_member_timeout` (the
|
|
21
|
+
per-server limit while failing over across the broker's cluster), `token_timeout` (each licence request), `execution_timeout` (a trade confirmation),
|
|
22
|
+
`quote_timeout` (waiting for a quote), `history_timeout` / `bars_timeout` (downloads), `ping_interval`
|
|
23
|
+
(keepalive), `no_message_timeout` (silence after which `connected` turns false). Every timeout must be
|
|
24
|
+
positive; the quote, history and bars timeouts are the defaults of `quote`, `history` and `bars`.
|
|
25
|
+
|
|
26
|
+
Reconnecting: `auto_reconnect=True` turns on the core's watchdog (exponential backoff with jitter, failover to the
|
|
27
|
+
broker's cluster members, re-subscription); tune it with `reconnect_backoff` / `reconnect_max_backoff` (seconds)
|
|
28
|
+
and `reconnect_max_attempts` (0 = until reconnected or `disconnect()`). Do not poll `connected` and call
|
|
29
|
+
`connect()` in a loop.
|
|
30
|
+
|
|
31
|
+
`proxy` routes the connection through a `Proxy`. `certificate` / `certificate_password` are for brokers
|
|
32
|
+
that require a client certificate (the bytes of a `.pfx` file); `common_key` (15 bytes) is for servers that
|
|
33
|
+
require one. `placed_type` records how orders are placed (`"manual"`
|
|
34
|
+
or `"expert"`; a per-call `placed_type="manual"` equals the default and so takes the client's value). `all_order_updates=True` also delivers the intermediate order states to
|
|
35
|
+
`on_order_update`.
|
|
36
|
+
|
|
37
|
+
Callbacks run on the core's worker threads, not on the thread that created the client.
|
|
38
|
+
|
|
39
|
+
## Connection and session
|
|
40
|
+
|
|
41
|
+
#### `account_method` *(property)*
|
|
42
|
+
|
|
43
|
+
`"Hedging"` or `"Netting"`.
|
|
44
|
+
|
|
45
|
+
#### `async aconnect()`
|
|
46
|
+
|
|
47
|
+
Awaitable `connect`; the blocking connect runs on a worker thread.
|
|
48
|
+
|
|
49
|
+
#### `async adisconnect()`
|
|
50
|
+
|
|
51
|
+
Awaitable `disconnect`.
|
|
52
|
+
|
|
53
|
+
#### `base_info()`
|
|
54
|
+
|
|
55
|
+
The server's own description of itself and of the account mode.
|
|
56
|
+
|
|
57
|
+
#### `can_trade` *(property)*
|
|
58
|
+
|
|
59
|
+
This login may place trades: not investor, not disabled on the server, confirmed.
|
|
60
|
+
|
|
61
|
+
#### `change_password(new_password, investor=False)`
|
|
62
|
+
|
|
63
|
+
Change the account password; with `investor=True` the read-only investor password instead of the main
|
|
64
|
+
one. The new password applies from the next connection.
|
|
65
|
+
|
|
66
|
+
#### `company` *(property)*
|
|
67
|
+
|
|
68
|
+
The broker's company name, as the server reports it.
|
|
69
|
+
|
|
70
|
+
#### `connect()`
|
|
71
|
+
|
|
72
|
+
Connect, authorise through the licence service and load the account. Returns `self`. Calling it on a
|
|
73
|
+
client that is already connected does nothing (it never opens a second session).
|
|
74
|
+
|
|
75
|
+
#### `connect_time` *(property)*
|
|
76
|
+
|
|
77
|
+
When this session connected, by the local clock.
|
|
78
|
+
|
|
79
|
+
#### `connected` *(property)*
|
|
80
|
+
|
|
81
|
+
Live: false when the socket died or the server has been silent past `no_message_timeout`.
|
|
82
|
+
|
|
83
|
+
#### `core_version` *(property)*
|
|
84
|
+
|
|
85
|
+
The version of the licensed core library in use.
|
|
86
|
+
|
|
87
|
+
#### `disconnect()`
|
|
88
|
+
|
|
89
|
+
Close the session and stop the core's reconnect watchdog for good — also when the link is down and the
|
|
90
|
+
watchdog is mid-way through reconnecting. Harmless when never connected.
|
|
91
|
+
|
|
92
|
+
#### `host` *(property)*
|
|
93
|
+
|
|
94
|
+
The access server this client was created for (it may fail over to a cluster member).
|
|
95
|
+
|
|
96
|
+
#### `is_confirmed` *(property)*
|
|
97
|
+
|
|
98
|
+
False while the broker has not yet confirmed the account (trading is blocked until it is).
|
|
99
|
+
|
|
100
|
+
#### `is_investor` *(property)*
|
|
101
|
+
|
|
102
|
+
The login is the read-only investor password.
|
|
103
|
+
|
|
104
|
+
#### `last_quote_time` *(property)*
|
|
105
|
+
|
|
106
|
+
The server timestamp of the last quote received (server time, not the local clock): compare it with
|
|
107
|
+
`server_time`, not with `datetime.now()`.
|
|
108
|
+
|
|
109
|
+
#### `last_server_message_time` *(property)*
|
|
110
|
+
|
|
111
|
+
When the server last sent anything, by the local clock: a liveness signal.
|
|
112
|
+
|
|
113
|
+
#### `login` *(property)*
|
|
114
|
+
|
|
115
|
+
The account login number.
|
|
116
|
+
|
|
117
|
+
#### `port` *(property)*
|
|
118
|
+
|
|
119
|
+
The access-server port.
|
|
120
|
+
|
|
121
|
+
#### `raw` *(property)*
|
|
122
|
+
|
|
123
|
+
The underlying core object, for anything this layer does not wrap. Calls made on it raise the core's own
|
|
124
|
+
exceptions, not pmt5api's.
|
|
125
|
+
|
|
126
|
+
#### `server_time` *(property)*
|
|
127
|
+
|
|
128
|
+
The server's clock, kept current by incoming quotes (server time, naive); `None` before the first
|
|
129
|
+
connect.
|
|
130
|
+
|
|
131
|
+
#### `server_utc_offset` *(property)*
|
|
132
|
+
|
|
133
|
+
The server's offset from UTC; `None` before the first connect.
|
|
134
|
+
|
|
135
|
+
#### `symbol_build` *(property)*
|
|
136
|
+
|
|
137
|
+
The server's symbol-database build number.
|
|
138
|
+
|
|
139
|
+
#### `trade_build` *(property)*
|
|
140
|
+
|
|
141
|
+
The server's trade build number.
|
|
142
|
+
|
|
143
|
+
#### `trading_disabled_by_server` *(property)*
|
|
144
|
+
|
|
145
|
+
Trading is disabled for this account on the server side.
|
|
146
|
+
|
|
147
|
+
## Symbols, quotes and bars
|
|
148
|
+
|
|
149
|
+
#### `async aquote(symbol, timeout=None)`
|
|
150
|
+
|
|
151
|
+
Awaitable `quote` (runs on a worker thread; never blocks the event loop).
|
|
152
|
+
|
|
153
|
+
#### `bars(symbol, timeframe='H1', *, count=None, start=None, end=None, timeout=None)`
|
|
154
|
+
|
|
155
|
+
OHLC bars, oldest first, in the broker's server time.
|
|
156
|
+
|
|
157
|
+
Give `count` for the latest N bars, or `start` (and optionally `end`) for a window; with neither, the
|
|
158
|
+
latest 500. `timeframe` is a name — `M1 M2 M3 M4 M5 M6 M10 M12 M15 M20 M30 H1 H2 H3 H4 H6 H8 H12 D1 W1 MN1` —
|
|
159
|
+
or its length in minutes. Higher timeframes are built from the server's one-minute bars with the tick volume
|
|
160
|
+
summed; minutes after `end` are not used (no look-ahead); the last bar may still be forming.
|
|
161
|
+
`timeout` (seconds, default: the client's `bars_timeout`) bounds the whole call.
|
|
162
|
+
|
|
163
|
+
#### `commission(symbol)`
|
|
164
|
+
|
|
165
|
+
The commission schedule that applies to a symbol, or `None` when the broker defines none.
|
|
166
|
+
|
|
167
|
+
#### `contract_size(symbol)`
|
|
168
|
+
|
|
169
|
+
The contract size of a symbol (units of the instrument per 1.0 lot).
|
|
170
|
+
|
|
171
|
+
#### `find_symbol(prefix)`
|
|
172
|
+
|
|
173
|
+
The symbol `prefix` names: the exact name if the broker has it, else the only symbol that starts with
|
|
174
|
+
it. `None` when there is none; an `InvalidRequestError` listing the candidates when several do
|
|
175
|
+
(use `find_symbols` and choose).
|
|
176
|
+
|
|
177
|
+
#### `find_symbols(prefix)`
|
|
178
|
+
|
|
179
|
+
Every symbol whose name starts with `prefix` (brokers add suffixes such as `m` or `.s`), exact
|
|
180
|
+
match first, then shortest name.
|
|
181
|
+
|
|
182
|
+
#### `has_symbol(name)`
|
|
183
|
+
|
|
184
|
+
Whether the broker offers `name` exactly as spelled.
|
|
185
|
+
|
|
186
|
+
#### `is_quote_session(symbol)`
|
|
187
|
+
|
|
188
|
+
The symbol is inside one of its quote sessions right now (server clock).
|
|
189
|
+
|
|
190
|
+
#### `is_subscribed(symbol)`
|
|
191
|
+
|
|
192
|
+
Whether the live feed of `symbol` is on.
|
|
193
|
+
|
|
194
|
+
#### `is_trade_session(symbol)`
|
|
195
|
+
|
|
196
|
+
The symbol is inside one of its trade sessions right now (server clock).
|
|
197
|
+
|
|
198
|
+
#### `ledger_value_per_lot(symbol)`
|
|
199
|
+
|
|
200
|
+
What the account's own closed deals say one price unit on one lot is worth for this symbol, or `None`
|
|
201
|
+
when the account has not closed enough deals on it.
|
|
202
|
+
|
|
203
|
+
#### `quote(symbol, timeout=None)`
|
|
204
|
+
|
|
205
|
+
The current quote of one symbol, waiting up to `timeout` seconds (default: the client's `quote_timeout`)
|
|
206
|
+
for the first tick; `NoQuoteError` if none arrives.
|
|
207
|
+
|
|
208
|
+
#### `request_bars(symbol, day=None)`
|
|
209
|
+
|
|
210
|
+
Ask the server for one-minute bars without waiting; the answer arrives through `on_quote_history`.
|
|
211
|
+
With no `day` this is today's bars, otherwise the block ending at `day`.
|
|
212
|
+
|
|
213
|
+
#### `sessions(symbol)`
|
|
214
|
+
|
|
215
|
+
When a symbol is quoted and traded, per weekday (0 = Sunday), in minutes from 00:00 server time.
|
|
216
|
+
|
|
217
|
+
#### `subscribe(*symbols)`
|
|
218
|
+
|
|
219
|
+
Start the live quote feed for the given symbols (names, or lists of names).
|
|
220
|
+
|
|
221
|
+
#### `subscriptions()`
|
|
222
|
+
|
|
223
|
+
The symbols currently subscribed.
|
|
224
|
+
|
|
225
|
+
#### `symbol(name)`
|
|
226
|
+
|
|
227
|
+
One symbol's specification and trading rules.
|
|
228
|
+
|
|
229
|
+
#### `symbol_groups()`
|
|
230
|
+
|
|
231
|
+
The names of the broker's symbol groups.
|
|
232
|
+
|
|
233
|
+
#### `symbols()`
|
|
234
|
+
|
|
235
|
+
Every symbol the broker offers on this account, by name, with its trading rules.
|
|
236
|
+
|
|
237
|
+
#### `tick_value(symbol, side='ask', timeout=None)`
|
|
238
|
+
|
|
239
|
+
The value, in account currency, of one full price unit per 1.0 lot (as the terminal computes it).
|
|
240
|
+
|
|
241
|
+
This is an *input* to position sizing, not a recipe: see `lots_for_risk`. `side` is `"ask"` (what a
|
|
242
|
+
long position is priced against) or `"bid"`. Waits up to `timeout` seconds (default: `quote_timeout`)
|
|
243
|
+
for a live quote. Raises `InvalidRequestError` when the value cannot be computed (a symbol whose
|
|
244
|
+
profit currency has no conversion rate), never a NaN.
|
|
245
|
+
|
|
246
|
+
#### `unsubscribe(*symbols)`
|
|
247
|
+
|
|
248
|
+
Stop the live quote feed for the given symbols (names, or lists of names).
|
|
249
|
+
|
|
250
|
+
## Account, orders and history
|
|
251
|
+
|
|
252
|
+
#### `account(refresh=True)`
|
|
253
|
+
|
|
254
|
+
Account details. With `refresh` (the default) the equity, profit and margin figures are brought up to date
|
|
255
|
+
first: every open position's symbol is quoted once and the profits are recalculated.
|
|
256
|
+
|
|
257
|
+
#### `closed_orders()`
|
|
258
|
+
|
|
259
|
+
The orders this session has seen close (a rolling cache of about ten). For anything older use
|
|
260
|
+
`history`.
|
|
261
|
+
|
|
262
|
+
#### `deal_history(year, month)`
|
|
263
|
+
|
|
264
|
+
One calendar month of history (a convenience over `history`).
|
|
265
|
+
|
|
266
|
+
#### `equity_history(start, timeframe='D1', exclude_same_bars=True)`
|
|
267
|
+
|
|
268
|
+
The balance and equity curve since `start` (`timeframe` is `H1`, `H4` or `D1`).
|
|
269
|
+
|
|
270
|
+
`balance` is exact; the historical `equity` is a bar-priced reconstruction and a point with
|
|
271
|
+
`incomplete` set has understated floating P/L. With `exclude_same_bars` (the default, as in the C# library)
|
|
272
|
+
consecutive points with an unchanged balance and equity are dropped. Downloads deals and per-symbol bars, so it
|
|
273
|
+
blocks.
|
|
274
|
+
|
|
275
|
+
#### `history(start=None, end=None, timeout=None)`
|
|
276
|
+
|
|
277
|
+
Orders and deals between `start` and `end` (default: the last 30 days up to now). Blocks until the
|
|
278
|
+
server has sent everything, up to `timeout` seconds (default: the client's `history_timeout`).
|
|
279
|
+
|
|
280
|
+
Naive datetimes are used exactly as given, in the broker's server time; timezone-aware ones are converted to
|
|
281
|
+
it. The default window is computed on the server's clock.
|
|
282
|
+
|
|
283
|
+
#### `orders()`
|
|
284
|
+
|
|
285
|
+
Everything currently working: open positions and pending orders.
|
|
286
|
+
|
|
287
|
+
#### `positions()`
|
|
288
|
+
|
|
289
|
+
Open positions only (pending orders excluded).
|
|
290
|
+
|
|
291
|
+
A position is an order of type `Buy` or `Sell`; pending orders are the `*Limit` and `*Stop` types. The
|
|
292
|
+
order's `state` is not used: the core can leave a freshly opened position in `Started` for a long time.
|
|
293
|
+
|
|
294
|
+
#### `request_history(start, end)`
|
|
295
|
+
|
|
296
|
+
Ask for history without waiting; it arrives through `on_history`. The server's answer is not trimmed
|
|
297
|
+
to `start` / `end` (it can hold more than you asked for, in pages): filter by time. The blocking
|
|
298
|
+
`history` does trim.
|
|
299
|
+
|
|
300
|
+
#### `request_history_month(year, month)`
|
|
301
|
+
|
|
302
|
+
Ask for one calendar month of history without waiting; it arrives through `on_history`.
|
|
303
|
+
|
|
304
|
+
#### `summary(start=None, end=None)`
|
|
305
|
+
|
|
306
|
+
Realized trading result, deposits and withdrawals, from the deal ledger (all time by default).
|
|
307
|
+
|
|
308
|
+
Downloads the deal history, so it blocks; call it off your UI thread (or use `asyncio.to_thread`).
|
|
309
|
+
|
|
310
|
+
#### `update_profits()`
|
|
311
|
+
|
|
312
|
+
Recompute floating P/L and used margin from the current quotes. Warm the open positions' quotes first (or
|
|
313
|
+
use `account(refresh=True)`, which does both).
|
|
314
|
+
|
|
315
|
+
## Sizing and risk
|
|
316
|
+
|
|
317
|
+
#### `calibrate_money_scale(start, *, min_deals_per_symbol=None, max_self_scatter=None, max_disagreement=None, max_snap_distance=None)`
|
|
318
|
+
|
|
319
|
+
Measure what a price unit is worth *on this account* from its own closed deals since `start`.
|
|
320
|
+
|
|
321
|
+
Read-only; places no order. Cent handling is a per-broker configuration, not a property of the currency, so
|
|
322
|
+
sizing is refused until this has succeeded. Returns `False` when the scale cannot be established (read
|
|
323
|
+
`money_scale_evidence`); more history usually fixes it.
|
|
324
|
+
|
|
325
|
+
#### `lots_for_risk(symbol, entry_price, stop_price, risk_amount, *, lot_step=None, min_lot=None, max_ratio=None, max_equity_share=None, max_lot=None)`
|
|
326
|
+
|
|
327
|
+
The volume that loses `risk_amount` (account currency) if `stop_price` is hit, with the evidence.
|
|
328
|
+
|
|
329
|
+
Requires a successful `calibrate_money_scale`; without it the answer is a refusal. The volume is
|
|
330
|
+
rounded **down**. Check `ok`: when false, `lots` is 0 and `reason` says which check failed.
|
|
331
|
+
|
|
332
|
+
#### `money_scale` *(property)*
|
|
333
|
+
|
|
334
|
+
The measured scale (`None` until `calibrate_money_scale` has succeeded).
|
|
335
|
+
|
|
336
|
+
#### `money_scale_evidence` *(property)*
|
|
337
|
+
|
|
338
|
+
Why the scale is what it is, or why it could not be established.
|
|
339
|
+
|
|
340
|
+
#### `money_scale_from_deal(deal)`
|
|
341
|
+
|
|
342
|
+
Re-measure the scale from ONE closed deal — the broker's own accounting of a trade that happened. Compare
|
|
343
|
+
it with `money_scale`; a disagreement means every size derived from the calibration was wrong.
|
|
344
|
+
|
|
345
|
+
#### `order_profit(symbol, open_price, close_price, lots, buy=True)`
|
|
346
|
+
|
|
347
|
+
The P/L, in account currency, of `lots` moving from `open_price` to `close_price` (cent accounts
|
|
348
|
+
included). For reporting a completed or hypothetical move; use `lots_for_risk` to size.
|
|
349
|
+
|
|
350
|
+
#### `required_margin(symbol, lots, side='buy', price=0.0)`
|
|
351
|
+
|
|
352
|
+
The margin needed to open `lots` of `symbol`, computed as the terminal does (`price` 0 = live quote).
|
|
353
|
+
A reference figure, not a sizing input.
|
|
354
|
+
|
|
355
|
+
## Order entry
|
|
356
|
+
|
|
357
|
+
#### `async abuy(*args, **kwargs)`
|
|
358
|
+
|
|
359
|
+
Awaitable `buy`.
|
|
360
|
+
|
|
361
|
+
#### `async acancel(*args, **kwargs)`
|
|
362
|
+
|
|
363
|
+
Awaitable `cancel`.
|
|
364
|
+
|
|
365
|
+
#### `async aclose(*args, **kwargs)`
|
|
366
|
+
|
|
367
|
+
Awaitable `close`.
|
|
368
|
+
|
|
369
|
+
#### `async amodify(*args, **kwargs)`
|
|
370
|
+
|
|
371
|
+
Awaitable `modify`.
|
|
372
|
+
|
|
373
|
+
#### `async aplace_order(*args, **kwargs)`
|
|
374
|
+
|
|
375
|
+
Awaitable `place_order`.
|
|
376
|
+
|
|
377
|
+
#### `async asell(*args, **kwargs)`
|
|
378
|
+
|
|
379
|
+
Awaitable `sell`.
|
|
380
|
+
|
|
381
|
+
#### `buy(symbol, lots, *, sl=0.0, tp=0.0, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
382
|
+
|
|
383
|
+
Buy at market (the current ask). `sl` / `tp` are prices (0 = none); `deviation` is the allowed
|
|
384
|
+
slippage in points; `magic` is your own number, readable back on `Order` and `Deal`;
|
|
385
|
+
`fill_policy` is `fok`, `ioc`, `flash` or `any`.
|
|
386
|
+
|
|
387
|
+
#### `buy_async(symbol, lots, *, request_id=None, sl=0.0, tp=0.0, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
388
|
+
|
|
389
|
+
Send a market buy and return with its request id as soon as the request is on the wire; the outcome arrives
|
|
390
|
+
through `on_order_progress` (and `on_order_update`).
|
|
391
|
+
|
|
392
|
+
A market order needs a price: if the symbol has no quote yet this first waits (up to the client's
|
|
393
|
+
`quote_timeout`) for one, and raises `NoQuoteError` — nothing sent — if none arrives.
|
|
394
|
+
|
|
395
|
+
#### `cancel(ticket, *, fill_policy=None, comment=None, placed_type=None)`
|
|
396
|
+
|
|
397
|
+
Delete a pending order.
|
|
398
|
+
|
|
399
|
+
#### `cancel_async(ticket, *, request_id=None, fill_policy=None, comment=None, placed_type=None)`
|
|
400
|
+
|
|
401
|
+
Delete a pending order and return at once with its request id; see `cancel`.
|
|
402
|
+
|
|
403
|
+
#### `close(ticket, lots=None, *, deviation=0, comment=None, fill_policy=None, close_by=None, placed_type=None)`
|
|
404
|
+
|
|
405
|
+
Close a position at market, completely or (with `lots`) in part. `close_by` closes it against an
|
|
406
|
+
opposite position of the same symbol (hedging accounts).
|
|
407
|
+
|
|
408
|
+
#### `close_async(ticket, lots=None, *, request_id=None, deviation=0, comment=None, fill_policy=None, close_by=None, placed_type=None)`
|
|
409
|
+
|
|
410
|
+
Close a position (or part of it) at market and return at once with its request id; see `close`.
|
|
411
|
+
|
|
412
|
+
#### `modify(ticket, *, sl=None, tp=None, price=None, stop_limit=None, expiration=None, comment=None)`
|
|
413
|
+
|
|
414
|
+
Change a position's stop-loss / take-profit, or a pending order's price / stops / expiration. Anything
|
|
415
|
+
left as `None` keeps its current value.
|
|
416
|
+
|
|
417
|
+
#### `modify_async(ticket, *, request_id=None, sl=None, tp=None, price=None, stop_limit=None, expiration=None, comment=None)`
|
|
418
|
+
|
|
419
|
+
Modify a position or pending order and return at once with its request id; see `modify`.
|
|
420
|
+
|
|
421
|
+
#### `new_request_id()`
|
|
422
|
+
|
|
423
|
+
A unique id for an asynchronous trade call (the `*_async` methods take one for you).
|
|
424
|
+
|
|
425
|
+
#### `place_order(symbol, kind, lots, price, *, sl=0.0, tp=0.0, stop_limit=0.0, expiration=None, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
426
|
+
|
|
427
|
+
Place a pending order. `kind` is one of `buy_limit sell_limit buy_stop sell_stop buy_stop_limit
|
|
428
|
+
sell_stop_limit` (the two stop-limit kinds also need `stop_limit`, the limit price). `expiration` is
|
|
429
|
+
`None` (the broker's default), `"gtc"`, `"today"`, a `datetime` (that moment) or a `date` (that day).
|
|
430
|
+
|
|
431
|
+
#### `place_order_async(symbol, kind, lots, price, *, request_id=None, sl=0.0, tp=0.0, stop_limit=0.0, expiration=None, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
432
|
+
|
|
433
|
+
Place a pending order and return at once with its request id; see `place_order` and `buy_async`.
|
|
434
|
+
|
|
435
|
+
#### `sell(symbol, lots, *, sl=0.0, tp=0.0, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
436
|
+
|
|
437
|
+
Sell at market (the current bid).
|
|
438
|
+
|
|
439
|
+
#### `sell_async(symbol, lots, *, request_id=None, sl=0.0, tp=0.0, deviation=0, comment=None, magic=0, fill_policy=None, trade_type=None, placed_type=None)`
|
|
440
|
+
|
|
441
|
+
Send a market sell and return at once with its request id; see `buy_async`.
|
|
442
|
+
|
|
443
|
+
## Events and streams
|
|
444
|
+
|
|
445
|
+
#### `aorder_updates(*, maxsize=1000)`
|
|
446
|
+
|
|
447
|
+
Async version of `order_updates`.
|
|
448
|
+
|
|
449
|
+
#### `aquotes(*symbols, maxsize=10000)`
|
|
450
|
+
|
|
451
|
+
Async version of `quotes` (no timeout; `aclose()` or cancel the task to stop). Call it inside a
|
|
452
|
+
running event loop.
|
|
453
|
+
|
|
454
|
+
#### `events_dropped` *(property)*
|
|
455
|
+
|
|
456
|
+
How many events were dropped because callbacks fell too far behind (see the module notes).
|
|
457
|
+
|
|
458
|
+
#### `on_connect_progress(callback)`
|
|
459
|
+
|
|
460
|
+
Call `callback(event)` for each connect step and for a drop. This is how to tell a permanent failure from
|
|
461
|
+
a transient one while `auto_reconnect` is on.
|
|
462
|
+
|
|
463
|
+
#### `on_history(callback)`
|
|
464
|
+
|
|
465
|
+
Call `callback(history)` when history requested with `request_history` arrives. The server may
|
|
466
|
+
deliver it in pages (`history.more` says another page follows) and does not trim it to the range you asked
|
|
467
|
+
for: filter by time.
|
|
468
|
+
|
|
469
|
+
#### `on_order_progress(callback)`
|
|
470
|
+
|
|
471
|
+
Call `callback(progress)` as an asynchronous trade request advances (see `buy_async`).
|
|
472
|
+
|
|
473
|
+
#### `on_order_update(callback)`
|
|
474
|
+
|
|
475
|
+
Call `callback(update)` when the server pushes a change to an order or position (opened, filled,
|
|
476
|
+
modified, closed, stopped out ...). Set `all_order_updates=True` on the client to also receive the
|
|
477
|
+
intermediate Started / Filled / Cancelling states.
|
|
478
|
+
|
|
479
|
+
#### `on_quote(callback)`
|
|
480
|
+
|
|
481
|
+
Call `callback(quote)` for every tick of every subscribed symbol. Returns a function that removes it.
|
|
482
|
+
|
|
483
|
+
#### `on_quote_history(callback)`
|
|
484
|
+
|
|
485
|
+
Call `callback(event)` when bars requested with `request_bars` arrive.
|
|
486
|
+
|
|
487
|
+
#### `on_symbol_update(callback)`
|
|
488
|
+
|
|
489
|
+
Call `callback()` when one symbol's data is (re)received; read `symbols` again.
|
|
490
|
+
|
|
491
|
+
#### `on_symbols_update(callback)`
|
|
492
|
+
|
|
493
|
+
Call `callback()` when the server pushes a change to the symbol list; read `symbols` again.
|
|
494
|
+
|
|
495
|
+
#### `order_updates(*, timeout=None, maxsize=1000)`
|
|
496
|
+
|
|
497
|
+
Iterate order updates (attached when called). Ends when `timeout` seconds pass without one.
|
|
498
|
+
|
|
499
|
+
#### `quotes(*symbols, timeout=None, maxsize=10000)`
|
|
500
|
+
|
|
501
|
+
Iterate live quotes of `symbols` (subscribing them first; with none given, every subscribed symbol).
|
|
502
|
+
Ends when `timeout` seconds pass without a tick. The feed is attached when this is called, not at the first
|
|
503
|
+
`next()`. If the consumer falls behind by more than `maxsize` quotes the oldest are dropped.
|
|
504
|
+
|
|
505
|
+
## Module functions
|
|
506
|
+
|
|
507
|
+
#### `load_servers_dat(source)`
|
|
508
|
+
|
|
509
|
+
The trade servers in a terminal's `servers.dat`: each with its name, company and (host, port) access points.
|
|
510
|
+
Offline: reads only the file (a path, or the file's bytes).
|
|
511
|
+
|
|
512
|
+
#### `save_servers_dat(records)`
|
|
513
|
+
|
|
514
|
+
The bytes of a `servers.dat` file holding `records` (the inverse of `load_servers_dat`).
|
|
515
|
+
|
|
516
|
+
#### `request_demo_account(request, host, port=443)`
|
|
517
|
+
|
|
518
|
+
Ask a broker's access server for a new demo account and return its login and passwords.
|
|
519
|
+
|
|
520
|
+
This creates a real account at the broker: use it deliberately.
|
|
521
|
+
|
|
522
|
+
#### `tick_value_from_deal(closed_profit, open_price, close_price, lots)`
|
|
523
|
+
|
|
524
|
+
The value of one price unit per lot implied by a closed deal's realized P/L — the empirical check of a
|
|
525
|
+
tick value.
|
|
526
|
+
|
|
527
|
+
#### `enable_core_logging(logger_name='pmt5api.core')`
|
|
528
|
+
|
|
529
|
+
Forward the core's log messages (`Logger.OnMsgEx`) and internal diagnostics (`Diag.Sink`) to the Python
|
|
530
|
+
logger `logger_name`. Returns a function that switches it off again. Nothing is forwarded unless this is called,
|
|
531
|
+
and the core is silent by default.
|
|
532
|
+
|
|
533
|
+
#### `aggregate(minute_bars, minutes)`
|
|
534
|
+
|
|
535
|
+
Build `minutes`-long bars from one-minute bars (any order; a repeated minute keeps its last value).
|
|
536
|
+
|
|
537
|
+
#### `to_frame(items)`
|
|
538
|
+
|
|
539
|
+
A `pandas.DataFrame` from a list of the package's value objects (`Bar`, `Order`, `Quote`, ...).
|
|
540
|
+
|
|
541
|
+
A list of bars is indexed by its `time`; anything else keeps a plain integer index.
|
|
542
|
+
|
|
543
|
+
## Data types
|
|
544
|
+
|
|
545
|
+
#### `Quote`
|
|
546
|
+
|
|
547
|
+
Quote(symbol: 'str', bid: 'float', ask: 'float', time: 'Optional[datetime]', last: 'float', volume: 'int')
|
|
548
|
+
|
|
549
|
+
Fields: `symbol`, `bid`, `ask`, `time`, `last`, `volume`
|
|
550
|
+
|
|
551
|
+
#### `SymbolInfo`
|
|
552
|
+
|
|
553
|
+
A symbol's specification and trading rules.
|
|
554
|
+
|
|
555
|
+
Fields: `name`, `description`, `digits`, `point`, `spread`, `contract_size`, `profit_currency`, `margin_currency`, `isin`, `custom`, `depth_of_market`, `calc_mode`, `gtc_mode`, `settlement_price`, `lower_limit`, `upper_limit`, `face_value`, `accrued_interest`, `raw_tick_value`, `raw_tick_size`, `group`, `trade_mode`, `execution`, `min_lots`, `max_lots`, `lots_step`, `min_stop_distance`, `min_take_distance`, `swap_type`, `swap_long`, `swap_short`, `triple_swap_day`, `initial_margin`, `maintenance_margin`
|
|
556
|
+
|
|
557
|
+
#### `TradingSession`
|
|
558
|
+
|
|
559
|
+
One trading or quoting window of a weekday, in minutes from 00:00 server time (`end` may be 1440).
|
|
560
|
+
|
|
561
|
+
Fields: `start`, `end`
|
|
562
|
+
|
|
563
|
+
#### `SymbolSessions`
|
|
564
|
+
|
|
565
|
+
Per weekday (index 0 = Sunday … 6 = Saturday), the windows in which a symbol is quoted and traded.
|
|
566
|
+
|
|
567
|
+
Fields: `symbol`, `quotes`, `trades`
|
|
568
|
+
|
|
569
|
+
#### `CommissionInfo`
|
|
570
|
+
|
|
571
|
+
CommissionInfo(group_name: 'str', type: 'str', period: 'str', money_currency: 'str', instant_type: 'str', tiers: 'Tuple[CommissionTier, ...]')
|
|
572
|
+
|
|
573
|
+
Fields: `group_name`, `type`, `period`, `money_currency`, `instant_type`, `tiers`
|
|
574
|
+
|
|
575
|
+
#### `BaseInfo`
|
|
576
|
+
|
|
577
|
+
What the server says about itself: the broker, the account currency and its digits, the account mode.
|
|
578
|
+
|
|
579
|
+
Fields: `company`, `currency`, `digits`, `account_method`, `margin_mode`
|
|
580
|
+
|
|
581
|
+
#### `AccountInfo`
|
|
582
|
+
|
|
583
|
+
AccountInfo(login: 'int', name: 'str', currency: 'str', leverage: 'int', balance: 'float', credit: 'float', equity: 'float', profit: 'float', margin: 'float', free_margin: 'float', margin_level: 'float', floating_pl: 'float' = 0.0, swap: 'float' = 0.0, commission: 'float' = 0.0, fee: 'float' = 0.0, blocked: 'float' = 0.0, company: 'str' = '', method: 'str' = '', account_type: 'str' = '', trade_flags: 'int' = 0, country: 'str' = '', city: 'str' = '', state: 'str' = '', zip_code: 'str' = '', address: 'str' = '', phone: 'str' = '', email: 'str' = '')
|
|
584
|
+
|
|
585
|
+
Fields: `login`, `name`, `currency`, `leverage`, `balance`, `credit`, `equity`, `profit`, `margin`, `free_margin`, `margin_level`, `floating_pl`, `swap`, `commission`, `fee`, `blocked`, `company`, `method`, `account_type`, `trade_flags`, `country`, `city`, `state`, `zip_code`, `address`, `phone`, `email`
|
|
586
|
+
|
|
587
|
+
#### `AccountSummary`
|
|
588
|
+
|
|
589
|
+
Realized figures from the deal ledger: trading result apart from deposits and withdrawals.
|
|
590
|
+
|
|
591
|
+
Fields: `balance`, `credit`, `realized_profit`, `deposit`, `withdrawal`
|
|
592
|
+
|
|
593
|
+
#### `EquityPoint`
|
|
594
|
+
|
|
595
|
+
One point of the balance/equity curve. `balance` and `balance_change` are exact (the deal ledger); the
|
|
596
|
+
historical `equity` and `unrealized_pl` are a bar-priced reconstruction. `incomplete` is set when a symbol's
|
|
597
|
+
bars did not arrive in time, so the floating part of that point is understated.
|
|
598
|
+
|
|
599
|
+
Fields: `time`, `balance`, `equity`, `balance_drawdown_raw`, `balance_drawdown_relative`, `equity_drawdown_raw`, `equity_drawdown_relative`, `realized_pl`, `unrealized_pl`, `incomplete`, `balance_change`
|
|
600
|
+
|
|
601
|
+
#### `LotSizing`
|
|
602
|
+
|
|
603
|
+
The answer of `Client.lots_for_risk`. If `ok` is false, `lots` is 0 and `reason` says why:
|
|
604
|
+
do not trade it. `warnings` can accompany a true `ok` (for example, nothing corroborated the scale).
|
|
605
|
+
|
|
606
|
+
Fields: `ok`, `lots`, `expected_loss_at_stop`, `risk_requested`, `minimum_trade_cost`, `ratio`, `reason`, `warnings`
|
|
607
|
+
|
|
608
|
+
#### `Order`
|
|
609
|
+
|
|
610
|
+
An open position, a pending order, or a historical order.
|
|
611
|
+
|
|
612
|
+
Fields: `ticket`, `symbol`, `order_type`, `deal_type`, `state`, `lots`, `digits`, `open_price`, `open_time`, `close_price`, `close_time`, `stop_loss`, `take_profit`, `profit`, `swap`, `commission`, `fee`, `comment`, `magic`, `close_lots`, `close_comment`, `contract_size`, `placed_type`, `request_id`, `stop_limit_price`, `profit_rate`, `expiration_type`, `expiration_time`, `fill_policy`
|
|
613
|
+
|
|
614
|
+
#### `Deal`
|
|
615
|
+
|
|
616
|
+
One executed deal from the account's ledger (a trade fill, or a balance operation such as a deposit).
|
|
617
|
+
|
|
618
|
+
Fields: `ticket`, `order_ticket`, `position_ticket`, `symbol`, `type`, `direction`, `time`, `price`, `open_price`, `stop_loss`, `take_profit`, `lots`, `profit`, `commission`, `swap`, `contract_size`, `digits`, `comment`, `magic`
|
|
619
|
+
|
|
620
|
+
#### `History`
|
|
621
|
+
|
|
622
|
+
Result of a history download: the orders and the deals in the requested window.
|
|
623
|
+
|
|
624
|
+
Fields: `orders`, `deals`, `action`
|
|
625
|
+
|
|
626
|
+
#### `Bar`
|
|
627
|
+
|
|
628
|
+
Bar(time: 'datetime', open: 'float', high: 'float', low: 'float', close: 'float', tick_volume: 'int', volume: 'int', spread: 'Optional[int]' = None)
|
|
629
|
+
|
|
630
|
+
Fields: `time`, `open`, `high`, `low`, `close`, `tick_volume`, `volume`, `spread`
|
|
631
|
+
|
|
632
|
+
#### `OrderUpdate`
|
|
633
|
+
|
|
634
|
+
A change the server pushed about an order or a position. `type` is one of Started, Filled, PendingOpen,
|
|
635
|
+
PendingModify, PendingClose, MarketOpen, MarketModify, MarketClose, PartialClose, MarketCloseBy, OnStopLoss,
|
|
636
|
+
OnTakeProfit, OnStopOut, Balance, Expired, Rejected, Cancelling, Unknown.
|
|
637
|
+
|
|
638
|
+
Fields: `type`, `order`, `ticket`, `transaction_id`, `close_by_ticket`
|
|
639
|
+
|
|
640
|
+
#### `OrderProgress`
|
|
641
|
+
|
|
642
|
+
Progress of an asynchronous trade request (the request id you got back from `*_async`).
|
|
643
|
+
|
|
644
|
+
Fields: `request_id`, `status`, `ticket`, `position_id`, `volume`, `price`, `bid`, `ask`, `comment`, `order_type`, `symbol`, `fill_policy`
|
|
645
|
+
|
|
646
|
+
#### `ConnectEvent`
|
|
647
|
+
|
|
648
|
+
A step of the connect sequence: SendLogin, SendAccountPassword, AcceptAuthorized, RequestTradeInfo, Connected,
|
|
649
|
+
Exception, Disconnect. `error` is the translated exception for `Exception` steps.
|
|
650
|
+
|
|
651
|
+
Fields: `stage`, `error`
|
|
652
|
+
|
|
653
|
+
#### `QuoteHistoryEvent`
|
|
654
|
+
|
|
655
|
+
One-minute bars the server delivered after `Client.request_bars`.
|
|
656
|
+
|
|
657
|
+
Fields: `symbol`, `bars`
|
|
658
|
+
|
|
659
|
+
#### `ServerRecord`
|
|
660
|
+
|
|
661
|
+
A trade server of a `servers.dat` file: its name, company and (host, port) access points.
|
|
662
|
+
|
|
663
|
+
Fields: `name`, `company`, `access`
|
|
664
|
+
|
|
665
|
+
#### `DemoAccountRequest`
|
|
666
|
+
|
|
667
|
+
What `pmt5api.request_demo_account` asks a broker's server for.
|
|
668
|
+
|
|
669
|
+
Fields: `user_name`, `email`, `deposit`, `leverage`, `account_type`, `country`, `city`, `state`, `zip_code`, `address`, `phone`, `company_name`, `language_id`
|
|
670
|
+
|
|
671
|
+
#### `DemoAccount`
|
|
672
|
+
|
|
673
|
+
DemoAccount(login: 'int', password: 'str', investor_password: 'str')
|
|
674
|
+
|
|
675
|
+
Fields: `login`, `password`, `investor_password`
|
|
676
|
+
|
|
677
|
+
#### `Proxy`
|
|
678
|
+
|
|
679
|
+
A proxy the core connects through. `kind` is `"https"`, `"socks4"` or `"socks5"`.
|
|
680
|
+
|
|
681
|
+
Fields: `kind`, `host`, `port`, `user`, `password`
|
|
682
|
+
|
|
683
|
+
## Errors
|
|
684
|
+
|
|
685
|
+
```
|
|
686
|
+
WmtError
|
|
687
|
+
BusyError
|
|
688
|
+
ConnectError
|
|
689
|
+
ConnectionLostError
|
|
690
|
+
CoreNotFoundError
|
|
691
|
+
InvalidRequestError
|
|
692
|
+
LicenseError
|
|
693
|
+
NoQuoteError
|
|
694
|
+
NotConnectedError
|
|
695
|
+
ProxyError
|
|
696
|
+
RequestTimeout
|
|
697
|
+
RuntimeNotFoundError
|
|
698
|
+
ServerError
|
|
699
|
+
InvestorModeError
|
|
700
|
+
TokenServiceError
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
- `BusyError` — The core allows one request of this kind at a time and one is still running; wait for it and retry.
|
|
704
|
+
- `ConnectError` — The broker's access server could not be reached.
|
|
705
|
+
- `ConnectionLostError` — An established connection was lost.
|
|
706
|
+
- `CoreNotFoundError` — The licensed core library (wmt5api.dll) could not be located.
|
|
707
|
+
- `InvalidRequestError` — The request was rejected before it was sent (for example, a symbol the server does not know).
|
|
708
|
+
- `InvestorModeError` — The account was opened with an investor (read-only) password and the request needs trading rights.
|
|
709
|
+
- `LicenseError` — The licence service refused the request. `reason` is one of: NoKey, Invalid, Expired, Revoked, RateLimited, LoginNotAllowed, AccountLimitReached, Unknown.
|
|
710
|
+
- `NoQuoteError` — No quote was available in time to read or to trade against. Nothing was sent.
|
|
711
|
+
- `NotConnectedError` — The call needs a connection and the client is not connected.
|
|
712
|
+
- `ProxyError` — The configured proxy refused or failed.
|
|
713
|
+
- `RequestTimeout` — The server did not answer within the requested time. For a trade call this means the request WAS sent and was not confirmed in time: the order may have been accepted; look at `orders()` before sending again. (When nothing was sent, `NoQuoteError` is raised instead.)
|
|
714
|
+
- `RuntimeNotFoundError` — The .NET runtime needed to host the core could not be started.
|
|
715
|
+
- `ServerError` — The broker's server refused the request (for example an incorrect login or password, or a rejected order). `code` is the server's return code by name (`"REQUOTE"`, `"NO_MONEY"`, `"INVALID_PRICE"`, ...) and `code_value` its number; both are `None` when the refusal carried no code.
|
|
716
|
+
- `TokenServiceError` — The licence service could not be reached or answered with something unusable (not a licence decision).
|
|
717
|
+
- `WmtError` — Base class of every pmt5api error.
|