Skip to main content

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
  2. Your private key (keep this secure!)
  3. APT in your account for gas fees (or set up Geomi Gas Station to sponsor gas)

Configuration Variables

Before placing an order, you’ll need to set these configuration variables:
PACKAGE=0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95
FULLNODE_URL=https://api.netna.aptoslabs.com/v1

Minimum Required Code

Here’s the minimal code needed to place an order:
import {
  Aptos,
  AptosConfig,
  Ed25519Account,
  Ed25519PrivateKey,
  Network,
} from "@aptos-labs/ts-sdk";

// Configuration
const PACKAGE = "0xb8a5788314451ce4d2fbbad32e1bad88d4184b73943b7fe5166eab93cf1a5a95";
const FULLNODE_URL = "https://api.netna.aptoslabs.com/v1";

// 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.CUSTOM,
fullnode: FULLNODE_URL,
});
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);

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:
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) - Get the market address from the v1/markets API endpoint - Format prices and sizes correctly using market configuration (see Formatting Prices and Sizes)
Security: Never expose your private key in client-side code or commit it to version control. Use environment variables or secure key management systems.