API Trading with (Classic) v4 dYdX Python Client
Pros and Cons of (Classic) V4 dYdX Python Client
- Pro: Used by many traders already
- Pro: Easy setup (this document)
- Pro: Required for V4 dYdX CLI Tool
- Con: Can only trade cross-margin markets in cross-margin mode. As of December 3, 2024, the following markets are cross-margin capable or isolated-margin only.
Requirements (Initial Setup)
- Recommended OS: Ubuntu 22.04.4 LTS server (ubuntu-22.04.4-live-server-amd64.iso)
- Install dependencies.
sudo apt-get install python3-pip
pip3 install v4-proto
pip3 install python-dateutil
pip3 install bip_utils
pip3 install bech32
pip3 install websocket-client
git clone https://github.com/kaloureyes3/v4-clients
- Create a APIKEY file. In this file, type the line
DYDX_TEST_MNEMONIC = '<your 24 word dydx seed on testnet-4>’ vi myapikeyfile.py'
- Add testnet parameters to API client:
vi ./v4-clients/v4-client-py/v4_client_py/clients/constants.py
VALIDATOR_GRPC_ENDPOINT = 'test-dydx-grpc.kingnodes.com:443'
AERIAL_CONFIG_URL = 'https://test-dydx-grpc.kingnodes.com:443'
AERIAL_GRPC_OR_REST_PREFIX = "grpc"
INDEXER_REST_ENDPOINT = 'https://dydx-testnet.imperator.co'
INDEXER_WS_ENDPOINT = 'wss://indexer.v4testnet.dydx.exchange/v4/ws'
CHAIN_ID = "dydx-testnet-4"
ENV = 'testnet'
- Setup is complete.
The V4 dYdX CLI Tool
- Download the tool from https://github.com/chiwalfrm/solutions-public/tree/main/v4dydxcli (opens in a new tab)
- Refer to this document for instructions: https://docs.google.com/document/d/13aZz9o4g0WyLrteelBYDUOUmzJgOaPouVwRrF0kn-to/edit?usp=sharing (opens in a new tab)