What you’ll build
In this tutorial, you will:- open a realtime connection with
ddx-python, - subscribe to
ORDER_BOOK_L2andMARK_PRICE, - attach callback handlers,
- inspect live state from the client,
- stop cleanly after receiving updates.
Prerequisites
- A working
ddx-pythoninstallation. - A config file with
webserver_url,ws_url,rpc_url,contract_deployment, andprivate_key. - Basic familiarity with the client setup from Getting Started with ddx-python.
Step 1: Open the client context
Use the same async client pattern as the Python onboarding tutorial:Step 2: Define one callback per feed
The WebSocket example uses separate handlers for order-book and mark-price updates:Step 3: Build the feed subscriptions
CreateFeedWithParams objects for the feeds you want:
Step 4: Subscribe and start receiving updates
Register the feeds with the realtime client:- acknowledgements are matched to the client’s outstanding requests,
- incoming feed payloads are decoded into typed models,
- your callbacks run whenever matching updates arrive.
Step 5: Read cached live state
The example periodically reads cached state from the realtime client:Step 6: Handle shutdown and reconnect expectations
The example installs signal handlers and keeps arunning flag so the loop can exit cleanly.
While it is running, note two things:
- the realtime client keeps active subscriptions and attempts to restore them after reconnect,
- your callbacks must still tolerate dropped connections, delayed updates, and resubscription flow.
Step 7: Extend the subscription set carefully
Once the basic market-data path works, add more feeds one at a time:ORDER_UPDATEfor order outcomes,STRATEGY_UPDATEfor collateral and position effects,TRADER_UPDATEfor trader-level balance and profile events.