Constants

pdmt5.constants

MetaTrader 5 constant parsing helpers.

COPY_TICKS_MAP module-attribute

COPY_TICKS_MAP: Final[Mapping[str, int]] = MappingProxyType(
    _COPY_TICKS_MAP
)

ORDER_TYPE_MAP module-attribute

ORDER_TYPE_MAP: Final[Mapping[str, int]] = MappingProxyType(
    _ORDER_TYPE_MAP
)

TIMEFRAME_MAP module-attribute

TIMEFRAME_MAP: Final[Mapping[str, int]] = MappingProxyType(
    _TIMEFRAME_MAP
)

__all__ module-attribute

__all__ = [
    "COPY_TICKS_MAP",
    "ORDER_TYPE_MAP",
    "TIMEFRAME_MAP",
    "get_copy_ticks_name",
    "get_copy_ticks_value",
    "get_order_type_name",
    "get_order_type_value",
    "get_timeframe_name",
    "get_timeframe_value",
    "list_copy_ticks_names",
    "list_copy_ticks_values",
    "list_order_type_names",
    "list_order_type_values",
    "list_timeframe_names",
    "list_timeframe_values",
    "parse_copy_ticks",
    "parse_order_type",
    "parse_timeframe",
]

get_copy_ticks_name

get_copy_ticks_name(
    value: int, *, prefer_alias: bool = False
) -> str

Return the MT5 COPY_TICKS name for an integer value.

Parameters:

Name Type Description Default
value int

COPY_TICKS integer value.

required
prefer_alias bool

Return the short alias instead of the official name.

False

Returns:

Type Description
str

The matching COPY_TICKS name.

Source code in pdmt5/constants.py
def get_copy_ticks_name(value: int, *, prefer_alias: bool = False) -> str:
    """Return the MT5 COPY_TICKS name for an integer value.

    Args:
        value: COPY_TICKS integer value.
        prefer_alias: Return the short alias instead of the official name.

    Returns:
        The matching COPY_TICKS name.

    """
    return _COPY_TICKS_FAMILY.name_by_value(value=value, prefer_alias=prefer_alias)

get_copy_ticks_value

get_copy_ticks_value(name: str) -> int

Return the integer value for an MT5 COPY_TICKS name or alias.

Parameters:

Name Type Description Default
name str

Official COPY_TICKS name or short alias.

required

Returns:

Type Description
int

The matching COPY_TICKS integer.

Source code in pdmt5/constants.py
def get_copy_ticks_value(name: str) -> int:
    """Return the integer value for an MT5 COPY_TICKS name or alias.

    Args:
        name: Official COPY_TICKS name or short alias.

    Returns:
        The matching COPY_TICKS integer.

    """
    return parse_copy_ticks(name)

get_order_type_name

get_order_type_name(
    value: int, *, prefer_alias: bool = False
) -> str

Return the MT5 ORDER_TYPE name for an integer value.

Parameters:

Name Type Description Default
value int

ORDER_TYPE integer value.

required
prefer_alias bool

Return the short alias instead of the official name.

False

Returns:

Type Description
str

The matching ORDER_TYPE name.

Source code in pdmt5/constants.py
def get_order_type_name(value: int, *, prefer_alias: bool = False) -> str:
    """Return the MT5 ORDER_TYPE name for an integer value.

    Args:
        value: ORDER_TYPE integer value.
        prefer_alias: Return the short alias instead of the official name.

    Returns:
        The matching ORDER_TYPE name.

    """
    return _ORDER_TYPE_FAMILY.name_by_value(value=value, prefer_alias=prefer_alias)

get_order_type_value

get_order_type_value(name: str) -> int

Return the integer value for an MT5 ORDER_TYPE name or alias.

Parameters:

Name Type Description Default
name str

Official ORDER_TYPE name or short alias.

required

Returns:

Type Description
int

The matching ORDER_TYPE integer.

Source code in pdmt5/constants.py
def get_order_type_value(name: str) -> int:
    """Return the integer value for an MT5 ORDER_TYPE name or alias.

    Args:
        name: Official ORDER_TYPE name or short alias.

    Returns:
        The matching ORDER_TYPE integer.

    """
    return parse_order_type(name)

get_timeframe_name

get_timeframe_name(
    value: int, *, prefer_alias: bool = False
) -> str

Return the MT5 timeframe name for an integer value.

Parameters:

Name Type Description Default
value int

Timeframe integer value.

required
prefer_alias bool

Return the short alias instead of the official name.

False

Returns:

Type Description
str

The matching timeframe name.

Source code in pdmt5/constants.py
def get_timeframe_name(value: int, *, prefer_alias: bool = False) -> str:
    """Return the MT5 timeframe name for an integer value.

    Args:
        value: Timeframe integer value.
        prefer_alias: Return the short alias instead of the official name.

    Returns:
        The matching timeframe name.

    """
    return _TIMEFRAME_FAMILY.name_by_value(value=value, prefer_alias=prefer_alias)

get_timeframe_value

get_timeframe_value(name: str) -> int

Return the integer value for an MT5 timeframe name or alias.

Parameters:

Name Type Description Default
name str

Official timeframe name or short alias.

required

Returns:

Type Description
int

The matching timeframe integer.

Source code in pdmt5/constants.py
def get_timeframe_value(name: str) -> int:
    """Return the integer value for an MT5 timeframe name or alias.

    Args:
        name: Official timeframe name or short alias.

    Returns:
        The matching timeframe integer.

    """
    return parse_timeframe(name)

list_copy_ticks_names

list_copy_ticks_names(
    *, include_aliases: bool = True
) -> list[str]

Return MT5 COPY_TICKS names for JSON schema generation.

Parameters:

Name Type Description Default
include_aliases bool

Include short aliases such as ALL.

True

Returns:

Type Description
list[str]

Accepted COPY_TICKS names.

Source code in pdmt5/constants.py
def list_copy_ticks_names(*, include_aliases: bool = True) -> list[str]:
    """Return MT5 COPY_TICKS names for JSON schema generation.

    Args:
        include_aliases: Include short aliases such as ``ALL``.

    Returns:
        Accepted COPY_TICKS names.
    """
    return _COPY_TICKS_FAMILY.names(include_aliases=include_aliases)

list_copy_ticks_values

list_copy_ticks_values() -> list[int]

Return valid MT5 COPY_TICKS integer values for JSON schema generation.

Returns:

Type Description
list[int]

Valid COPY_TICKS integer values.

Source code in pdmt5/constants.py
def list_copy_ticks_values() -> list[int]:
    """Return valid MT5 COPY_TICKS integer values for JSON schema generation.

    Returns:
        Valid COPY_TICKS integer values.
    """
    return _COPY_TICKS_FAMILY.values

list_order_type_names

list_order_type_names(
    *, include_aliases: bool = True
) -> list[str]

Return MT5 ORDER_TYPE names for JSON schema generation.

Parameters:

Name Type Description Default
include_aliases bool

Include short aliases such as BUY.

True

Returns:

Type Description
list[str]

Accepted ORDER_TYPE names.

Source code in pdmt5/constants.py
def list_order_type_names(*, include_aliases: bool = True) -> list[str]:
    """Return MT5 ORDER_TYPE names for JSON schema generation.

    Args:
        include_aliases: Include short aliases such as ``BUY``.

    Returns:
        Accepted ORDER_TYPE names.
    """
    return _ORDER_TYPE_FAMILY.names(include_aliases=include_aliases)

list_order_type_values

list_order_type_values() -> list[int]

Return valid MT5 ORDER_TYPE integer values for JSON schema generation.

Returns:

Type Description
list[int]

Valid ORDER_TYPE integer values.

Source code in pdmt5/constants.py
def list_order_type_values() -> list[int]:
    """Return valid MT5 ORDER_TYPE integer values for JSON schema generation.

    Returns:
        Valid ORDER_TYPE integer values.
    """
    return _ORDER_TYPE_FAMILY.values

list_timeframe_names

list_timeframe_names(
    *, include_aliases: bool = True
) -> list[str]

Return MT5 timeframe names for JSON schema generation.

Parameters:

Name Type Description Default
include_aliases bool

Include short aliases such as M1.

True

Returns:

Type Description
list[str]

Accepted timeframe names.

Source code in pdmt5/constants.py
def list_timeframe_names(*, include_aliases: bool = True) -> list[str]:
    """Return MT5 timeframe names for JSON schema generation.

    Args:
        include_aliases: Include short aliases such as ``M1``.

    Returns:
        Accepted timeframe names.
    """
    return _TIMEFRAME_FAMILY.names(include_aliases=include_aliases)

list_timeframe_values

list_timeframe_values() -> list[int]

Return valid MT5 timeframe integer values for JSON schema generation.

Returns:

Type Description
list[int]

Valid timeframe integer values.

Source code in pdmt5/constants.py
def list_timeframe_values() -> list[int]:
    """Return valid MT5 timeframe integer values for JSON schema generation.

    Returns:
        Valid timeframe integer values.
    """
    return _TIMEFRAME_FAMILY.values

parse_copy_ticks

parse_copy_ticks(value: object) -> int

Parse a MetaTrader 5 COPY_TICKS name, alias, or integer value.

Parameters:

Name Type Description Default
value object

Official name (COPY_TICKS_ALL), short alias (ALL), or numeric string, or integer value.

required

Returns:

Type Description
int

The validated MetaTrader 5 COPY_TICKS integer.

Source code in pdmt5/constants.py
def parse_copy_ticks(value: object) -> int:
    """Parse a MetaTrader 5 COPY_TICKS name, alias, or integer value.

    Args:
        value: Official name (``COPY_TICKS_ALL``), short alias (``ALL``), or
            numeric string, or integer value.

    Returns:
        The validated MetaTrader 5 COPY_TICKS integer.

    """
    return _parse_constant(value=value, family=_COPY_TICKS_FAMILY)

parse_order_type

parse_order_type(value: object) -> int

Parse a MetaTrader 5 ORDER_TYPE name, alias, or integer value.

Parameters:

Name Type Description Default
value object

Official name (ORDER_TYPE_BUY), short alias (BUY), or numeric string, or integer value.

required

Returns:

Type Description
int

The validated MetaTrader 5 ORDER_TYPE integer.

Source code in pdmt5/constants.py
def parse_order_type(value: object) -> int:
    """Parse a MetaTrader 5 ORDER_TYPE name, alias, or integer value.

    Args:
        value: Official name (``ORDER_TYPE_BUY``), short alias (``BUY``), or
            numeric string, or integer value.

    Returns:
        The validated MetaTrader 5 ORDER_TYPE integer.

    """
    return _parse_constant(value=value, family=_ORDER_TYPE_FAMILY)

parse_timeframe

parse_timeframe(value: object) -> int

Parse a MetaTrader 5 timeframe name, alias, or integer value.

Parameters:

Name Type Description Default
value object

Official name (TIMEFRAME_M1), short alias (M1), numeric string, or integer value.

required

Returns:

Type Description
int

The validated MetaTrader 5 timeframe integer.

Source code in pdmt5/constants.py
def parse_timeframe(value: object) -> int:
    """Parse a MetaTrader 5 timeframe name, alias, or integer value.

    Args:
        value: Official name (``TIMEFRAME_M1``), short alias (``M1``), numeric
            string, or integer value.

    Returns:
        The validated MetaTrader 5 timeframe integer.

    """
    return _parse_constant(value=value, family=_TIMEFRAME_FAMILY)