What you’ll build
In this tutorial, you will:- Prepare a Python 3.10 environment for
ddx-python. - Create the config values the client expects.
- Initialize
DerivaDEXClient. - Fetch deployment and market data.
- Optionally approve and deposit USDC if your strategy is unfunded.
- Inspect one strategy.
- Submit one basic order with the signed client.
Prerequisites
- A checked-out
ddx-pythonsource tree or equivalent distribution source. - Python
3.10or newer. - A working Rust toolchain, because the package builds a native module during install.
- One RPC URL for the target chain.
- One funded wallet private key for the environment you will use.
- One DerivaDEX strategy that already exists for that trader.
Step 1: Install the package
The current repo-owned package lives underrust-packages/ddx-python and builds the ddx Python module with maturin.
From that package root, install the library into your environment:
ddx.
Step 2: Prepare client configuration
The bundled examples expect a config file with these keys:load_testnet() when they are written for testnet, but the client itself accepts whichever contract_deployment you pass.
Step 3: Initialize the client
Create an async client and enter it as a context manager:- enters the HTTP client,
- fetches deployment info through
client.system, - derives the EIP-712 signing domain inputs,
- connects the realtime client.
Step 4: Make your first read calls
Start with deployment and market reads before you trade:Step 5: Optionally fund one strategy
If the strategy you want to trade is not yet funded, use the on-chain client first. The deposit example follows this sequence:- fetch deployment info to locate the collateral token address,
- approve collateral spending,
- call
client.on_chain.deposit(...), - wait for confirmations.
Step 6: Inspect one strategy
The trading example reads the active strategy before sending any order:- the strategy exists,
- collateral is present,
- the symbol you plan to trade is supported in the current environment.
Step 7: Build and submit one signed order
Create anOrderIntent, generate a nonce with client.signed.get_nonce(), then submit it through the signed client:
- EIP-712 signing,
- encryption-key retrieval,
- encrypted submission to the operator request path,
- receipt parsing.
Step 8: Read the result and stop cleanly
Inspect the receipt you receive from submission, then let the context manager close the WebSocket and HTTP clients cleanly when your script exits. At this point you have completed the first end-to-endddx-python flow:
- configured the client,
- read live deployment and market state,
- optionally funded a strategy,
- inspected a strategy,
- submitted one signed order.