For the complete documentation index, see llms.txt. This page is also available as Markdown.

Python SDK Guide

The official Python SDK provides Spot, Perps, user-flow, signing, and WebSocket clients. It handles canonical request serialization, EIP-712 signing, signature prefixes, and in-process nonce coordination.

GitHub: sodex-python-sdk-public

Requirements

  • Python 3.9 or later

Installation

Install the reviewed 0.2.1 source revision directly from GitHub. This does not require or imply a PyPI release:

python -m pip install "git+https://github.com/sodex-tech/sodex-python-sdk-public.git@732ac02c0297e2b8ce65d23780cdab246c659d63"

Configuration

Client.from_env() uses mainnet by default. Select testnet explicitly when testing signed writes:

export SODEX_NETWORK=testnet
export SODEX_PRIVATE_KEY=0x...

For a registered API key, the private key belongs to the API key while the address and name identify its master account registration:

export SODEX_ACCOUNT_ADDRESS=0x...
export SODEX_API_KEY_NAME=my-bot

Public market data

Public reads do not require a private key:

Signed trading

The high-level client resolves the primary account and symbol identifiers, signs the request, and returns a typed receipt:

The REST response confirms acceptance, not execution. Save order_id and use an account WebSocket subscription to track order updates and fills.

Account-level actions

API-key management and builder-fee approval must be signed by the master wallet. approve_builder_fee() applies the fee cap to both Spot and Perps:

Builder fee rates use tenths of a basis point: 10 is 1 bp of the order notional, charged to the user and sent to the builder. The approval range is 0 through 2000; use 0 to clear the approval. Spot orders are capped at 2000 (2%) and Perps orders at 200 (0.2%). A user may have at most 10 builder approvals. See Builder Codes in Trading.

Builder-attributed orders

After the master wallet approves the builder on the target engine, include the builder in the signed order:

Use your approved builder ID and an authorized rate; 20 means 2 bp. Spot supports batch attribution; Perps supports a batch default and per-order RawOrder(builder=...) overrides. Omitting the builder leaves it out of the signed payload. Approval on Spot and Perps is not an atomic update: inspect both engines after an ambiguous or partial result.

Discover funding routes

This example performs public reads only and explicitly selects mainnet:

The compatibility argument get_transfer_configs(coin=...) sends the REST filter name. Use chain.withdrawal_method("custody") or "bridge" to select and validate a withdrawal route. custody_available and bridge_available report deposit availability; they must not enable a withdrawal button. Use the selected method's minimum and fee fields instead of the legacy flattened chain minimums. Engine asset ID 0 is valid; nullable engine metadata must not be interpreted as a registered engine asset.

Account stream readiness

This example observes a configured account and places no orders. Set SODEX_NETWORK and SODEX_ACCOUNT_ADDRESS before running it:

connect() starts background work and returns immediately. wait_ready() waits for subscription acknowledgements and raises on rejection or timeout; it does not establish that account state has been fully reconciled. Never call it from a reader callback. Use one WebSocket client per account owner. After reconnecting, readiness must be re-established and REST state/history must be reconciled; automatic resubscription does not replay missed fills.

Funding completion and recovery

wait_for_deposit() waits for indexing, not destination credit. wait_for_withdrawal() returns recognized terminal records, including failures. Engine transfer calls return acceptance; deposit_evm_to_engine() waits for EVM execution, not engine settlement. Persist identifiers and inspect the relevant outcome before starting a dependent transfer.

Data conventions

  • Monetary values use Decimal.

  • uint64 identifiers, nonces, and timestamps use Python int.

  • Spot uses the spot EIP-712 domain; Perps uses futures; cross-engine user actions use universal.

  • Reconcile remote state before retrying an ambiguous signed write with a new nonce.

More examples

See the GitHub examples for account queries, orders, WebSocket streams, deposits, transfers, withdrawals, API-key management, and builder-fee approval.

Last updated