Skip to main content

What you’ll build

In this tutorial, you will build a monitor that:
  1. reads DerivaDEX market state,
  2. reads one external venue quote stream,
  3. computes a net spread,
  4. alerts only when the spread persists,
  5. records the context needed for later manual or automated execution.

Prerequisites

Step 1: Choose one narrow comparison

Start with one product such as ETHP and one external venue quote source. For the first version, do not try to route live trades. Build only the monitor.

Step 2: Read DerivaDEX state from one canonical path

Capture the local market context from DerivaDEX with:
  1. MARK_PRICE for the current risk price,
  2. ORDER_BOOK_L2 or ORDER_BOOK_L3 for executable depth.
Record timestamps with every update.

Step 3: Read the external quote stream

Connect to one external best-bid and best-ask source for the same underlying market. Normalize the payload into the same simple shape you use for DerivaDEX:
  • best bid
  • best ask
  • timestamp

Step 4: Compute a net spread instead of a raw difference

For each side you care about, subtract the costs that would matter in practice:
  1. fees,
  2. expected slippage from visible depth,
  3. stale-data tolerance,
  4. any funding or carry assumptions you are using in the monitor.
Only alert on the net spread, not the headline price gap.

Step 5: Require persistence before alerting

Do not alert on a single transient tick. Require the divergence to hold across multiple consecutive observations or a minimum time window before it becomes actionable.

Step 6: Record enough context for a real follow-up decision

When a spread qualifies, log:
  1. DerivaDEX mark price,
  2. visible DerivaDEX book levels used for the estimate,
  3. external venue quote,
  4. computed net spread,
  5. timestamps for both sides.
This log is the minimum payload you need before deciding whether to automate later.

Step 7: Keep sequencing and finality separate from the alert

This monitor is complete without submitting any order. Treat the alert as a signal for later action, not as proof that a trade would already have filled on both sides under live conditions.

Step 8: Finish with one durable alert run

This tutorial is complete when the monitor:
  1. ingests both feeds,
  2. computes the net spread repeatedly,
  3. emits at least one persistent alert,
  4. records enough context for later review.

Next routes

Last modified on April 13, 2026