WebSocket vs REST APIs on Crypto Exchanges: What's the Difference
If you are wiring a strategy up to an exchange, one of the first technical forks you hit is WebSocket vs REST APIs on a crypto exchange. Both let your code talk...
Why automated trading systems sometimes place the same order twice, and how idempotency keys ensure that one signal fires exactly one order.
If you run a trading bot long enough, you will eventually see it: two identical orders, seconds apart, that you only meant to place once. Duplicate orders are one of the most common ways a trading bot quietly damages an account — they double your position size, double your fees, and can flip a carefully sized trade into an oversized one. The fix is a well-established engineering pattern: the idempotency key. This guide explains why duplicates happen, what idempotency means in practice, and how to prevent duplicate orders in any trading bot or webhook pipeline.
Duplicates almost never come from your strategy. They come from the plumbing between your signal source and the exchange. Three failure modes account for most of them.
When TradingView (or any signal source) sends a webhook and doesn't get a fast, successful response, it may retry. That's good behavior — it's how the alert survives a transient network blip. But if your execution layer treats every incoming request as a brand-new instruction, one alert becomes two orders. The retry that was supposed to protect you is now working against you.
Your bot sends an order to the exchange and the connection times out before the response arrives. Did the order go through? The honest answer is: you don't know. A naive bot resubmits, and if the first request actually succeeded, you now hold double the position. This is the classic distributed-systems problem — a timeout is not a failure, it's an unknown.
Most reliable systems use a message queue between signal intake and order dispatch. Queues typically guarantee at-least-once delivery, which means a message can be delivered more than once under failure conditions. Without deduplication, every redelivery is another order.
An operation is idempotent when performing it twice has the same effect as performing it once. An idempotency key is how you make order placement idempotent: a unique identifier attached to each logical instruction — for example, a UUID generated when the signal is first received.
Every system that touches the order checks the key before acting:
The result is a simple property: one signal fires exactly one order, no matter how many times any individual step is retried.
The exchange-level check deserves emphasis. Even if every upstream layer fails — your dedup cache expires, your queue redelivers, your connector retries after a timeout — a stable client order ID means the exchange recognizes the resubmission as the same order. That timeout scenario from earlier stops being dangerous: the bot can safely retry, because the worst case is the exchange saying "already have it."
This is why a stable, deterministic client order ID derived from the idempotency key is stronger than a random one generated at send time. Random IDs make every retry look like a new order. Deterministic IDs make retries harmless.
SignalToExchange treats deduplication as core infrastructure, not an option you configure. Each incoming signal is assigned an idempotency key at the API edge. Keys are retained for 24 hours at intake, messages are deduplicated again in the queue, and every exchange order carries a client order ID derived from the original key. Each layer is independent, so a failure in one doesn't compromise the protection.
Because the platform is non-custodial and uses trade-only API keys, the blast radius of any failure is limited by design: your funds never leave your exchange, and the keys you provide can place orders but never withdraw. If you want the background on that model, read our guide on why trade-only API keys matter.
If you're still setting up your signal pipeline, our TradingView webhook to exchange setup guide covers the intake side in detail.
Signals are easy. Execution is hard. A strategy that's right 60% of the time can still lose money if the execution layer occasionally doubles a position or drops an order. Idempotency keys are one of the unglamorous mechanisms that make automated execution trustworthy — and they're exactly the kind of infrastructure you shouldn't have to build yourself. SignalToExchange routes your TradingView and webhook signals to your exchange with deduplication at every layer, using trade-only API keys on a non-custodial design. Request access / start your free trial →
Automated trading involves risk. SignalToExchange is execution infrastructure and does not provide financial advice, trading signals, or guarantees of any kind.
Non-custodial execution. Trade-only API keys. Independent infrastructure built for reliability.
Request Early AccessTrade-only API key enforcement. No withdrawal permissions. No custody.