What you’ll build
In this tutorial, you will implement a minimal market-making bot workflow:- Subscribe to realtime market data.
- Build a simple quote decision.
- Sign a request with EIP-712.
- Encrypt the request for the operator.
- Submit to
/v2/request. - Track
ORDER_UPDATEand strategy events.
Prerequisites
- One funded DerivaDEX strategy in the same environment as the endpoints you will use.
- Ability to connect to matching realtime WebSocket and REST endpoints for that same environment.
- One signing wallet with authority over that strategy and one execution environment that can reach those endpoints.
Step 1: Subscribe to live market data
Connect to:wss://exchange.derivadex.com/realtime-api
The current public realtime docs use the production endpoint above. If you target another environment, keep the WebSocket URL, REST base URL, funded strategy, and signing key in that same environment.
Start with one feed such as MARK_PRICE for ETHP, then add ORDER_BOOK_L2.
For the shortest current public WebSocket path, use Realtime Quickstart.
Step 2: Define minimal quote logic
Use a simple rule:- Read current mark price.
- Place one buy quote slightly below mark.
- Place one sell quote slightly above mark.
- Keep quote size aligned to minimum order-size increments.
Step 3: Build a signable request
DerivaDEX client requests are EIP-712 signed and include nonce and timing fields for replay protection. At minimum, ensure:- stable trader identity
- strategy identifier
- order details (symbol, side, amount, price, type)
- nonce and client timestamp window
Step 4: Sign with EIP-712
Sign the request payload with the wallet that controls the strategy. If signature recovery does not match trader identity, the request can fail withSignatureRecoveryMismatch.
Reference and detailed implementation:
Step 5: Encrypt and submit request
Before submission:- Fetch operator encryption key from
/v2/encryption-key. - Generate ephemeral secret key and nonce.
- Encrypt request bytes.
- Submit encrypted payload to
/v2/request.
Step 6: Handle immediate response and retries
On submission, handle:- success receipt
- rate-limit response (
429) - safety failure (
422) - transient service unavailability (
503)
Step 7: Track order lifecycle and account updates
Use REST snapshot plus realtime updates:- Bootstrap current state from REST.
- Subscribe to
ORDER_UPDATE,STRATEGY_UPDATE, andTRADER_UPDATE. - Correlate updates by order identity and ordinals.
- How to Track an Order Through Its Lifecycle
- How to Handle Order Sequencing vs Execution
- Order and Account Event Reference
Step 8: Verify safety boundaries in logs
Confirm your bot stays inside core guardrails:- tick-size and minimum-order-size validation
- notional cap and price-band validation
- collateral sufficiency and
OMF >= IMFchecks