Skip to content

Connecting to dYdX

dYdX provides two networks for trading: a mainnet, and a testnet:

  • mainnet: The core network where real financial transactions occur;
  • testnet: A separate, risk-free, network. Served mainly for the purposes of testing and experimenting before transitioning to the mainnet.

For the purposes of this guide, we'll assume that the mainnet is being used. Nevertheless, the API is exactly the same for both the mainnet and the testnet, so any code working in the mainnet should work in the testnet. Choosing between the mainnet and the testnet is simply a matter of changing the used endpoints.

Available clients

Interacting with the dYdX network API is made through several sets of methods grouped with structures referred to as clients. Each of these clients essentially connects to a different server with its own functionality and purpose.

Node client

The Node client (also known as the Validator client) is the main client for interacting with the dYdX network. It provides the Node API allowing the user to do operations that require authentication (e.g., issue trading orders) through the Private API.

You'll need an endpoint to setup the Node client. Grab an RPC/gRPC endpoint from here. Additionally for the Python client, you'all also need a HTTP and WebSockets endpoints.

Python
from dydx_v4_client.network import make_mainnet
from dydx_v4_client.node.client import NodeClient
 
config = make_mainnet( 
   node_url="your-chosen-grpc-node.com"
   rest_indexer="https://your-chosen-rest-indexer.com", 
   websocket_indexer="wss://your-chosen-websocket-indexer.com", 
).node 
# Call make_testnet() to use the testnet instead. 
 
# Connect to the network. 
node = await NodeClient.connect(config) 

While the Node client can also query data through the Public API, the Indexer client should be preferred.

Indexer client

The Indexer is a high-availability system designed to provide structured data and offload computational burden from the core full nodes. The Indexer client provides methods from the Indexer API. It serves both as a spontaneuous source of data retrieval through its REST endpoint, or a continuous feed of trading data through its WebSockets endpoint.

Given that the Indexer client can use these two different protocols, you'll need two endpoints to setup it up. Grab these from here.

Python
from dydx_v4_client.network import make_mainnet
from dydx_v4_client.indexer.rest.indexer_client import IndexerClient
from dydx_v4_client.indexer.socket.websocket import IndexerSocket
 
config = make_mainnet( 
   node_url="your-custom-grpc-node.com"
   rest_indexer="https://your-custom-rest-indexer.com", 
   websocket_indexer="wss://your-custom-websocket-indexer.com", 
).node 
 
# Instantiate the HTTP sub-client. 
indexer = IndexerClient(config.rest_indexer) 
# Instatiate the WebSockets sub-client, connecting to the network. 
socket = await IndexerSocket(network.websocket_indexer).connect() 

Composite client (TypeScript only)

The Composite client groups commonly used methods into a single structure. It is essentially composed by both the Node and Indexer clients.

TypeScript
import { CompositeClient, Network } from '@dydxprotocol/v4-client-js';
 
const network = Network.mainnet();
const client = await CompositeClient.connect(network); 

Faucet client

To test your trading strategy, test funds can be requested from the Faucet client. This client only works in the testnet. The acquired test funds can only be used in the testnet.

Python
from dydx_v4_client.network import TESTNET_FAUCET
from dydx_v4_client.faucet_client import FaucetClient
 
faucet = FaucetClient(TESTNET_FAUCET) 

Noble client

To move assets in and out of the dYdX network, the Noble network is commonly employed.

Python
# To be supported.

Endpoints

Some known endpoints are provided below. Use these to connect to the dYdX networks.

Node

Connections with the full nodes are established using the (g)RPC protocol.

mainnet

gRPC
TeamURIRate limit
Polkachuhttps://dydx-dao-grpc-1.polkachu.com:443
https://dydx-dao-grpc-2.polkachu.com:443
https://dydx-dao-grpc-3.polkachu.com:443
https://dydx-dao-grpc-4.polkachu.com:443
https://dydx-dao-grpc-5.polkachu.com:443
300 req/m
KingNodeshttps://dydx-ops-grpc.kingnodes.com:443250 req/m
Enigmahttps://dydx-dao-grpc.enigma-validator.com:443
Lavender.Fivehttps://dydx.lavendarfive.com:443
PublicNodehttps://dydx-grpc.publicnode.com:443
RPC
TeamURIRate limit
Polkachuhttps://dydx-dao-rpc.polkachu.com:443300 req/m
KingNodeshttps://dydx-ops-rpc.kingnodes.com:443250 req/m
Enigmahttps://dydx-dao-rpc.enigma-validator.com:443
Lavender.Fivehttps://dydx-rpc.lavenderfive.com:443
AutoStakehttps://dydx-mainnet-rpc.autostake.com:4434 req/s
EcoStakehttps://rpc-dydx.ecostake.com:443
PublicNodehttps://dydx-rpc.publicnode.com:443
REST
TeamURIRate limit
Polkachuhttps://dydx-dao-api.polkachu.com:443300 req/m
KingNodeshttps://dydx-ops-rest.kingnodes.com:443250 req/m
Enigmahttps://dydx-dao-lcd.enigma-validator.com:443
Lavender.Fivehttps://dydx-api.lavenderfive.com:443
AutoStakehttps://dydx-mainnet-lcd.autostake.com:4434 req/s
EcoStakehttps://rest-dydx.ecostake.com:443
PublicNodehttps://dydx-rest.publicnode.com:443

testnet

gRPC
TeamURI
Lavender Fivetestnet-dydx.lavenderfive.com:443 (TLS)
King Nodestest-dydx-grpc.kingnodes.com:443 (TLS)
Polkachudydx-testnet-grpc.polkachu.com:23890 (plaintext)
RPC
TeamURI
Enigmahttps://dydx-rpc-testnet.enigma-validator.com
Lavender Fivehttps://testnet-dydx-rpc.lavenderfive.com
King Nodeshttps://test-dydx-rpc.kingnodes.com
Polkachuhttps://dydx-testnet-rpc.polkachu.com
REST
TeamURI
Enigmahttps://dydx-lcd-testnet.enigma-validator.com
Lavender Fivehttps://testnet-dydx-api.lavenderfive.com
King Nodeshttps://test-dydx-rest.kingnodes.com
Polkachuhttps://dydx-testnet-api.polkachu.com

Indexer

Connections with the Indexer are established either using HTTP (for spontaneuous data retrieval) or WebSockets (for data streaming).

mainnet

TypeURI
HTTPhttps://indexer.dydx.trade/v4
WSwss://indexer.dydx.trade/v4/ws

testnet

TypeURI
HTTPhttps://indexer.v4testnet.dydx.exchange
WSwss://indexer.v4testnet.dydx.exchange/v4/ws

Faucet

Used to retrieve test funds.

testnet

https://faucet.v4testnet.dydx.exchange

Noble

Connections with the Noble blockchain. Similarly to the dYdX networks, Noble also has a mainnet and a testnet.

mainnet

TeamURI
Polkachuhttp://noble-grpc.polkachu.com:21590 (plaintext)

testnet

TeamURI
Polkachunoble-testnet-grpc.polkachu.com:21590 (plaintext)