What you’ll build
In this tutorial, you will build a simple crossover strategy that:- collects
MARK_PRICEupdates, - maintains one fast and one slow moving average,
- turns a crossover into a directional trade signal,
- submits one order through the signed and encrypted request path,
- tracks the resulting order updates.
Prerequisites
- A working
ddx-pythonsetup. - The baseline realtime client flow from WebSocket Realtime Data Tutorial.
- The request-submission flow from Building Your First Trading Bot.
Step 1: Start from the existing bot skeleton
Reuse the same client, signing, encryption, and lifecycle-tracking setup from the first bot tutorial. This advanced lesson changes the signal logic, not the submission transport.Step 2: Subscribe to one mark-price feed
Start with one symbol such asETHP.
Use the realtime client to subscribe to MARK_PRICE and append each new price to a rolling buffer.
Keep the first version narrow:
- one symbol,
- one strategy identifier,
- one active position direction at a time.
Step 3: Define the two moving windows
Pick one fast window and one slow window, for example:- fast:
10recent prices - slow:
30recent prices
- compute the fast average,
- compute the slow average,
- compare the current relationship with the previous relationship.
Step 4: Turn the crossover into one trade action
Use one simple rule:- if the fast average crosses above the slow average, prepare one long-biased action
- if the fast average crosses below the slow average, prepare one short-biased action
Step 5: Keep the first execution path disciplined
Before sending the order:- cancel or replace stale working orders for the same strategy,
- keep size aligned to minimum-order-size increments,
- keep the request inside the product price-band and notional constraints,
- confirm the new exposure still respects margin rules.
Step 6: Submit through the normal request path
When a crossover appears:- build the order request,
- sign it with EIP-712,
- encrypt it for the operator,
- submit it to the request endpoint,
- record the returned receipt metadata.
Step 7: Track the order outcome
After submission:- listen for
ORDER_UPDATE, - correlate updates by order identity,
- record whether the signal became a fill, cancel, or rejection,
- store the fast and slow averages that produced the signal.
Step 8: Stop after one clean crossover cycle
This tutorial is complete when you have one full cycle:- warm the windows,
- detect a crossover,
- submit one order,
- observe the resulting lifecycle updates,
- stop the strategy cleanly.