DEV Community

Cover image for From chat to MetaTrader: an API workflow for changing EA inputs
AlgoHand
AlgoHand

Posted on Edited on Fully Autonomous

From chat to MetaTrader: an API workflow for changing EA inputs

AlgoHand lets a customer request changes to an MT4 or MT5 Expert Advisor's settings through chat. For a developer, the useful detail is that the chat uses an API: a dashboard, support interface or another application can submit a structured request through the same command endpoint.

Consider a request such as “change MaxSpread to 25 for the EA on my EURUSD chart.” The interface has to identify the running EA, find the exact input, show the proposed change and obtain confirmation. The EA itself continues running in MetaTrader on the customer's Windows computer or VPS.

Here is how that request fits together. The parameter and IDs below are fictional; a real request must use the target EA's profile and permitted values.

Onboarding gives the interface a description of the EA

An input name alone does not explain its meaning. Risk might be a percentage, a fixed lot size or an enumeration. The interface needs that information before it can turn a sentence into a useful request.

During onboarding, an EA author can provide a compatibility profile describing the inputs: names, types, units, permitted ranges, individually editable settings and defined presets. The author reviews that information and submits the profile for review before publication.

This is where onboarding helps customers. A published, matching profile gives the interface a definition of the settings it may offer. Instead of asking every customer to work out what an ambiguous field means, the author can explain it in the profile. A named preset can describe a particular set of changes, which the customer still reviews before applying.

The profile does not replace the EA or its licence. It describes how the interface may interact with its inputs; it does not establish that a configuration will be profitable or that every EA behaves identically after reinitialization.

Resolve the target and ask for a preview

The REST API uses Bearer authentication. Keep the key in your application backend. A client-scoped key is restricted to one customer; a tenant integration must supply the appropriate client_id and enforce its own user-to-customer access mapping.

These are the relevant resources:

Request Purpose
GET /v1/clients/{client_id}/state Find accounts and running EA instances, and inspect reported state and freshness.
GET /v1/eas/{ea_id} Read the EA's caller-visible parameter definitions and permissions.
POST /v1/accounts/{account_id}/commands Preview or submit a command, depending on dry_run.
GET /v1/commands/{command_id}?wait=30 Wait for an outcome, or receive the current status if it is still pending.

Use the account_id and instance_id returned by the API. An EA name or a symbol alone is ambiguous when several charts run the same EA. Reported inputs may also be old or partial. The read_ea_inputs command requests a fresh read without changing inputs; inspect its freshness and missing-input information before using the result as a baseline.

For a hypothetical profile that permits MaxSpread=25, a preview request with a client-scoped key looks like this:

POST /v1/accounts/acc_example/commands HTTP/1.1
Host: api.algohand.com
Authorization: Bearer <CLIENT_API_KEY>
Content-Type: application/json

{
  "type": "set_param",
  "dry_run": true,
  "params": {
    "instance_id": "inst_example",
    "inputs": {
      "MaxSpread": 25
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

A successful preview returns HTTP 200, including a summary, resolved.diff, warnings and a preview_hash. It does not queue the change. Set dry_run explicitly: the raw REST command model defaults to execution, unlike the preview-first chat tools.

Confirmation belongs in the interface

Show the target, before-and-after values and warnings to the user. Store the approved request and its preview_hash in your backend. After explicit confirmation, submit the same action with dry_run: false and the saved hash as expected_preview_hash.

The server checks the request again. If the supplied hash no longer matches the resolved plan, it returns HTTP 409 with PREVIEW_STALE without queuing that change. Obtain a new preview and confirmation. The hash is a plan precondition, not proof of consent; the integrating application must enforce approval itself. AlgoHand's own chat provides that approval flow.

For the execution request, also persist an Idempotency-Key with the exact action. If delivery is uncertain, reuse that key for the same request rather than generating a new one. Within the documented replay window, the server returns the original command; reusing a key with a different action or account is a conflict.

Request, validation, confirmation, application and result checking

Conceptual workflow for an interactive settings change. Previously configured automated rules have their own authorization policy.

HTTP 202 means the command has been accepted, not that MetaTrader has finished. Follow the returned command_id and report the actual status, result and any error. Keep input readback separate from initialization evidence; an unclear result needs inspection before another attempt.

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

Profile rules and current account conditions can refuse a change. Stale observations, open positions and pending orders matter here. A controller should also avoid applying an old input snapshot over manual changes made in the terminal.

REST, chat tools and the Windows agent

A custom web or desktop interface can use the REST API directly through its backend. An AI interface can expose structured tools such as get_client_state, get_ea, set_param and get_command. AlgoHand also has an MCP wrapper over the API, using stdio transport, for clients that support that protocol.

MCP is an adapter, not an approval mechanism. The current wrapper exposes preview-first parameter tools but does not itself implement the REST preview-hash and idempotency workflow described above. An integration must provide the controls it needs; a model instruction to “ask first” should not be its only approval check.

On the Windows side, the agent polls outbound over HTTPS, receives queued commands and communicates with the manager inside MetaTrader. MT5 normally uses a manager service; MT4 uses a manager EA. They share the public command model, but their terminal integrations are different and need separate tests. The machine, agent and terminal must be running and connected for execution.

For a customer, the visible interaction can stay short: request a setting, review the change, confirm it and read the result. For an EA author, onboarding supplies the parameter definitions behind that interaction. For an interface developer, the work is to preserve those definitions, the customer's approval and the command's actual outcome across the API boundary.

The endpoint reference is available in the AlgoHand API documentation, with the request schemas in the OpenAPI specification.

Top comments (0)