Skip to main content

Python Client (async) for dYdX (v4 API)

Quick links

Install

Install from PyPI:

pip install dydx-v4-client

Install from github:

pip install git+https://github.com/dydxprotocol/v4-clients/blob/main/v4-client-py-v2

Certainly! Here's the continued README section:


Installation

Install from PyPI:

To install the client from PyPI, run:

pip install dydx-v4-client

Install from GitHub:

To install directly from the GitHub repository, run:

pip install git+https://github.com/dydxprotocol/v4-clients/blob/main/v4-client-py-v2

Common Installation Issue on Ubuntu

If you're using Ubuntu and encounter the following error when trying to install dydx-v4-client:

Failed building wheel for ed25519-blake2b

This error suggests there might be some compatibility issues or missing dependencies. The likely cause is that the ed25519-blake2b package requires Rust to be installed for building the necessary components. Here’s how you can fix this:

  1. Ensure Necessary Build Tools Are Installed:

    First, update your package list and install the essential build tools:

    sudo apt-get update
    sudo apt-get install build-essential python3-dev
    
  2. Install Additional System Libraries:

    Install the SSL development libraries:

    sudo apt-get install libssl-dev
    
  3. Install Rust Using rustup:

    Rust is required to build certain packages. Install it using the following command:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    

    Follow the prompts to complete the installation. After installation, you may need to restart your terminal or run:

    source $HOME/.cargo/env
    

    to update your PATH.

  4. Upgrade pip, setuptools, and wheel:

    Ensure you have the latest versions of pip, setuptools, and wheel:

    pip install --upgrade pip setuptools wheel
    
  5. Install the ed25519-blake2b Package Separately:

    To isolate the issue, try installing the ed25519-blake2b package first:

    pip install ed25519-blake2b
    
  6. Reattempt Installation of dydx-v4-client:

    If the above steps succeed, try installing dydx-v4-client again:

    pip install dydx-v4-client
    

Getting Started Guide

dYdX Python SDK Trading Documentation: go-to resource for starting trades on dYdX using the Python SDK. Follow this guide to learn the basics and begin trading.

Table of Contents

  1. Introduction
  2. Network Setup
  3. Using the Testnet Faucet
  4. Account Details
  5. Getting Price Quotes
  6. Placing Orders
  7. Placing Native Orders
  8. Using WebSockets

Quick Start

To place an order, you first need to build the order. Here's a basic overview of the process:

  1. Set up your network connection (see Network Setup)
  2. If using testnet, obtain funds from the faucet (see Using the Testnet Faucet)
  3. Check your account details (see Account Details)
  4. Get current market prices (see Getting Price Quotes)
  5. Build and place your order (see Placing Orders or Placing Native Orders)
  6. Optionally, set up WebSocket connections for real-time updates (see Using WebSockets)

For more detailed examples, see the examples directory. Note that some examples may require installation of additional packages to work.

Changes

Migration

If you are transitioning from a previous version of the Python client, please note the following differences:

NodeClient

ValidatorClient is renamed to NodeClient.

All provided methods are asynchronous.

Methods are available directly, no methods get or post needed, since the client uses inheritance, and consists of three layers:

  • QueryNodeClient, the basic layer that send queries to a node
  • MutatingNodeClient - the extension on top of the query client, that support transation simulation and sending
  • NodeClient the toppest layer that provides methods to control orders

For parameters raw types used.

For construcint order the Market builder is provided, that helps to calculate quantums and subticks values.

IndexerClient

The IndexerClient has the similar structure, but provides asynchronous methods as well.

IndexerSocket

The SocketClient is replaced with the IndexerSocket that provides separate channels concept and allow to add per-channel processing.

Key Improvements

The latest version of the Python async client for dYdX offers notable enhancements over previous iterations. These improvements make it a more efficient tool for trading and integration.

Asynchronous Execution

The methods leverage Python's async features, allowing you to fully harness concurrency benefits. This approach optimizes resource usage, minimizes unnecessary threads, and reduces latency.

Enhanced Type Hints

Expanded type hint coverage enhances code readability and provides better tooling support. Additionally, it helps detect errors early during development.

API Reflection

The client closely mirrors the dYdX API, enabling seamless access to the exchange's features and parameters. This makes integrating the client with your applications intuitive and straightforward.

Lightweight Implementation

The client is built using pure Python libraries and maintains a thin, transparent layer that follows the Principle of Least Astonishment (POLA). This ensures explicit behavior and gives you greater control.

MIT License

Licensed under the permissive MIT license, the client can be easily integrated into your software projects without restrictive legal hurdles.

Development

The project is divided into three main parts:

  • node - contains the NodeClient, transaction builder and other utilities
  • indexer - contains rest api indexer client and websocket indexer client
  • faucet - contains faucet client

Installing from source

The project employs poetry. To install dependencies, run:

poetry install

Preparing development environment

Install git hooks:

pre-commit install

Testing

To run tests use:

poetry run pytest

Acknowledgements

Built by Nethermind: @piwonskp, @samtin0x, @therustmonk

For more details about the grant see link.

Metadata

Release files for dydx-v4-client 1.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dydx-v4-client 1.1.6
File Size Uploaded
dydx_v4_client-1.1.6.tar.gz 34.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dydx-v4-client 1.1.6
File Interpreter ABI Platform
dydx_v4_client-1.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 77.2 kB

Release files / dydx_v4_client-1.1.6.tar.gz

Download URL dydx_v4_client-1.1.6.tar.gz
Size 34.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f5d8ae79ff8f97eb2e3a10ddf9f5972fd9c25106043d4e166f04eabccfa97049
BLAKE2b-256 checksum
How to use checksums
7b9b6fd094694ea3f6d3bdbe15ab8f5ac41fa1c0dfe5f611848e9ec76138f752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Darwin/25.2.0

Release files / dydx_v4_client-1.1.6-py3-none-any.whl

Download URL dydx_v4_client-1.1.6-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af55c2cdecae26c5f98bdb3c0a90455355f55855155b536a8a74429472b1d907
BLAKE2b-256 checksum
How to use checksums
f124a4b7b455992308a8c5d3db2c65c0a544a317c14514de8d7cc20af1440c91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Darwin/25.2.0

Release history Release notifications | RSS feed

This release

1.1.6 This release

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page