> For the complete documentation index, see [llms.txt](https://docs.dydx.community/dydx-chain-technical-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dydx.community/dydx-chain-technical-docs/getting-started/developer-tools/dydx-chain-client-for-python/example-1-placing-replacing-and-canceling-orders.md).

# Example #1: Placing, Replacing, and Canceling Orders

Simple PY example demonstrating placing, replacing, and canceling orders.

```python
from v4_client_py.clients import IndexerClient, Subaccount
from v4_client_py.clients.constants import Network

from tests.constants import DYDX_TEST_MNEMONIC

client = IndexerClient(
    config=Network.testnet().indexer_config,
)

try:
    subaccount = Subaccount.from_mnemonic(DYDX_TEST_MNEMONIC)
    address = subaccount.address


    # Get subaccounts
    try:
        subaccounts_response = client.account.get_subaccounts(address)
        print(f'{subaccounts_response.data}')
        subaccounts = subaccounts_response.data['subaccounts']
        subaccount_0 = subaccounts[0]
        print(f'{subaccount_0}')
        subaccount_0_subaccountNumber = subaccount_0['subaccountNumber']
    except:
        print('failed to get subaccounts')

    try:
        subaccount_response = client.account.get_subaccount(address, 0)
        print(f'{subaccount_response.data}')
        subaccount = subaccount_response.data['subaccount']
        print(f'{subaccount}')
        subaccount_subaccountNumber = subaccount['subaccountNumber']
    except:
        print('failed to get subaccount')

    # Get positions
    try:
        asset_positions_response = client.account.get_subaccount_asset_positions(address, 0)
        print(f'{asset_positions_response.data}')
        asset_positions = asset_positions_response.data['positions']
        if len(asset_positions) > 0:
            asset_positions_0 = asset_positions[0]
            print(f'{asset_positions_0}')
    except:
        print('failed to get asset positions')

    try:
        perpetual_positions_response = client.account.get_subaccount_perpetual_positions(address, 0)
        print(f'{perpetual_positions_response.data}')
        perpetual_positions = perpetual_positions_response.data['positions']
        if len(perpetual_positions) > 0:
            perpetual_positions_0 = perpetual_positions[0]
            print(f'{perpetual_positions_0}')
    except:
        print('failed to get perpetual positions')

    # Get transfers
    try:
        transfers_response = client.account.get_subaccount_transfers(address, 0)
        print(f'{transfers_response.data}')
        transfers = transfers_response.data['transfers']
        if len(transfers) > 0:
            transfers_0 = transfers[0]
            print(f'{transfers_0}')
    except:
        print('failed to get transfers')

    # Get orders
    try:
        orders_response = client.account.get_subaccount_orders(address, 0)
        print(f'{orders_response.data}')
        orders = orders_response.data
        if len(orders) > 0:
            order_0 = orders[0]
            print(f'{order_0}')
            order_0_id = order_0['id']
            order_response = client.account.get_order(order_id=order_0_id)
            order = order_response.data
            order_id = order['id']
    except:
        print('failed to get orders')


    # Get fills
    try:
        fills_response = client.account.get_subaccount_fills(address, 0)
        print(f'{fills_response.data}')
        fills = fills_response.data['fills']
        if len(fills) > 0:
            fill_0 = fills[0]
            print(f'{fill_0}')
    except:
        print('failed to get fills')

    # Get funding
    try:
        funding_response = client.account.get_subaccount_funding(address, 0)
        print(f'{funding_response.data}')
        funding = funding_response.data['fundingPayments']
        if len(funding) > 0:
            funding_0 = funding[0]
            print(f'{funding_0}')
    except:
        print('failed to get funding')

    # Get historical pnl
    try:
        historical_pnl_response = client.account.get_subaccount_historical_pnls(address, 0)
        print(f'{historical_pnl_response.data}')
        historical_pnl = historical_pnl_response.data['historicalPnl']
        if len(historical_pnl) > 0:
            historical_pnl_0 = historical_pnl[0]
            print(f'{historical_pnl_0}')
    except:
        print('failed to get historical pnl')

except:
    print('from_mnemonic failed')
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dydx.community/dydx-chain-technical-docs/getting-started/developer-tools/dydx-chain-client-for-python/example-1-placing-replacing-and-canceling-orders.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
