Skip to content

last_error

last_error

Return data on the last error.

last_error()

Return Value

Return the last error code and description as a tuple.

Note

last_error() allows obtaining an error code in case of a failed execution of a MetaTrader 5 library function. It is similar to GetLastError(). However, it applies its own error codes. Possible values:

ConstantValueDescription
RES_S_OK1generic success
RES_E_FAIL-1generic fail
RES_E_INVALID_PARAMS-2invalid arguments/parameters
RES_E_NO_MEMORY-3no memory condition
RES_E_NOT_FOUND-4no history
RES_E_INVALID_VERSION-5invalid version
RES_E_AUTH_FAILED-6authorization failed
RES_E_UNSUPPORTED-7unsupported method
RES_E_AUTO_TRADING_DISABLED-8auto-trading disabled
RES_E_INTERNAL_FAIL-10000internal IPC general error
RES_E_INTERNAL_FAIL_SEND-10001internal IPC send failed
RES_E_INTERNAL_FAIL_RECEIVE-10002internal IPC recv failed
RES_E_INTERNAL_FAIL_INIT-10003internal IPC initialization fail
RES_E_INTERNAL_FAIL_CONNECT-10003internal IPC no ipc
RES_E_INTERNAL_FAIL_TIMEOUT-10005internal timeout

Example:

import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)

# establish connection to the MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()

# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()

See also

version, GetLastError

Last updated on