last_error

Retorna informações sobre o último erro.

last_error()

Valor retornado

Retorna o código do último erro e sua descrição na forma de uma tupla.

Observação

last_error() permite que obter o código de erro em caso de execução mal sucedida de qualquer função da biblioteca MetaTrader 5. É semelhante a GetLastError(), mas são usados seus próprios códigos de erro. Valores possíveis:

Constante

Valor

Descrição

RES_S_OK

1

generic success

RES_E_FAIL

-1

generic fail

RES_E_INVALID_PARAMS

-2

invalid arguments/parameters

RES_E_NO_MEMORY

-3

no memory condition

RES_E_NOT_FOUND

-4

no history

RES_E_INVALID_VERSION

-5

invalid version

RES_E_AUTH_FAILED

-6

authorization failed

RES_E_UNSUPPORTED

-7

unsupported method

RES_E_AUTO_TRADING_DISABLED

-8

auto-trading disabled

RES_E_INTERNAL_FAIL

-10000

internal IPC general error

RES_E_INTERNAL_FAIL_SEND

-10001

internal IPC send failed

RES_E_INTERNAL_FAIL_RECEIVE

-10002

internal IPC recv failed

RES_E_INTERNAL_FAIL_INIT

-10003

internal IPC initialization fail

RES_E_INTERNAL_FAIL_CONNECT

-10003

internal IPC no ipc

RES_E_INTERNAL_FAIL_TIMEOUT

-10005

internal timeout

Exemplo:

import MetaTrader5 as mt5
# exibimos dados sobre o pacote MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# estabelecemos a conexão ao MetaTrader 5
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
 
# concluímos a conexão ao terminal MetaTrader 5
mt5.shutdown()

Veja também

version, GetLastError