โ† All tutorials
MT5 API ยท 3:16

Other methods: results and errors.

Account, market, history, calculation and stream methods. Understand valid empty, zero and false results.

Step-by-step transcript

  1. 0:00

    Other methods: results and errors.

    This tutorial shows how to handle results and errors in other MT5 methods, including account data, market information, history, calculations, and WebSocket streams.

  2. 0:14

    Open the selected method’s guide.

    Open M T five dot M R P C dot pro. Select the method you need, such as Account Summary or Opened Orders. Expand How to check whether a request succeeded below the code example. Read the instructions for that particular method.

  3. 0:33

    1. Check the HTTP status code.

    First, check the HTTP status code. HTTP status code two hundred means the API received the request and returned a response. Read the JSON body next. For another status code, read the HTTP error and its response body first.

  4. 0:53

    Step 2. Check error.

    Second, check error. If it is not null, read error code and error message. Here, an actual Account Summary request returned HTTP status code two hundred, but the terminal identifier was invalid. The red result explains the correction.

  5. 1:12

    Fix a missing or invalid session.

    For an invalid terminal identifier, use the complete I D returned by Connect Ex. For a missing terminal, check the identifier and platform, then check the terminal state. A session that has ended needs a valid connection before account requests can continue.

  6. 1:31

    Other methods: interpret their own data.

    For account, market, history, and calculation methods, read the method’s own data fields after checking error. An empty list means no matching items. A zero count can mean no positions. A false value may be a valid answer to a yes or no question. It is not automatically an API failure.

  7. 1:54

    Read the method’s exact result fields.

    In Account Summary, read the returned account details. In Positions Total, read the position count. Calculation methods return estimated margin or profit; they do not execute a trade. In history methods, check your filters and time range when the returned list is empty.

  8. 2:15

    Busy terminal: wait before retrying.

    If the terminal reports Busy or Rate Limit Exceeded, read Retry After Seconds from error properties when it is supplied. Wait for that interval and reduce concurrent requests. For a timed out read, check terminal state and retry when it is ready.

  9. 2:33

    Streams: check every message.

    For WebSocket methods, check each incoming message for error, then process its data. An open socket is not proof that every operation succeeded. A quiet stream or an empty heartbeat is not a failed request. If the connection drops, reconnect as needed and read current account state to catch up.

  10. 2:55

    Other methods: one, two, three.

    For ordinary methods, check the HTTP status code, inspect error, and interpret the method’s own data. For streams, inspect every received message. Keep the original diagnostics for troubleshooting, and remove credentials and account details before sharing a response.