Skip to main content

What you’ll build

In this tutorial, you will implement a minimal market-making bot workflow:
  1. Subscribe to realtime market data.
  2. Build a simple quote decision.
  3. Sign a request with EIP-712.
  4. Encrypt the request for the operator.
  5. Submit to /v2/request.
  6. Track ORDER_UPDATE and 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:
  1. Read current mark price.
  2. Place one buy quote slightly below mark.
  3. Place one sell quote slightly above mark.
  4. Keep quote size aligned to minimum order-size increments.
Keep notional below the maximum order notional and within price-band constraints.

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 with SignatureRecoveryMismatch. Reference and detailed implementation:

Step 5: Encrypt and submit request

Before submission:
  1. Fetch operator encryption key from /v2/encryption-key.
  2. Generate ephemeral secret key and nonce.
  3. Encrypt request bytes.
  4. Submit encrypted payload to /v2/request.
Reference and detailed implementation:

Step 6: Handle immediate response and retries

On submission, handle:
  • success receipt
  • rate-limit response (429)
  • safety failure (422)
  • transient service unavailability (503)
Do not blindly retry all failures. Use failure class to choose retry, repair, or stop.

Step 7: Track order lifecycle and account updates

Use REST snapshot plus realtime updates:
  1. Bootstrap current state from REST.
  2. Subscribe to ORDER_UPDATE, STRATEGY_UPDATE, and TRADER_UPDATE.
  3. Correlate updates by order identity and ordinals.
Detailed tracking and sequencing behavior:

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 >= IMF checks
Reference:

Next routes

Last modified on April 13, 2026