Gateway Execution Reconciliation¶
These administrative commands inspect and reconcile the durable execution
journal used by MT5-routed trades. They do not submit or resend an operation to
the provider. Both commands require an administrator session with the
super_admin permission. The same routes are available over HTTP as described
in the client REST reference.
The journal is stored separately from the trading bases at
var/sttrader/gateway-executions.db. It is synchronously persisted and is not
removed when a trading base is restored. On startup, an unresolved submission
is retained and the server does not automatically replay it. A SENT record
becomes UNCERTAIN after restart; an interrupted APPLYING record becomes
EXECUTED and needs operator follow-up after checking local trade state.
For machine migration, preserve the journal database and its SQLite WAL state
consistently. While the server is online, use a SQLite-consistent backup method
or capture the database and its -wal/-shm sidecars from the same snapshot;
do not copy only the database file while it is active. The journal is separate
from restorable trading-base backups and must be migrated independently.
Trading storage normally uses WAL with synchronous=NORMAL. A batch containing
an active MT5 execution temporarily uses synchronous=FULL for its SQL commit;
ordinary batches keep their existing mode. The journal releases the execution
only after the final retained trade row is durably committed. This does not
require a full checkpoint to wait on unrelated long-running readers. If an
acknowledgement lacks that durability proof, including manual inspection of
existing SQL evidence, a complete WAL checkpoint is required instead. A busy or
failed checkpoint keeps the operation blocked; background retries can confirm
an already-committed row without sending another provider request or modifying
the trade. These retries are not automatic provider reconciliation.
Gateway configuration updates and deletion are blocked with
GATEWAY_EXECUTION_UNCERTAIN (HTTP409) while that gateway has unresolved
executions. Configuration mutation is serialized with pre-send admission so it
cannot change the provider identity between validation and journal creation.
Stopping or restarting the runtime does not remove the journal lock.
MngGetGatewayExecutions¶
GET /gateways/executions
Lists unresolved executions by default. Set unresolved_only to false to
inspect recent terminal records. Historical results include at most the most
recent 500 journal records before gateway filtering and pagination.
Request¶
{
"command": "MngGetGatewayExecutions",
"unresolved_only": true,
"gateway_id": 12,
"offset": 0,
"limit": 100
}
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
unresolved_only |
bool | No | true |
Return records still requiring operator or local-apply completion. |
gateway_id |
int | No | — | Filter by a positive gateway configuration ID. |
offset |
int | No | 0 |
Number of matching records to skip. Must be non-negative. |
limit |
int | No | 100 |
Maximum rows; range 1–500. |
Response¶
count is the number of matching records before pagination. rows contains
the page of records.
{
"rows": [
{
"execution_id": "0123456789abcdef0123456789abcdef",
"gateway_id": 12,
"login": 2000001,
"order": 900100,
"symbol": "EURUSD",
"provider_symbol": "EURUSD.a",
"operation": 1,
"volume": 10000,
"before_volume": 10000,
"before_closed_volume": 0,
"correlation_id": 778812,
"state": "UNCERTAIN",
"code": "GATEWAY_TIMEOUT",
"request_json": "{\"operation\":1,\"login\":2000001,\"order\":900100,\"open_time\":1794500000,\"source_symbol\":\"EURUSD\",\"target_symbol\":\"EURUSD.a\",\"cmd\":0,\"volume\":10000,\"lots\":100,\"price\":1.0845,\"sl\":0,\"tp\":0,\"parent_order\":0,\"gw_source\":\"\",\"gw_uuid\":\"\",\"gw_order\":\"\",\"gw_volume\":0,\"timeout_ms\":5000,\"trade_context\":\"{\\\"commission\\\":0,\\\"storage\\\":0,\\\"magic\\\":0,\\\"reason\\\":3,\\\"comment\\\":\\\"\\\",\\\"expiration\\\":0,\\\"close_time\\\":0}\"}",
"provider_order": "",
"provider_uuid": "",
"provider_source": "MT5",
"provider_deal": "",
"provider_request_order": "mt5-request-98765",
"provider_volume": 0,
"price": 0,
"created_at": 1794500000,
"updated_at": 1794500005,
"resolved_by": 0,
"resolution_note": ""
}
],
"count": 1
}
| Field | Type | Description |
|---|---|---|
execution_id |
string | 32-character hexadecimal journal ID used by reconciliation. |
gateway_id |
int | Gateway configuration ID. |
login |
int | SCT account login. |
order |
int | SCT order reserved for this operation. |
symbol |
string | SCT symbol. |
provider_symbol |
string | Mapped provider symbol. |
operation |
int | Internal operation kind: 1 open, 2 close, 3 partial close. |
volume |
int | Requested operation volume in SCT integer volume units. |
before_volume |
int | For OPEN, the requested position volume; for CLOSE/PARTIAL_CLOSE, the remaining position volume before the operation. |
before_closed_volume |
int | Position closed volume captured before a close operation. |
correlation_id |
uint64 | Gateway request correlation identifier. |
state |
string | Journal state: SENT, UNCERTAIN, EXECUTED, APPLYING, LOCAL_APPLIED, or NOT_EXECUTED. |
code |
string | Last execution or local-application code; empty when none was recorded. |
request_json |
string | Captured serialized request context used for controlled local application. |
provider_order |
string | Provider position ticket, when known. |
provider_uuid |
string | Provider UUID, when supplied. |
provider_source |
string | Provider identifier, for this safety flow MT5. |
provider_deal |
string | Provider deal identifier, when supplied. |
provider_request_order |
string | Provider request/order identifier, when supplied. |
provider_volume |
int | Provider-reported executed volume in SCT integer volume units. |
price |
number | Provider-reported execution price. |
created_at |
int64 | Journal creation time as Unix seconds. |
updated_at |
int64 | Last journal update time as Unix seconds. |
resolved_by |
int | Administrator ID that recorded a manual resolution; 0 if unresolved. |
resolution_note |
string | Operator note attached to a manual resolution. |
If the execution journal is not ready, the command returns HTTP-style status
503 and error: EXECUTION_JOURNAL_UNAVAILABLE (without a message). Invalid
query fields return 400 INVALID_DATA; access requires SESSION_ADMIN and
super_admin.
MngReconcileGatewayExecution¶
POST /gateway/execution/reconcile
Records an operator decision and, for an EXECUTED decision, attempts to apply
the confirmed outcome to the local trading state. No provider command is sent.
An APPLYING record means local application is pending or has not committed;
repeat the reconciliation query, not the trade request.
Request: confirmed execution¶
{
"command": "MngReconcileGatewayExecution",
"execution_id": "0123456789abcdef0123456789abcdef",
"resolution": "EXECUTED",
"note": "Verified against MT5 position history",
"provider_order": "123456789",
"provider_uuid": "mt5-position-123456789",
"provider_volume": 10000,
"price": 1.08452,
"local_price": 1.0845,
"commission": -2.5
}
For a market CLOSE with captured request price 0, provide the verified SCT
close price as local_price:
{
"command": "MngReconcileGatewayExecution",
"execution_id": "0123456789abcdef0123456789abcdef",
"resolution": "EXECUTED",
"note": "Verified against MT5 deal history",
"provider_order": "123456789",
"provider_volume": 10000,
"price": 1.08452,
"local_price": 1.0845
}
Request: confirmed non-execution¶
{
"command": "MngReconcileGatewayExecution",
"execution_id": "0123456789abcdef0123456789abcdef",
"resolution": "NOT_EXECUTED",
"note": "Verified that no matching MT5 position or deal exists"
}
| Field | Type | Required | Description |
|---|---|---|---|
execution_id |
string | Yes | Journal ID, exactly 32 characters. |
resolution |
string | Yes | EXECUTED or NOT_EXECUTED. |
note |
string | Yes | Operator's reason, 1–2048 characters. |
provider_order |
string | For EXECUTED |
Confirmed non-zero MT5 position ticket, up to 32 characters. |
provider_uuid |
string | No | Confirmed provider UUID, up to 128 characters. |
provider_volume |
int | For EXECUTED |
Positive executed volume in SCT integer volume units; cannot exceed requested volume. |
price |
number | For EXECUTED |
Positive confirmed MT5 provider execution price. Manual reconciliation requires a positive value even if a normal market-close result omitted its external close price. |
local_price |
number | Conditional | Positive SCT execution price used for local application. Required when the captured request price is non-positive; otherwise omitted to use the captured price. |
commission |
number | Conditional | Signed commission in the account currency. Required when an OPEN execution is partially filled. |
For a partial OPEN, enter the actual signed commission confirmed by the
provider. The server does not prorate the requested commission automatically.
MT5 partial closes preserve the position's existing gw_uuid and record the
provider close price in gw_close_price; this metadata retention is specific
to MT5 execution.
For a confirmed execution, the server records the provider identity and
execution details, then applies the outcome locally using the captured SCT
request price (or local_price) and time together with the confirmed provider
price and volume. The local close time uses the original journal submission
time (created_at), not the time of manual reconciliation.
An open already reflected in the local SQL trade journal can be recognized and
marked applied without importing it again. The response reports
local_apply_pending: true only while the record is APPLYING.
While normal execution is in SENT, EXECUTED, or APPLYING, another trade
request for the same login and symbol receives GATEWAY_EXECUTION_IN_PROGRESS.
This is a temporary execution lock, not a request for manual reconciliation;
if the original operation commits, the journal changes to LOCAL_APPLIED and
the lock clears. An APPLYING reconciliation submission itself returns
GATEWAY_EXECUTION_IN_PROGRESS, without resending to MT5 or starting a second
local application.
If a confirmed EXECUTED record remains unresolved after a restart or local
apply failure, inspect local trade state before manually repeating the same
EXECUTED reconciliation. If the corresponding trade was already committed,
the journal can recognize it and mark the entry LOCAL_APPLIED; otherwise the
confirmed operation is applied locally. This is a local recovery step, never a
provider retry.
If a matching local trade row was already committed, the journal can recognize
its identity and volume and mark the entry applied. This acknowledgement does
not rewrite the already-booked trade price; local_price affects only a new
local application.
NOT_EXECUTED is an operator attestation and is accepted only for an uncertain
outcome with no recorded execution evidence. It releases the execution lock
only after the operator confirms that the provider did not execute the request.
It is rejected when the journal records a positive filled volume or a non-zero
numeric MT5 deal/UUID identifier. An in-flight SENT request cannot be
resolved; confirmed EXECUTED or APPLYING outcomes cannot be discarded as
not executed. A terminal provider result that arrives after its request
correlation expires is not applied automatically; reconcile it manually using
provider evidence.
Response¶
{
"execution": {
"execution_id": "0123456789abcdef0123456789abcdef",
"gateway_id": 12,
"login": 2000001,
"order": 900100,
"symbol": "EURUSD",
"provider_symbol": "EURUSD.a",
"operation": 1,
"volume": 10000,
"before_volume": 10000,
"before_closed_volume": 0,
"correlation_id": 778812,
"state": "LOCAL_APPLIED",
"code": "",
"request_json": "{\"operation\":1,\"login\":2000001,\"order\":900100,\"open_time\":1794500000,\"source_symbol\":\"EURUSD\",\"target_symbol\":\"EURUSD.a\",\"cmd\":0,\"volume\":10000,\"lots\":100,\"price\":1.0845,\"sl\":0,\"tp\":0,\"parent_order\":0,\"gw_source\":\"\",\"gw_uuid\":\"\",\"gw_order\":\"\",\"gw_volume\":0,\"timeout_ms\":5000,\"trade_context\":\"{\\\"commission\\\":0,\\\"storage\\\":0,\\\"magic\\\":0,\\\"reason\\\":3,\\\"comment\\\":\\\"\\\",\\\"expiration\\\":0,\\\"close_time\\\":0}\"}",
"provider_order": "123456789",
"provider_uuid": "mt5-position-123456789",
"provider_source": "MT5",
"provider_deal": "",
"provider_request_order": "",
"provider_volume": 10000,
"price": 1.08452,
"created_at": 1794500000,
"updated_at": 1794500100,
"resolved_by": 7,
"resolution_note": "Verified against MT5 position history"
},
"local_apply_pending": false
}
Errors¶
| HTTP-style status | Error | Meaning |
|---|---|---|
400 |
INVALID_DATA |
Missing/invalid input, invalid execution details, missing local_price when the captured price is non-positive, or a partial OPEN execution without commission. |
400 |
RET_TRADE_INCORRECT_STATE |
Journal/local trade state is incompatible, or NOT_EXECUTED is requested despite recorded execution evidence. |
404 |
RET_NOT_FOUND |
Execution ID does not exist in the journal. |
409 |
RET_DUPLICATE_RECORD |
A terminal local result exists or the submitted provider identity, volume, or known positive provider price conflicts with the confirmed result. |
409 |
RET_GATEWAY_EXECUTION_IN_PROGRESS |
Local application is already in progress. |
500 |
RET_TRADE_ORDER_LOCKED |
The request is still in-flight (SENT) and cannot be manually reconciled yet. |
500 |
RET_TECH_PROBLEM / RET_ERROR |
Journal, restore barrier, or local operation failed. |
The MngReconcileGatewayExecution command is journaled with the full request
and response. Never use a trade retry to clear an uncertain record.