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...
A nonce is a number used once that keeps every private exchange API request unique and in order. Here is what a nonce is, why exchanges require one, and why nonce errors break automated trading.
Your TradingView alert fired, your automation sent the order, and the exchange answered with something cryptic: `invalid nonce` or `nonce must be greater than the last value`. The trade never reached the book. If you have ever automated crypto orders, you have probably met this error at the worst possible moment. Understanding what a nonce in an exchange API request actually is — and why it exists — turns one of the most confusing rejection messages into a solved problem.
This guide explains what a nonce is, why exchanges require one on private API calls, how it quietly protects your account, and where nonce errors come from when automation moves fast.
A nonce is a "number used once." It is a value your client attaches to every private, signed request it sends to a crypto exchange — the calls that place orders, cancel orders, or read your balances. The rule is simple: each new request must carry a nonce that is larger than the nonce on the previous request from the same API key.
Most exchanges expect the nonce to always increase. The value is included in the data your client signs with your API secret, so the exchange can confirm two things at once: that the request came from someone holding your secret, and that it is a fresh request rather than an old one being replayed.
Public endpoints — market data, order books, ticker prices — usually do not need a nonce, because they are not tied to your account. The nonce belongs to the authenticated side of the API, where actions have consequences.
The core job of a nonce is to stop replay attacks. Imagine an attacker captures one of your signed order requests as it travels across the network. Without a nonce, that captured request would be valid forever. The attacker could resend it a hundred times and the exchange would happily execute each copy, because the signature checks out.
A monotonically increasing nonce closes that door. Once the exchange has seen nonce 1700000000001, it will reject any later request that reuses that number or anything smaller. The captured request becomes stale the instant a newer one arrives. This is why nonce handling sits alongside other account-protection layers such as trade-only API key permissions, which limit what a key can do even if it is exposed.
The nonce also enforces ordering. In automated trading, the sequence of actions matters — you want an entry to register before its stop, and a cancel to land before a replacement. Requiring an ever-increasing value gives the exchange a clean way to reason about which instruction came first.
Nonces do more than block attackers. They also protect you from your own automation misfiring. If a network hiccup causes your client to retry a request, a well-designed nonce scheme means the exchange can recognize and reject the stale duplicate instead of opening a second position you never intended.
That said, a nonce alone is not a complete defense against duplicate orders — it prevents the same signed request from being reused, but a retry that generates a brand-new nonce is a genuinely new order to the exchange. Preventing accidental double-fills needs a separate mechanism, which is why robust systems pair nonce handling with idempotency keys that stop duplicate trades. The two work together: the nonce keeps requests unique and ordered at the transport layer, while idempotency keeps intents unique at the application layer.
Exchanges accept a few common styles, and the right one depends on the venue:
Each exchange documents which format it expects and how large the value may be, so automation has to match the specific venue rather than assume one universal rule.
Nonce errors almost always come down to one of a handful of causes:
Because these failures surface as rejected orders, they belong to the same family of problems as other execution failures. If you are building your own stack, our guide on handling failed and rejected orders in a trading bot covers how to detect, classify, and respond to them so a single nonce hiccup does not silently drop a trade.
Getting nonces right by hand means keeping accurate clocks, serializing requests per key, persisting counters across restarts, and never letting two components share a key carelessly. It is solvable, but it is fiddly infrastructure that has nothing to do with your actual trading logic.
This is the layer SignalToExchange is built to own. When a signal comes in from TradingView or an automation platform, the relay generates and sequences a valid, monotonically increasing nonce for each exchange call, serializes requests per key so concurrent signals do not collide, and manages the signing so your credentials never leave the encrypted boundary. You keep your funds on your own exchange and connect trade-only keys with no withdrawal access. You control the logic; the relay handles the mechanics of talking to the exchange correctly.
Whether you build it yourself or use a relay, the same principles apply:
No. Your API key identifies your account and your API secret signs requests. The nonce is a per-request value that rides inside the signed payload to keep each request unique and ordered. All three play different roles in authenticating a private call.
It means the exchange received a nonce that was equal to or smaller than the last one it accepted for that key. The usual culprits are a backward clock jump, two processes sharing a key, or a replayed request. The fix is to ensure every request uses a strictly larger value.
Only if you are calling exchange APIs directly. If you route signals through a relay such as SignalToExchange, nonce generation, sequencing, and signing are handled for you, so a misconfigured clock or a concurrent signal does not turn into a rejected order.
Not entirely. A nonce stops the same signed request from being replayed, but a retry with a fresh nonce is a new order to the exchange. Preventing double-fills needs idempotency keys layered on top of nonce handling.
Nonces are a small detail with an outsized ability to break automated trading when they go wrong. They protect your account from replays and keep your requests in order — but only when the clock, the sequencing, and the signing are all handled correctly. That is exactly the kind of unglamorous infrastructure a dedicated relay layer exists to absorb, so you can focus on your signals instead of debugging rejection codes. SignalToExchange keeps your funds on your own exchange, uses trade-only keys with no withdrawal access, and takes care of the exchange-side mechanics for you. Request access or start your free trial to route your signals through infrastructure that gets the details right.
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.