Client Order ID
Also known as: idempotency key, clOrdID, client order reference, order deduplication key
What is it?
A client order ID is a unique reference string that your own code attaches to every order request it sends a broker or exchange, so that if the same request arrives twice the venue recognises it and returns the original order instead of opening a second position. You generate the value, not the broker: the broker generates its own order ticket after the order is accepted, but the client order ID is the label you controlled before the request ever left your machine. It exists because network calls fail in the worst possible way.
sequenceDiagram
autonumber
participant Bot
participant Broker
Bot->>Broker: Place order, ID sig-88421
Note over Bot,Broker: Reply lost, timeout
Bot->>Broker: Retry, same ID sig-88421
alt ID already seen
Broker-->>Bot: Return the original order
Note over Broker: No second position opened
else ID is new
Broker-->>Bot: Accept as a new order
end
When your bot posts an order and the connection times out before a reply comes back, you genuinely do not know whether the venue received it. Retrying risks a duplicate position; not retrying risks missing the trade entirely. With a client order ID the choice disappears — you retry the identical request, and the venue either accepts it as new or replies with the order it already created under that same ID.
Say your webhook receiver sends a 0.50-lot EUR/USD buy tagged `sig-88421-eurusd-buy` and the reply never arrives. It fires the same request twice more; because all three carry `sig-88421-eurusd-buy`, you end up with exactly one 0.50-lot position rather than 1.50 lots. This is different from MT4/MT5's magic number, which tags positions inside a terminal so an Expert Advisor can tell its own trades apart — a magic number is not unique per request and does nothing to stop a duplicate order over a REST or FIX connection.
Why it matters: It is what makes an automated order safe to retry after a timeout, so a dropped reply or a replayed alert cannot quietly double your position size.
Without it, a single network timeout can double your intended exposure on a live account before you notice.
Real-world example
A TradingView alert fires twice during a webhook retry storm; both requests carry the ID `btc-brk-1043`, so the exchange fills one 0.2 BTC order and returns that same order for the duplicate.
How SignalBots handles it
The SignalBots MT4/MT5 Connector and webhook endpoints tag each forwarded signal with its own unique reference, so a retried delivery reconciles to the trade you already have rather than opening a second one. See /risk-warning.
Pro tip
Derive the ID from the signal itself — its id plus symbol plus side — not from a timestamp or random value, or a retry generates a fresh ID and defeats the whole mechanism.
Common pitfalls
Generating a new ID on every attempt, which makes each retry look like a brand-new order and produces exactly the duplicate fills the ID was meant to prevent.
Frequently asked questions
Is a client order ID the same as a magic number?
No. A magic number tags positions inside an MT4 or MT5 terminal so an Expert Advisor recognises its own trades. A client order ID identifies a single API request end to end, and is what a broker checks to reject a duplicate submission.
Do all brokers support it?
Most REST and FIX venues do, though the field name varies — clOrdID, clientOrderId, newClientOrderId. Check whether your broker actually enforces uniqueness or merely echoes the value back, because an echoed-only field gives you no protection.
How long does a venue remember an ID?
Typically hours to days, and it varies by broker. Once the retention window expires the same ID may be accepted again as a fresh order, so treat it as protection against retries within a session, not a permanent lock.
What should the ID actually contain?
Something deterministic that identifies the trading intent — for example the signal id, symbol and direction combined. It must regenerate identically if your code retries the same intent, and differ for any genuinely new order.
Does this remove the risk of automated trading?
No. It removes one specific failure mode, accidental duplicate orders. Slippage, gaps, rejected orders and losing trades remain, and your capital is still at risk on every position. See /risk-warning.
Trading involves substantial risk of loss. Historical and backtested results do not guarantee future performance. Read the full risk warning.