Skip to content

Terminal Info

CTerminalInfo

Source code in strategytester5\trade_classes\TerminalInfo.py
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
class CTerminalInfo:
    def __init__(self, terminal: Union[OverLoadedMetaTrader5API|MetaTrader5]):

        """
        A lightweight Python wrapper that resembles the MQL5 Standard Library class
        `CTerminalInfo` and provides convenient, read-only access to the properties
        of the MetaTrader 5 terminal environment.

        This class caches the result of `mt5.terminal_info()` at construction time.
        The returned values reflect the terminal state at the moment of initialization.
        If you need up-to-date values, create a new instance or add a refresh method.

        [MQL5 Reference](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cterminalinfo)

        Parameters
        ----------
        terminal : Initialize native MetaTrader5 API or the simulated one from the StrategyTester instance

        Raises
        ------
        RuntimeError
            If terminal information cannot be retrieved.

        Notes
        -----
        Method groups mirror the MQL5 layout:
        - Integer / boolean properties: Build, IsConnected, IsDLLsAllowed, IsTradeAllowed, etc.
        - String properties: Language, Name, Company, Path, DataPath, CommonDataPath
        - Generic accessors: InfoInteger, InfoString
        """

        self.terminal = terminal
        self._info = self.terminal.terminal_info()

        if self._info is None:
            raise RuntimeError("Failed to retrieve terminal info")

    # ------------- State / boolean properties -------------

    @property
    def is_valid(self) -> bool:
        """Returns True if terminal info is available."""
        return self._info is not None

    @property
    def is_connected(self) -> bool:
        """Gets the information about connection to the trade server."""
        return bool(self._info.connected)

    @property
    def is_dlls_allowed(self) -> bool:
        """Gets the information about permission of DLL usage."""
        return bool(self._info.dlls_allowed)

    @property
    def is_trade_allowed(self) -> bool:
        """Gets the information about permission to trade."""
        return bool(self._info.trade_allowed)

    @property
    def is_email_enabled(self) -> bool:
        """Gets the information about permission to send emails."""
        return bool(self._info.email_enabled)

    @property
    def is_ftp_enabled(self) -> bool:
        """Gets the information about permission to send FTP reports."""
        return bool(self._info.ftp_enabled)

    @property
    def is_community_account(self) -> bool:
        """Gets whether an MQL5.community account is configured."""
        return bool(self._info.community_account)

    @property
    def is_community_connection(self) -> bool:
        """Gets whether the terminal is connected to the MQL5.community service."""
        return bool(self._info.community_connection)

    @property
    def are_notifications_enabled(self) -> bool:
        """Gets whether push notifications are enabled."""
        return bool(self._info.notifications_enabled)

    @property
    def is_mqid(self) -> bool:
        """Gets whether a MetaQuotes ID is configured."""
        return bool(self._info.mqid)

    @property
    def is_tradeapi_disabled(self) -> bool:
        """Gets whether external trade API usage is disabled."""
        return bool(self._info.tradeapi_disabled)

    @property
    def is_x64(self) -> bool:
        """Gets the information about the type of the client terminal."""
        value = getattr(self._info, "x64", False)
        return bool(value)

    # ---------- Integer / numeric properties ------------

    @property
    def build(self) -> int:
        """Gets the build number of the client terminal."""
        return int(self._info.build)

    @property
    def max_bars(self) -> int:
        """Gets the maximum number of bars on chart."""
        return int(self._info.maxbars)

    @property
    def code_page(self) -> int:
        """Gets the code page of the terminal language."""
        return int(self._info.codepage)

    @property
    def cpu_cores(self) -> int:
        """Gets the number of CPU cores."""
        value = getattr(self._info, "cpu_cores", 0)
        return int(value)

    @property
    def memory_physical(self) -> int:
        """Gets the amount of physical memory in MB."""
        value = getattr(self._info, "memory_physical", 0)
        return int(value)

    @property
    def memory_total(self) -> int:
        """Gets the total memory available for terminal/agent process in MB."""
        value = getattr(self._info, "memory_total", 0)
        return int(value)

    @property
    def memory_available(self) -> int:
        """Gets the free memory available for terminal/agent process in MB."""
        value = getattr(self._info, "memory_available", 0)
        return int(value)

    @property
    def memory_used(self) -> int:
        """Gets the memory used by terminal/agent process in MB."""
        value = getattr(self._info, "memory_used", 0)
        return int(value)

    @property
    def disk_space(self) -> int:
        """Gets the free disk space in MB."""
        value = getattr(self._info, "disk_space", 0)
        return int(value)

    @property
    def ping_last(self) -> int:
        """Gets the last ping value."""
        return int(self._info.ping_last)

    @property
    def community_balance(self) -> float:
        """Gets the MQL5.community balance."""
        return float(self._info.community_balance)

    @property
    def retransmission(self) -> float:
        """Gets the retransmission percentage/value."""
        return float(self._info.retransmission)

    @property
    def opencl_support(self) -> str:
        """Gets the OpenCL version supported by the video card."""
        value = getattr(self._info, "opencl_support", "")
        return str(value)

    # ---------- String properties --------------

    @property
    def name(self) -> str:
        """Gets the name of the client terminal."""
        return str(self._info.name)

    @property
    def company(self) -> str:
        """Gets the company name of the client terminal."""
        return str(self._info.company)

    @property
    def language(self) -> str:
        """Gets the language of the client terminal."""
        return str(self._info.language)

    @property
    def path(self) -> str:
        """Gets the folder of the client terminal."""
        return str(self._info.path)

    @property
    def data_path(self) -> str:
        """Gets the data folder of the client terminal."""
        return str(self._info.data_path)

    @property
    def common_data_path(self) -> str:
        """Gets the common data folder of all installed terminals."""
        return str(self._info.commondata_path)

    # ------------- Generic Info* methods ------------

    def info_integer(self, prop_name: str) -> Optional[int]:
        """
        Gets the value of a property of integer type.

        Parameters
        ----------
        prop_name : str
            Name of the terminal info attribute.

        Returns
        -------
        Optional[int]
            Integer value if present, otherwise None.
        """
        if self._info is None or not hasattr(self._info, prop_name):
            return None

        value = getattr(self._info, prop_name)
        return None if value is None else int(value)

    def info_string(self, prop_name: str) -> Optional[str]:
        """
        Gets the value of a property of string type.

        Parameters
        ----------
        prop_name : str
            Name of the terminal info attribute.

        Returns
        -------
        Optional[str]
            String value if present, otherwise None.
        """
        if self._info is None or not hasattr(self._info, prop_name):
            return None

        value = getattr(self._info, prop_name)
        return None if value is None else str(value)

    # ---------- Debug / utility helpers --------------

    def to_dict(self) -> dict[str, Any]:
        """Return all @property values as a dictionary."""
        data: dict[str, Any] = {}
        seen: set[str] = set()

        for cls in type(self).mro():
            for name, attr in vars(cls).items():
                if name in seen:
                    continue
                if isinstance(attr, property):
                    seen.add(name)
                    try:
                        data[name] = getattr(self, name)
                    except Exception as e:
                        data[name] = f"<error: {e}>"

        return data

    def print_all(self) -> None:
        """Print all @property values of the class."""
        for name, value in self.to_dict().items():
            print(f"{name:24} : {value}")

    def __repr__(self) -> str:
        props = self.to_dict()
        props_str = ", ".join(f"{k}={v!r}" for k, v in props.items())
        return f"{self.__class__.__name__}({props_str})"

are_notifications_enabled property

Gets whether push notifications are enabled.

build property

Gets the build number of the client terminal.

code_page property

Gets the code page of the terminal language.

common_data_path property

Gets the common data folder of all installed terminals.

community_balance property

Gets the MQL5.community balance.

company property

Gets the company name of the client terminal.

cpu_cores property

Gets the number of CPU cores.

data_path property

Gets the data folder of the client terminal.

disk_space property

Gets the free disk space in MB.

is_community_account property

Gets whether an MQL5.community account is configured.

is_community_connection property

Gets whether the terminal is connected to the MQL5.community service.

is_connected property

Gets the information about connection to the trade server.

is_dlls_allowed property

Gets the information about permission of DLL usage.

is_email_enabled property

Gets the information about permission to send emails.

is_ftp_enabled property

Gets the information about permission to send FTP reports.

is_mqid property

Gets whether a MetaQuotes ID is configured.

is_trade_allowed property

Gets the information about permission to trade.

is_tradeapi_disabled property

Gets whether external trade API usage is disabled.

is_valid property

Returns True if terminal info is available.

is_x64 property

Gets the information about the type of the client terminal.

language property

Gets the language of the client terminal.

max_bars property

Gets the maximum number of bars on chart.

memory_available property

Gets the free memory available for terminal/agent process in MB.

memory_physical property

Gets the amount of physical memory in MB.

memory_total property

Gets the total memory available for terminal/agent process in MB.

memory_used property

Gets the memory used by terminal/agent process in MB.

name property

Gets the name of the client terminal.

opencl_support property

Gets the OpenCL version supported by the video card.

path property

Gets the folder of the client terminal.

ping_last property

Gets the last ping value.

retransmission property

Gets the retransmission percentage/value.

__init__(terminal)

A lightweight Python wrapper that resembles the MQL5 Standard Library class CTerminalInfo and provides convenient, read-only access to the properties of the MetaTrader 5 terminal environment.

This class caches the result of mt5.terminal_info() at construction time. The returned values reflect the terminal state at the moment of initialization. If you need up-to-date values, create a new instance or add a refresh method.

MQL5 Reference

Parameters

terminal : Initialize native MetaTrader5 API or the simulated one from the StrategyTester instance

Raises

RuntimeError If terminal information cannot be retrieved.

Notes

Method groups mirror the MQL5 layout: - Integer / boolean properties: Build, IsConnected, IsDLLsAllowed, IsTradeAllowed, etc. - String properties: Language, Name, Company, Path, DataPath, CommonDataPath - Generic accessors: InfoInteger, InfoString

Source code in strategytester5\trade_classes\TerminalInfo.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(self, terminal: Union[OverLoadedMetaTrader5API|MetaTrader5]):

    """
    A lightweight Python wrapper that resembles the MQL5 Standard Library class
    `CTerminalInfo` and provides convenient, read-only access to the properties
    of the MetaTrader 5 terminal environment.

    This class caches the result of `mt5.terminal_info()` at construction time.
    The returned values reflect the terminal state at the moment of initialization.
    If you need up-to-date values, create a new instance or add a refresh method.

    [MQL5 Reference](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/cterminalinfo)

    Parameters
    ----------
    terminal : Initialize native MetaTrader5 API or the simulated one from the StrategyTester instance

    Raises
    ------
    RuntimeError
        If terminal information cannot be retrieved.

    Notes
    -----
    Method groups mirror the MQL5 layout:
    - Integer / boolean properties: Build, IsConnected, IsDLLsAllowed, IsTradeAllowed, etc.
    - String properties: Language, Name, Company, Path, DataPath, CommonDataPath
    - Generic accessors: InfoInteger, InfoString
    """

    self.terminal = terminal
    self._info = self.terminal.terminal_info()

    if self._info is None:
        raise RuntimeError("Failed to retrieve terminal info")

info_integer(prop_name)

Gets the value of a property of integer type.

Parameters

prop_name : str Name of the terminal info attribute.

Returns

Optional[int] Integer value if present, otherwise None.

Source code in strategytester5\trade_classes\TerminalInfo.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
def info_integer(self, prop_name: str) -> Optional[int]:
    """
    Gets the value of a property of integer type.

    Parameters
    ----------
    prop_name : str
        Name of the terminal info attribute.

    Returns
    -------
    Optional[int]
        Integer value if present, otherwise None.
    """
    if self._info is None or not hasattr(self._info, prop_name):
        return None

    value = getattr(self._info, prop_name)
    return None if value is None else int(value)

info_string(prop_name)

Gets the value of a property of string type.

Parameters

prop_name : str Name of the terminal info attribute.

Returns

Optional[str] String value if present, otherwise None.

Source code in strategytester5\trade_classes\TerminalInfo.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def info_string(self, prop_name: str) -> Optional[str]:
    """
    Gets the value of a property of string type.

    Parameters
    ----------
    prop_name : str
        Name of the terminal info attribute.

    Returns
    -------
    Optional[str]
        String value if present, otherwise None.
    """
    if self._info is None or not hasattr(self._info, prop_name):
        return None

    value = getattr(self._info, prop_name)
    return None if value is None else str(value)

print_all()

Print all @property values of the class.

Source code in strategytester5\trade_classes\TerminalInfo.py
277
278
279
280
def print_all(self) -> None:
    """Print all @property values of the class."""
    for name, value in self.to_dict().items():
        print(f"{name:24} : {value}")

to_dict()

Return all @property values as a dictionary.

Source code in strategytester5\trade_classes\TerminalInfo.py
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
def to_dict(self) -> dict[str, Any]:
    """Return all @property values as a dictionary."""
    data: dict[str, Any] = {}
    seen: set[str] = set()

    for cls in type(self).mro():
        for name, attr in vars(cls).items():
            if name in seen:
                continue
            if isinstance(attr, property):
                seen.add(name)
                try:
                    data[name] = getattr(self, name)
                except Exception as e:
                    data[name] = f"<error: {e}>"

    return data