DEV Community

AlgoHand
AlgoHand

Posted on Fully Autonomous

Verifying remote MetaTrader commands after confirmation

A customer presses Apply. The API returns a command ID. A few seconds later, their connection drops.

At that point, a controller has to answer two different questions: did the server accept the request, and did MetaTrader finish the change? Treating either question as the other can produce a misleading success message or a duplicate attempt.

AlgoHand exposes the request, resolved plan and observed result separately. A reliable integration keeps those distinctions visible all the way to the user.

Preserve the approved action

For an input change, obtain a preview with dry_run: true. Show the exact account, EA instance, changed values and warnings. Store the approved action in the application backend along with its preview_hash.

On confirmation, submit that action with dry_run: false and the hash as expected_preview_hash. If the resolved plan changed, the server can return PREVIEW_STALE instead of queuing the new version. The user should review a fresh preview.

The hash checks the plan; it does not prove that a person approved it. A custom interface must enforce its own confirmation flow. This matters because raw REST commands default to execution when dry_run is omitted. Preview-first behaviour in a chat tool is not a property every API caller automatically inherits.

Save the receipt before updating the interface

HTTP 202 means accepted. Save the returned command_id and continue observing it:

GET /v1/commands/cmd_example?wait=30
Authorization: Bearer <CLIENT_API_KEY>
Enter fullscreen mode Exit fullscreen mode

The example uses a fictional ID and a client-scoped key. A long-poll can return because an outcome is available or because its wait elapsed. HTTP 200 alone does not indicate command success; read the body's status.

Status What the interface should communicate
queued Waiting for execution
dispatched Delivered for agent handling
running Work or verification is still in progress
succeeded The command's required result checks passed
unconfirmed The EA change was applied, but initialization lacks confirmation; inspect before another change
failed, rejected, expired, cancelled Read the error, timeline and observed result; these labels are not interchangeable rollback guarantees

Display summary, relevant result.observed fields and the error's explanation. The operation determines what evidence is required. A successful screenshot and a successful EA start do not have the same verification contract.

Separate input readback from initialization

For a settings operation, reading back the intended values answers whether those values are visible in the terminal. It does not alone establish that the EA initialized successfully or that its trading logic will work as intended.

MetaTrader calls an EA's initialization handler when loading it; MQL5's OnInit can report failure. That is why a chart name or a requested template is insufficient evidence by itself. MQL5 OnInit reference

AlgoHand can report unconfirmed when an applied change lacks initialization confirmation after the verification period. The current command reference specifies 15 minutes. Present that as an applied change requiring inspection, and keep the receipt available. Do not silently turn it into either success or an automatic second application.

Changing inputs reinitializes the EA. If it has open trades, check the author's guidance on changing settings while trading.

Retry the delivery without inventing a new action

Persist an Idempotency-Key before sending an execution request. If the response is lost, reuse the same key and exact action to recover the existing receipt while it is retained by the server. A different body or account with that key is a conflict.

This protects one API operation from repeated submission. It is not a general guarantee of exactly-once behaviour across every failure of Windows, the terminal and the network. Do not rotate the key merely because the first request took longer than expected.

Lost HTTP response
    |
    +-- known command ID -> read that command
    |
    +-- no command ID -> retry exact delivery with its saved idempotency key

Unclear terminal outcome -> inspect receipt and current state
                         -> do not create a fresh application automatically
Enter fullscreen mode Exit fullscreen mode

Cancellation needs the same care. Requesting cancellation does not reverse an input change already applied inside MetaTrader. Read the cancellation response and the current command state rather than treating a Cancel button as an undo operation.

Expect evidence to arrive late

A timeout means the expected evidence did not arrive within a deadline. It does not prove that nothing happened. A later result may clarify a command's outcome, so refresh its current record before deciding on a recovery action.

Webhook consumers should also tolerate repeated and out-of-order events. Deduplicate by event ID, correlate by command ID and consult the current command record when a delayed event conflicts with what the interface already knows. An arrival timestamp is not the execution order.

For support, retain the command ID, target identity, approved diff, timestamps and result. That is enough to investigate a particular operation without teaching users to press Apply repeatedly until the UI changes.

The complete request and outcome fields are in the AlgoHand command API, including the OpenAPI schema.

Top comments (0)