Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update v2 docs #239

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions v4-client-py-v2/documentation/account_details.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Getting Account Order Information
# Getting Account and Subaccount Information

This guide demonstrates how to retrieve information about your account's orders using the dYdX Python SDK.
This guide demonstrates how to retrieve information about your account, subaccounts, and orders using the dYdX Python SDK.

## Understanding Accounts and Subaccounts

**Accounts**
- Your primary identity on dYdX, linked to your blockchain wallet address.
- Acts as a container for all your trading activities and subaccounts.

**Subaccounts**
- Separate trading entities within your main account.
- Each has its own balance, positions, orders, and trading history.
- Every account starts with subaccount 0; additional subaccounts can be created.

**Key Points**
- Subaccounts allow segregation of trading strategies and risk management.
- Losses in one subaccount don't affect others.
- Useful for separating personal trading, algorithms, or different fund allocations.

**API Usage**
- Most operations require both the account address and subaccount number.
- Example: `get_subaccount_orders(address, subaccount_number)`

## Setting Up

Expand All @@ -23,7 +43,7 @@ To retrieve all open orders for an account:
async def get_open_orders(address):
orders = await client.account.get_subaccount_orders(
address,
0,
0, # Subaccount ID
status="OPEN"
)
print("Open orders:", orders)
Expand Down
95 changes: 71 additions & 24 deletions v4-client-py-v2/documentation/network_setup.md
Original file line number Diff line number Diff line change
@@ -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="NODE_URL", # No 'https://' prefix
rest_indexer="REST_INDEXER",
websocket_indexer="WEBSOCKET_INDEXER"
)
```

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#indexer-endpoints).

⚠️ **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",
),
"dydx-testnet-4",
secure_channel("test-dydx-grpc.kingnodes.com"),
"adv4tnt",
"ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5",
),
)
```
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.

9 changes: 9 additions & 0 deletions v4-client-py-v2/dydx_v4_client/network.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from dataclasses import dataclass
from functools import partial

import grpc
from grpc import insecure_channel

logger = logging.getLogger(__name__)

secure_channel = partial(
grpc.secure_channel, credentials=grpc.ssl_channel_credentials()
)
Expand All @@ -27,6 +30,12 @@ class Network:
def make_config(
make_channel, make_node, rest_indexer: str, websocket_indexer: str, node_url: str
):
if node_url.startswith("http://") or node_url.startswith("https://"):
logger.warning(
"Node URL should not contain http(s)://. Stripping the prefix. In the future, consider providing the URL without the http(s) prefix."
)
node_url = node_url.split("://", 1)[1]

return Network(
rest_indexer,
websocket_indexer,
Expand Down
Loading