What you’ll build
In this tutorial, you will build a monitor that:- reads DerivaDEX market state,
- reads one external venue quote stream,
- computes a net spread,
- alerts only when the spread persists,
- records the context needed for later manual or automated execution.
Prerequisites
- A working
ddx-pythonsetup. - The market-data flow from WebSocket Realtime Data Tutorial.
- The order-book and mark-price vocabulary from Understanding the Trading Interface.
Step 1: Choose one narrow comparison
Start with one product such asETHP 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:MARK_PRICEfor the current risk price,ORDER_BOOK_L2orORDER_BOOK_L3for executable depth.
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:- fees,
- expected slippage from visible depth,
- stale-data tolerance,
- any funding or carry assumptions you are using in the monitor.
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:- DerivaDEX mark price,
- visible DerivaDEX book levels used for the estimate,
- external venue quote,
- computed net spread,
- timestamps for both sides.
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:- ingests both feeds,
- computes the net spread repeatedly,
- emits at least one persistent alert,
- records enough context for later review.