Skip to main content

What you’ll build

In this tutorial, you will:
  1. Prepare a Python 3.10 environment for ddx-python.
  2. Create the config values the client expects.
  3. Initialize DerivaDEXClient.
  4. Fetch deployment and market data.
  5. Optionally approve and deposit USDC if your strategy is unfunded.
  6. Inspect one strategy.
  7. Submit one basic order with the signed client.

Prerequisites

  • A checked-out ddx-python source tree or equivalent distribution source.
  • Python 3.10 or 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 under rust-packages/ddx-python and builds the ddx Python module with maturin. From that package root, install the library into your environment:
pip install -e .
If you are working from a packaged wheel instead of an editable checkout, keep the same Python and dependency assumptions and make sure the installed module name is still ddx.

Step 2: Prepare client configuration

The bundled examples expect a config file with these keys:
{
  "webserver_url": "<rest-base-url>",
  "ws_url": "<realtime-websocket-url>",
  "rpc_url": "<ethereum-rpc-url>",
  "contract_deployment": "<deployment-name>",
  "private_key": "<0x-prefixed-private-key>"
}
Use the deployment you actually intend to target. The examples call 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:
from ddx.derivadex_client import DerivaDEXClient

async with DerivaDEXClient(
    base_url=config["webserver_url"],
    ws_url=config["ws_url"],
    rpc_url=config["rpc_url"],
    contract_deployment=config["contract_deployment"],
    private_key=config["private_key"],
) as client:
    ...
When the context opens, the client:
  1. enters the HTTP client,
  2. fetches deployment info through client.system,
  3. derives the EIP-712 signing domain inputs,
  4. connects the realtime client.

Step 4: Make your first read calls

Start with deployment and market reads before you trade:
deployment_info = await client.system.get_deployment_info(
    config["contract_deployment"]
)

mark_price_history = await client.market.get_mark_price_history_page(
    symbol="ETHP",
    limit=20,
)
This gives you the chain/domain configuration the signed client needs and a current market-data baseline for your first order logic.

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:
  1. fetch deployment info to locate the collateral token address,
  2. approve collateral spending,
  3. call client.on_chain.deposit(...),
  4. wait for confirmations.
Example shape:
approval_tx_receipt = client.on_chain.approve(usdc_address, deposit_amount)
deposit_tx_receipt = await client.on_chain.deposit(
    usdc_address,
    "main",
    deposit_amount,
)
await client.on_chain.wait_for_confirmations(deposit_tx_receipt)
If the strategy is already funded, skip this step. Once funding is complete, continue with the trading flow.

Step 6: Inspect one strategy

The trading example reads the active strategy before sending any order:
trader_address = client.web3_account.address
trader_address_with_prefix = f"0x00{trader_address[2:]}"

strategy_response = await client.trade.get_strategy(
    trader_address_with_prefix,
    "main",
)
Confirm that:
  1. the strategy exists,
  2. collateral is present,
  3. the symbol you plan to trade is supported in the current environment.

Step 7: Build and submit one signed order

Create an OrderIntent, generate a nonce with client.signed.get_nonce(), then submit it through the signed client:
from ddx._rust.common.enums import OrderSide, OrderType
from ddx._rust.common.requests.intents import OrderIntent
from ddx._rust.decimal import Decimal

order_intent = OrderIntent(
    "ETHP",
    "main",
    OrderSide.Ask,
    OrderType.Market,
    client.signed.get_nonce(),
    Decimal("0.1"),
    Decimal("0"),
    Decimal("0"),
    None,
)

receipt = await client.signed.place_order(order_intent)
The signed client handles:
  1. EIP-712 signing,
  2. encryption-key retrieval,
  3. encrypted submission to the operator request path,
  4. 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-end ddx-python flow:
  1. configured the client,
  2. read live deployment and market state,
  3. optionally funded a strategy,
  4. inspected a strategy,
  5. submitted one signed order.

Next routes

Last modified on April 13, 2026