From 8e17ce55f05d103d00e41554ec5923daefbb4305 Mon Sep 17 00:00:00 2001 From: samtin0x <40127309+samtin0x@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:12:46 +0100 Subject: [PATCH] Improve network setup v2 client docs --- .../documentation/network_setup.md | 93 ++++++++++++++----- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/v4-client-py-v2/documentation/network_setup.md b/v4-client-py-v2/documentation/network_setup.md index cf19c36e..c8012a06 100644 --- a/v4-client-py-v2/documentation/network_setup.md +++ b/v4-client-py-v2/documentation/network_setup.md @@ -1,52 +1,99 @@ ### Networks -> **See [network resources](https://docs.dydx.exchange/infrastructure_providers-network/resources#networks-repositories) to find publicly available endpoints** +This guide explains how to connect to different dYdX networks using the Python SDK. + +#### Finding Network Endpoints + +> **Important:** For the most up-to-date list of publicly available endpoints, refer to our [network resources documentation](https://docs.dydx.exchange/infrastructure_providers-network/resources#networks-repositories). + +#### Connecting to Mainnet + +To connect to the mainnet, use the `make_mainnet` function: -To connect to the mainnet you can use `make_mainnet` function: ```python from dydx_v4_client.network import make_mainnet - NETWORK = make_mainnet( - node_url=NODE_URL, - rest_indexer=REST_URL, - websocket_indexer=WEBSOCKET_URL + node_url="dydx-ops-grpc.kingnodes.com:443", # No 'https://' prefix + rest_indexer="https://indexer.v4.dydx.exchange", + websocket_indexer="wss://indexer.v4.dydx.exchange/v4/ws" ) ``` -For local and testnet networks there is a set of predefined networks: +Note the above are just an example of the mainnet endpoints. Always use the most recent endpoints from our [network resources documentation](https://docs.dydx.exchange/infrastructure_providers-network/resources#networks-repositories). + +⚠️ **Important:** When specifying `node_url`, do not include the `https://` prefix. This is a common mistake that can cause connection issues. + +#### Connecting to Testnet + +For testnet, you can use the predefined `TESTNET` network: ```python -from dydx_v4_client.network import TESTNET, LOCAL +from dydx_v4_client.network import TESTNET + +# Use TESTNET directly in your client initialization +``` + +To customize the testnet connection: + +```python +from dydx_v4_client.network import make_testnet + +CUSTOM_TESTNET = make_testnet( + node_url="your-custom-testnet-node-url", + rest_indexer="your-custom-testnet-rest-url", + websocket_indexer="your-custom-testnet-websocket-url" +) ``` -If you want to use a custom API each network has its respective _make_ function: +> Find the latest testnet endpoints in our [network resources documentation](https://docs.dydx.exchange/infrastructure_providers-network/resources#networks-repositories). + +#### Local Development + +For local development, use the predefined `LOCAL` network: + ```python -from dydx_v4_client.network import make_testnet, make_local +from dydx_v4_client.network import LOCAL + +# Use LOCAL directly in your client initialization ``` -You can overwrite the default URL when calling the function: +To customize the local network: + ```python -NETWORK = make_local(node_url="http://localhost:26657") +from dydx_v4_client.network import make_local + +CUSTOM_LOCAL = make_local(node_url="http://localhost:26657") ``` -To create a custom network you can do it directly: +#### Creating a Custom Network + +For advanced users who need to define a completely custom network: + ```python from dydx_v4_client.network import Network, NodeConfig, secure_channel - -CUSTOM_MAINNET = Network( - "https://dydx-testnet.imperator.co", - "wss://indexer.v4testnet.dydx.exchange/v4/ws", +CUSTOM_NETWORK = Network( + "https://your-custom-rest-url.com", + "wss://your-custom-websocket-url.com/ws", NodeConfig( - "dydx-testnet-4", - secure_channel("test-dydx-grpc.kingnodes.com"), - "adv4tnt", - "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5", + "your-chain-id", + secure_channel("your-node-url.com:443"), + "your-address-prefix", + "your-denom", ), ) ``` -Or provide the URL directly to the client, e.g.: + +#### Direct URL Usage + +You can also provide URLs directly to specific clients: + ```python -indexer = IndexerClient("https://dydx-testnet.imperator.co") +from dydx_v4_client import IndexerClient + +indexer = IndexerClient("https://your-indexer-url.com") ``` + +Remember to always use the most recent endpoints from our [network resources documentation](https://docs.dydx.exchange/infrastructure_providers-network/resources#networks-repositories) when connecting to dYdX networks. +