KazaTrade
دخول
القائمة

Errors

The library reports problems by throwing exceptions. This page lists the types, when they appear, and the broker status codes.

All exception types are in the namespace mtapi.mt5.

Exception types

TypeBaseWhen
ServerExceptionExceptionThe broker or login server answered with an error. Read Code (a Msg).
ConnectExceptionExceptionConnect failed before the broker answered, or you used a member that needs a connection (Symbols.Exist, ServerBuild, AccountMethod). Also the text from the login service, such as KazaTrade: no ApiKey set (set api.ApiKey to the key from your Developer page).
ConnectionExceptionApplicationExceptionThe client certificate (PfxFile) has no usable private key.
ServerNotFoundExceptionExceptionThe server-name constructor could not find the broker server.
InvalidSymbolExceptionExceptionThe symbol does not exist on this broker.
InvestorModeExceptionExceptionYou tried to trade on a read-only (investor password) login.
DoubleRequestExceptionExceptionA history or bar download is already running on this client. Wait and try again.
ProxyExceptionExceptionThe proxy refused or failed.
TimeoutExceptionsystemA quote, bar or history wait ran out, or OrderSend, OrderClose or OrderModify got no answer within ExecutionTimeout. After a trade timeout the trade may still have happened: check GetOpenedOrders before you retry.

Exception itself is thrown for a few cases, for example trading switched off for the account or the symbol (or the symbol only allows one direction or closing), "Not connected", "Symbol not found: ...", "Account not loaded" and "Request Lots = 0 ". Catch it last.

ServerException.Code

ServerException.Code is a Msg. ex.Message has a readable text for it. Common values:

Login

CodeMeaning
INVALID_ACCOUNTWrong login number or password
ACCOUNT_DISABLEDThe account is disabled
UNKNOWN_ACCOUNTThe server does not know this account
INVALID_PASSWORDPassword refused
INVALID_ONETIME_PASSWORDOne-time password wrong or missing (set OtpPassword)
PASSWORD_MUST_CHANGEDThe broker requires a new password first
SERVER_BUSY, SERVER_SHUTDOWNThe broker server is busy or stopping. Try later.
OLD_SERVER, INVALID_SERVERThe server version or address does not fit

Trading

CodeMeaning
REQUOTE, PRICE_CHANGEDThe price moved. Get a new quote and retry, or raise deviation.
NO_PRICESNo price for the symbol
MARKET_CLOSEDThe market is closed
TRADE_DISABLED, AUTOTRADE_DISABLE_SERVER, AUTOTRADE_DISABLE_CLIENTTrading is not allowed
NO_MONEYNot enough free margin
INVALID_VOLUMELots outside min, max or step
INVALID_PRICE, INVALID_STOPS, INVALID_EXPIRATION, INVALID_REQUESTA price, stop level, expiry or the request is not valid
UNSUPPORTED_FILLING_MODETry another fillPolicy (or Any)
ORDER_LIMIT_REACHED_, POSITION_LIMIT_REACHED, VOLUME_LIMIT_REACHEDA broker limit was reached
POSITION_NOT_EXISTSThe position is already closed
VOLUME_CLOSE_EXCEEDS_POSITIONYou tried to close more than the position holds
NO_CHANGESNothing to modify: the values are the same
MODIFICATION_FAILEDThe change was refused
TOO_MANY_TRADE_REQUESTSSlow down
HEDGE_PROHIBITED, FIFO_CLOSE, ONLY_LONG_POSITION, ONLY_SHORT_POSITION, ONLY_CLOSE_POSITIONA broker rule blocks this trade
REQUEST_REJECTED, REQUEST_CANCELLED, REQUEST_ERROR, REQUEST_TIMEOUTThe request did not complete
NETWORK_PROBLEMThe link dropped

The progress codes REQUEST_ON_WAY, REQUEST_ACCEPTED, REQUEST_EXECUTED, ORDER_PLACED and DONE are normal steps, not errors.

Msg has more values than listed here. Use ex.Code.ToString() for the name.

Handling errors

try
{
    api.OrderSend("EURUSD", 0.10, price, OrderType.Buy);
}
catch (InvestorModeException)   { /* read-only login */ }
catch (InvalidSymbolException)  { /* wrong symbol name */ }
catch (TimeoutException)        { /* unknown outcome: check open positions */ }
catch (ServerException ex) when (ex.Code == Msg.REQUOTE)
{
    // get a fresh quote and try once more
}
catch (ServerException ex)      { Console.WriteLine($"Broker refused: {ex.Code}"); }
catch (Exception ex)            { Console.WriteLine(ex.Message); /* e.g. trading off for this symbol */ }
Errors · MT5 library reference