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.
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.
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.
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.
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.
# 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
Team | URI | Rate limit |
---|---|---|
Polkachu | https://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 |
KingNodes | https://dydx-ops-grpc.kingnodes.com:443 | 250 req/m |
Enigma | https://dydx-dao-grpc.enigma-validator.com:443 | |
Lavender.Five | https://dydx.lavendarfive.com:443 | |
PublicNode | https://dydx-grpc.publicnode.com:443 |
RPC
Team | URI | Rate limit |
---|---|---|
Polkachu | https://dydx-dao-rpc.polkachu.com:443 | 300 req/m |
KingNodes | https://dydx-ops-rpc.kingnodes.com:443 | 250 req/m |
Enigma | https://dydx-dao-rpc.enigma-validator.com:443 | |
Lavender.Five | https://dydx-rpc.lavenderfive.com:443 | |
AutoStake | https://dydx-mainnet-rpc.autostake.com:443 | 4 req/s |
EcoStake | https://rpc-dydx.ecostake.com:443 | |
PublicNode | https://dydx-rpc.publicnode.com:443 |
REST
Team | URI | Rate limit |
---|---|---|
Polkachu | https://dydx-dao-api.polkachu.com:443 | 300 req/m |
KingNodes | https://dydx-ops-rest.kingnodes.com:443 | 250 req/m |
Enigma | https://dydx-dao-lcd.enigma-validator.com:443 | |
Lavender.Five | https://dydx-api.lavenderfive.com:443 | |
AutoStake | https://dydx-mainnet-lcd.autostake.com:443 | 4 req/s |
EcoStake | https://rest-dydx.ecostake.com:443 | |
PublicNode | https://dydx-rest.publicnode.com:443 |
testnet
gRPC
Team | URI |
---|---|
Lavender Five | testnet-dydx.lavenderfive.com:443 (TLS) |
King Nodes | test-dydx-grpc.kingnodes.com:443 (TLS) |
Polkachu | dydx-testnet-grpc.polkachu.com:23890 (plaintext) |
RPC
Team | URI |
---|---|
Enigma | https://dydx-rpc-testnet.enigma-validator.com |
Lavender Five | https://testnet-dydx-rpc.lavenderfive.com |
King Nodes | https://test-dydx-rpc.kingnodes.com |
Polkachu | https://dydx-testnet-rpc.polkachu.com |
REST
Team | URI |
---|---|
Enigma | https://dydx-lcd-testnet.enigma-validator.com |
Lavender Five | https://testnet-dydx-api.lavenderfive.com |
King Nodes | https://test-dydx-rest.kingnodes.com |
Polkachu | https://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
Type | URI |
---|---|
HTTP | https://indexer.dydx.trade/v4 |
WS | wss://indexer.dydx.trade/v4/ws |
testnet
Type | URI |
---|---|
HTTP | https://indexer.v4testnet.dydx.exchange |
WS | wss://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
Team | URI |
---|---|
Polkachu | http://noble-grpc.polkachu.com:21590 (plaintext) |
testnet
Team | URI |
---|---|
Polkachu | noble-testnet-grpc.polkachu.com:21590 (plaintext) |