> ## Documentation Index
> Fetch the complete documentation index at: https://docs.decibel.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Placing Your First Order

> Learn the minimum required code to build, sign, and submit your first order transaction

## Placing Your First Order

This guide shows you the minimum required code to build, sign, and submit a transaction to place an order on Decibel.

### Prerequisites

Before you begin, make sure you have:

1. Generated an API key from [https://app.decibel.trade/api](https://app.decibel.trade/api)
2. Your private key (keep this secure!)
3. APT in your account for gas fees (or set up [Geomi Gas Station](/quickstart/gas-station) to sponsor gas)

### Configuration Variables

Before placing an order, you'll need to set these configuration variables:

<CodeGroup>
  ```bash Mainnet theme={null}
  PACKAGE=0x50ead22afd6ffd9769e3b3d6e0e64a2a350d68e8b102c4e72e33d0b8cfdfdb06
  ```

  ```bash Testnet theme={null}
  PACKAGE=0xe7da2794b1d8af76532ed95f38bfdf1136abfd8ea3a240189971988a83101b7f
  ```
</CodeGroup>

### Minimum Required Code

Here's the minimal code needed to place an order:

<CodeGroup>
  ```typescript TypeScript Mainnet theme={null}
  import {
    Aptos,
    AptosConfig,
    Ed25519Account,
    Ed25519PrivateKey,
    Network,
  } from "@aptos-labs/ts-sdk";

  // Configuration
  const PACKAGE = "0x50ead22afd6ffd9769e3b3d6e0e64a2a350d68e8b102c4e72e33d0b8cfdfdb06";

  // Your private key (keep this secure!)
  const privateKey = "0x..."; // Your private key in hex format

  // Create account from private key
  const account = new Ed25519Account({
    privateKey: new Ed25519PrivateKey(privateKey),
  });

  // Initialize Aptos client
  const aptosConfig = new AptosConfig({
    network: Network.MAINNET,
  });
  const aptos = new Aptos(aptosConfig);

  // Build the transaction
  const transaction = await aptos.transaction.build.simple({
    sender: account.accountAddress,
    data: {
      function: `${PACKAGE}::dex_accounts_entry::place_order_to_subaccount`,
      typeArguments: [],
      functionArguments: [
        "0x123...abc", // subaccountAddr
        "0x456...def", // marketAddr (PerpMarket object address)
        5670000000, // price (5.67 with 9 decimals)
        1000000000, // size (1.0 with 9 decimals)
        true, // isBuy (true for buy, false for sell)
        0, // timeInForce (0 = GoodTillCanceled, 1 = PostOnly, 2 = ImmediateOrCancel)
        false, // isReduceOnly
        null, // clientOrderId (optional)
        null, // stopPrice (optional)
        null, // tpTriggerPrice (optional)
        null, // tpLimitPrice (optional)
        null, // slTriggerPrice (optional)
        null, // slLimitPrice (optional)
        null, // builderAddress (optional)
        null, // builderFees (optional)
      ],
    },
  });

  // Sign the transaction
  const senderAuthenticator = aptos.transaction.sign({
    signer: account,
    transaction,
  });

  // Submit the transaction
  const pendingTransaction = await aptos.transaction.submit.simple({
    transaction,
    senderAuthenticator,
  });

  // Wait for confirmation
  const executedTx = await aptos.waitForTransaction({
    transactionHash: pendingTransaction.hash,
  });

  console.log("Order placed successfully!");
  console.log("Transaction Hash:", executedTx.hash);

  ```

  ```typescript TypeScript Testnet theme={null}
  import {
    Aptos,
    AptosConfig,
    Ed25519Account,
    Ed25519PrivateKey,
    Network,
  } from "@aptos-labs/ts-sdk";

  // Configuration
  const PACKAGE = "0xe7da2794b1d8af76532ed95f38bfdf1136abfd8ea3a240189971988a83101b7f";

  // Your private key (keep this secure!)
  const privateKey = "0x..."; // Your private key in hex format

  // Create account from private key
  const account = new Ed25519Account({
    privateKey: new Ed25519PrivateKey(privateKey),
  });

  // Initialize Aptos client
  const aptosConfig = new AptosConfig({
    network: Network.TESTNET,
  });
  const aptos = new Aptos(aptosConfig);

  // Build the transaction
  const transaction = await aptos.transaction.build.simple({
    sender: account.accountAddress,
    data: {
      function: `${PACKAGE}::dex_accounts_entry::place_order_to_subaccount`,
      typeArguments: [],
      functionArguments: [
        "0x123...abc", // subaccountAddr
        "0x456...def", // marketAddr (PerpMarket object address)
        5670000000, // price (5.67 with 9 decimals)
        1000000000, // size (1.0 with 9 decimals)
        true, // isBuy (true for buy, false for sell)
        0, // timeInForce (0 = GoodTillCanceled, 1 = PostOnly, 2 = ImmediateOrCancel)
        false, // isReduceOnly
        null, // clientOrderId (optional)
        null, // stopPrice (optional)
        null, // tpTriggerPrice (optional)
        null, // tpLimitPrice (optional)
        null, // slTriggerPrice (optional)
        null, // slLimitPrice (optional)
        null, // builderAddress (optional)
        null, // builderFees (optional)
      ],
    },
  });

  // Sign the transaction
  const senderAuthenticator = aptos.transaction.sign({
    signer: account,
    transaction,
  });

  // Submit the transaction
  const pendingTransaction = await aptos.transaction.submit.simple({
    transaction,
    senderAuthenticator,
  });

  // Wait for confirmation
  const executedTx = await aptos.waitForTransaction({
    transactionHash: pendingTransaction.hash,
  });

  console.log("Order placed successfully!");
  console.log("Transaction Hash:", executedTx.hash);
  ```

  ```python Python Mainnet theme={null}
  from aptos_sdk.account import Account
  from aptos_sdk.client import RestClient
  from aptos_sdk.account_address import AccountAddress

  # Configuration
  PACKAGE = "0x50ead22afd6ffd9769e3b3d6e0e64a2a350d68e8b102c4e72e33d0b8cfdfdb06"
  FULLNODE_URL = "https://api.mainnet.aptoslabs.com/v1"

  # Your private key (keep this secure!)
  private_key = "0x..."  # Your private key in hex format

  # Create account from private key
  account = Account.load_key(private_key)

  # Initialize Aptos client
  rest_client = RestClient(FULLNODE_URL)

  # Build the transaction
  transaction = rest_client.build_transaction(
      sender=account.address(),
      payload={
          "function": f"{PACKAGE}::dex_accounts_entry::place_order_to_subaccount",
          "type_arguments": [],
          "function_arguments": [
              "0x123...abc",  # subaccountAddr
              "0x456...def",  # marketAddr (PerpMarket object address)
              5670000000,  # price (5.67 with 9 decimals)
              1000000000,  # size (1.0 with 9 decimals)
              True,  # isBuy (true for buy, false for sell)
              0,  # timeInForce (0 = GoodTillCanceled, 1 = PostOnly, 2 = ImmediateOrCancel)
              False,  # isReduceOnly
              None,  # clientOrderId (optional)
              None,  # stopPrice (optional)
              None,  # tpTriggerPrice (optional)
              None,  # tpLimitPrice (optional)
              None,  # slTriggerPrice (optional)
              None,  # slLimitPrice (optional)
              None,  # builderAddress (optional)
              None,  # builderFees (optional)
          ],
      },
  )

  # Sign the transaction
  signed_transaction = account.sign(transaction)

  # Submit the transaction
  pending_transaction = rest_client.submit_transaction(signed_transaction)

  # Wait for confirmation
  executed_tx = rest_client.wait_for_transaction(pending_transaction)

  print("Order placed successfully!")
  print(f"Transaction Hash: {executed_tx['hash']}")
  ```

  ```python Python Testnet theme={null}
  from aptos_sdk.account import Account
  from aptos_sdk.client import RestClient
  from aptos_sdk.account_address import AccountAddress

  # Configuration
  PACKAGE = "0xe7da2794b1d8af76532ed95f38bfdf1136abfd8ea3a240189971988a83101b7f"
  FULLNODE_URL = "https://api.testnet.aptoslabs.com/v1"

  # Your private key (keep this secure!)
  private_key = "0x..."  # Your private key in hex format

  # Create account from private key
  account = Account.load_key(private_key)

  # Initialize Aptos client
  rest_client = RestClient(FULLNODE_URL)

  # Build the transaction
  transaction = rest_client.build_transaction(
      sender=account.address(),
      payload={
          "function": f"{PACKAGE}::dex_accounts_entry::place_order_to_subaccount",
          "type_arguments": [],
          "function_arguments": [
              "0x123...abc",  # subaccountAddr
              "0x456...def",  # marketAddr (PerpMarket object address)
              5670000000,  # price (5.67 with 9 decimals)
              1000000000,  # size (1.0 with 9 decimals)
              True,  # isBuy (true for buy, false for sell)
              0,  # timeInForce (0 = GoodTillCanceled, 1 = PostOnly, 2 = ImmediateOrCancel)
              False,  # isReduceOnly
              None,  # clientOrderId (optional)
              None,  # stopPrice (optional)
              None,  # tpTriggerPrice (optional)
              None,  # tpLimitPrice (optional)
              None,  # slTriggerPrice (optional)
              None,  # slLimitPrice (optional)
              None,  # builderAddress (optional)
              None,  # builderFees (optional)
          ],
      },
  )

  # Sign the transaction
  signed_transaction = account.sign(transaction)

  # Submit the transaction
  pending_transaction = rest_client.submit_transaction(signed_transaction)

  # Wait for confirmation
  executed_tx = rest_client.wait_for_transaction(pending_transaction)

  print("Order placed successfully!")
  print(f"Transaction Hash: {executed_tx['hash']}")
  ```
</CodeGroup>

### What This Code Does

1. **Imports**: Imports the necessary classes from `@aptos-labs/ts-sdk` (TypeScript) or `aptos-sdk` (Python)
2. **Account Setup**: Creates an account from your private key
3. **Client Initialization**: Initializes the Aptos client with the network configuration
4. **Transaction Building**: Builds a transaction calling `place_order_to_subaccount` with your order parameters
5. **Signing**: Signs the transaction with your private key
6. **Submission**: Submits the signed transaction to the blockchain
7. **Confirmation**: Waits for the transaction to be confirmed

### Next Steps

For more detailed information, see:

* [Place Order Transaction](/developer-hub/on-chain/order-management/place-order) - Complete documentation for placing orders
* [Formatting Prices and Sizes](/developer-hub/on-chain/overview/formatting-prices-sizes) - Learn how to format prices and sizes correctly
* [Optimized Transaction Building](/developer-hub/on-chain/overview/optimized-building) - Learn how to build transactions synchronously for better performance
* [Authenticated Requests](/quickstart/authenticated-requests) - Overview of authenticated requests

<Info>
  **Note:** This example uses mock addresses for `subaccountAddr` and
  `marketAddr`. In a real application, you'll need to: - Get your Trading Account
  address (see [Create Trading
  Account](/developer-hub/on-chain/account-management/create-subaccount)) - Get the
  market address from the `v1/markets` API endpoint - Format prices and sizes
  correctly using market configuration (see [Formatting Prices and
  Sizes](/developer-hub/on-chain/overview/formatting-prices-sizes))
</Info>

<Warning>
  **Security:** Never expose your private key in client-side code or commit it
  to version control. Use environment variables or secure key management
  systems.
</Warning>
