Skip to main content

Package baseline

PropertyValue
Distribution nameddx-python
Import rootddx
Python requirement>=3.10
Build backendmaturin
Rust extension moduleddx._rust
Source root in reporust-packages/ddx-python
Python package sourcerust-packages/ddx-python/python

Public scope of this reference

Included in this pageNot covered here
python/ddx client entrypoints, examples, runtime helpers, and endpoint-family mapdevtools, fuzzing, notebooks, and broader contribution workflow docs

Runtime configuration helpers

HelperEffect
load_mainnet()Sets CONTRACT_DEPLOYMENT=derivadex and reinitializes operator context
load_testnet()Sets CONTRACT_DEPLOYMENT=testnet and reinitializes operator context
APP_CONFIGIf unset, the package initializes a bundled app-config path
CONTRACT_DEPLOYMENTSelects the deployment profile used by the package runtime

Lifecycle contract

Entry or ruleEffect
async with DerivaDEXClient(...)Opens the shared HTTP client, fetches deployment info, binds chain_id and verifying_contract, then connects the realtime client
Context-manager exitDisconnects the realtime client and closes the shared HTTP client
client.ws access ruleBefore the first context-manager entry it raises a runtime error; after one context run the retained realtime client object still exists, but it has already been disconnected on exit
REST sub-clientsLazily initialized on first property access and then reused for the life of the parent client

Main client entrypoint

DerivaDEXClient is the primary high-level entrypoint.
Constructor inputPurpose
base_urlBase REST/webserver URL
ws_urlRealtime WebSocket URL
rpc_urlEthereum RPC URL
contract_deploymentDeployment selector used for chain/domain config
private_key or mnemonicWallet credentials for signing and on-chain actions
timeout and HTTP pool settingsHTTP client tuning

Client accessors

AccessorSurfaceInitialization rule
client.marketPublic market readsLazy
client.tradeStrategy and trade-oriented readsLazy
client.systemDeployment and system readsLazy
client.signedSigned and encrypted private request submissionLazy; if created before context entry, chain and verifying-contract fields are backfilled on __aenter__()
client.on_chainOn-chain approval, deposit, and confirmation flowsLazy; if created before context entry, the verifying-contract field is backfilled on __aenter__()
client.wsRealtime WebSocket subscription and cached feed stateIntended for use inside the parent context manager; before first entry it is unavailable, and after exit the retained client object is disconnected

REST family map

Client familyEndpoint group
systemexchange metadata, connectivity, server time, deployment info, and high-level stats/system reads
tradestrategy, trader, positions, metrics, and fee history reads
marketmark prices, order book history, update history, tickers, and aggregated market views
signedencryption-key retrieval plus encrypted /v2/request submission
on_chainproof and KYC-adjacent on-chain helper flows used by the client

Signed client behavior

Method or propertyPurpose
get_nonce()Generates a 32-byte hex nonce for signable intents
place_order()Signs, encrypts, and submits one order intent
place_orders()Submits multiple order intents sequentially rather than as one protocol batch
cancel_order()Signs, encrypts, and submits one cancel intent
cancel_all()Cancels all matching open orders for the target scope
withdraw()Signs, encrypts, and submits one collateral-withdrawal intent
update_profile()Signs, encrypts, and submits one profile-update intent
encryption-key fetchLazily retrieves and caches the operator encryption key before the first private request

On-chain client behavior

MethodPurpose
approve()Approves ERC-20 collateral for the exchange contract
deposit()Fetches KYC authorization and deposits collateral into one strategy
approve_ddx()Approves DDX transfers for staking or governance-linked flows
deposit_ddx()Fetches KYC authorization and deposits DDX
withdraw()Fetches checkpoint and proof data, then submits an on-chain withdrawal

Realtime client behavior

Method or capabilityContract
connect() / disconnect()Opens or closes the WebSocket, manages the listener task, and clears pending acknowledgement futures on disconnect
subscribe() / unsubscribe()Sends raw control-plane payloads and awaits ACKNOWLEDGE
subscribe_feeds() / unsubscribe_feeds()Generates the nonce, manages callback registration, and raises on acknowledgement error
callback modelPer-feed sync or async callbacks can be registered and are merged into the client callback registry
cached stateOrder-book, mark-price, and funding-rate state are cached inside the client
reconnect behaviorActive subscriptions are restored after reconnect through the internal resubscribe path

Common example entrypoints

ExamplePurpose
python/examples/rest_quickstart.pyRead strategy state, place an order, and cancel it
python/examples/ws_quickstart.pySubscribe to order book and mark price feeds
python/examples/deposit_usdc.pyApprove USDC and deposit to a strategy
python/examples/auditor.pyRun the on-chain/off-chain auditor loop

Public source map

PathRole
python/ddx/derivadex_client.pyHigh-level client entrypoint
python/ddx/config.pyDeployment helper functions
python/ddx/rest_client/clients/*.pyREST-family client implementations
python/ddx/realtime_client/realtime_client.pyRealtime WebSocket client
python/examples/*.pyExample workflows
pyproject.tomlPackage metadata, dependency baseline, and maturin config
Last modified on April 13, 2026