|
10 | 10 | from .state import global_state as _state |
11 | 11 | from .types import * |
12 | 12 |
|
| 13 | +# _OMIT_FUNCS_FROM_CONVERSION = [] |
13 | 14 |
|
14 | 15 | class MT5Error(Exception): |
15 | 16 | pass |
16 | 17 |
|
17 | 18 |
|
18 | 19 | def _context_manager_modified(f): |
19 | 20 | @functools.wraps(f) |
20 | | - def wrapper(*args, **kwargs): |
| 21 | + def context_manager_modified_wrapper(*args, **kwargs): |
21 | 22 | result = f(*args, **kwargs) |
22 | 23 | if _state.global_debugging: |
23 | 24 | call_sig = f"{f.__name__}({_h.args_to_str(args, kwargs)})" |
24 | 25 | _state.log(f"[{call_sig}][{last_error()}][{str(result)[:80]}]") |
25 | 26 | # make sure we log before we raise |
26 | | - if _state.raise_on_errors: |
| 27 | + if _state.raise_on_errors and not result: # no need to check last error if we got a result |
27 | 28 | error_code, description = last_error() |
28 | 29 | if error_code != _const.RES_S_OK: |
29 | 30 | raise MT5Error(error_code, description) |
| 31 | + # if _state.convert_namedtuples_to_dict and result: |
| 32 | + # result = _h.as_dict_all(result) |
30 | 33 | return result |
31 | 34 |
|
32 | | - return wrapper |
| 35 | + return context_manager_modified_wrapper |
33 | 36 |
|
34 | 37 |
|
35 | 38 | @_context_manager_modified |
@@ -167,10 +170,9 @@ def symbols_get(*, |
167 | 170 | symbols = _mt5.symbols_get(group=group) if group else _mt5.symbols_get() |
168 | 171 | if symbols is None and _state.raise_on_errors: |
169 | 172 | build = version() |
170 | | - if build: |
171 | | - if build[1] < _const.MIN_TERMINAL_BUILD : |
172 | | - raise MT5Error(_const.RES_X_TERMINAL_VERSION_OUTDATED, |
173 | | - "The terminal build needs to be updated to support this feature.") |
| 173 | + if build and build[1] < _const.MIN_TERMINAL_BUILD : |
| 174 | + raise MT5Error(_const.RES_X_TERMINAL_VERSION_OUTDATED, |
| 175 | + "The terminal build needs to be updated to support this feature.") |
174 | 176 | else: |
175 | 177 | error_code, des = last_error() |
176 | 178 | if error_code == _const.RES_S_OK: |
@@ -215,9 +217,14 @@ def symbol_info_tick(symbol) -> Tick: |
215 | 217 | :param symbol: |
216 | 218 | :return: |
217 | 219 | """ |
218 | | - symbol = _h.any_symbol(symbol) |
219 | | - return _mt5.symbol_info_tick(symbol) |
| 220 | + try: |
| 221 | + return _mt5.symbol_info_tick(symbol) |
| 222 | + except Exception: |
| 223 | + symbol = _h.any_symbol(symbol) |
| 224 | + return _mt5.symbol_info_tick(symbol) |
220 | 225 |
|
| 226 | +#direct access to API function without any added overhead |
| 227 | +symbol_info_tick_fast = _mt5.symbol_info_tick |
221 | 228 |
|
222 | 229 | @_context_manager_modified |
223 | 230 | def symbol_select(symbol, enable: bool = True) -> bool: |
|
0 commit comments