A partially filled order is a live portfolio state, not merely an error message. The system must distinguish requested quantity, confirmed fills, remaining quantity and cancellation status. Acting on the original instruction as though it were wholly filled or wholly absent can create unintended exposure.
The execution economics
Orders and deals are different records. One instruction may produce multiple executions at different prices, and a cancellation request can race with another fill. Reconcile using stable broker identifiers and cumulative quantities rather than assuming one response maps to one completed trade.
This also affects performance analysis. Average execution price should be quantity-weighted, while remaining exposure may need a new decision under changed market conditions. A strategy that assumes its full hedge was executed can retain a risk that is invisible in its intended-position model.
A worked example
An instruction requests 100 units. The broker confirms 40 at $50.00 and 35 at $50.02, leaving 25 outstanding. Confirmed exposure is 75 units at a weighted average of about $50.0093. If a timeout triggers a fresh 100-unit instruction without reconciliation, the account could end up with 175 units before considering the original remainder. Repeating the original request is not a safe recovery rule.
Practical review and implementation
Maintain a state machine for submitted, acknowledged, partially filled, filled, cancellation pending and cancelled states. Process fills idempotently by execution identifier and reconcile the broker’s current state after uncertain responses. Separate the authorised target from the outstanding order. Log quantities and timestamps so operations can explain how an exposure arose without relying on a screenshot alone.
Assumptions and limitations
Broker and venue semantics vary, including whether an order allows partial execution and how late reports arrive. A locally consistent state machine still needs authoritative broker reconciliation. The MetaQuotes return-code and deal references describe platform fields; they do not guarantee every broker will resolve an uncertain event identically.
Primary references
Further detail on the underlying concepts and data definitions:
