Skip to main content
All CollectionsDeveloper FAQs
Can users set any nonce value, and how does the system handle collisions?
Can users set any nonce value, and how does the system handle collisions?
Updated over a month ago

Yes, users can set any nonce value within the 32-bit limit (uint32_t). The nonce acts as a deconflicting mechanism to allow users to send multiple identical orders (with the same parameters such as market type, time-in-force, post-only/reduce-only flags, legs, and expiration timestamp) while still generating unique signatures. Each nonce ensures that even if every other attribute of the order is the same, the signature remains unique.

When a user submits an order, if the same nonce has already been used for an identical order (i.e., all parameters match) for the same user, the order will be rejected to prevent replay attacks. If the nonce is unique, the system accepts the order and stores the nonce to prevent future reuse for that user.

If a user wishes to create the exact same order multiple times, they can do so by using different nonces. In theory, this allows up to 4 billion unique orders with identical content by using different nonce values. However, in practice, it is very unlikely that a user would need to generate that many identical orders.

Recommendations for generating nonce

1. Atomic Rotating Counter - Implement an atomic rotating counter to generate nonces. With this approach, you’ll never rotate past 2 billion nonces within a nanosecond, ensuring uniqueness even with high-frequency requests.

2. Use Timestamp Directly - Using a timestamp as a nonce is practical because machine instructions typically take more than 1 nanosecond to execute. This makes the risk of reusing a nonce within the same nanosecond extremely unlikely, effectively preventing collisions.

Did this answer your question?