Key Parameters in the Order Payload
Field Description
orderType Order type, e.g., LIMIT, MARKET.
session Trading session (NORMAL, AM, PM, SEAMLESS).
duration Order duration, e.g., DAY or GTC (Good Till Canceled).
instruction BUY or SELL.
quantity Number of shares to buy/sell.
price For limit orders, the maximum price you're willing to pay.
assetType Asset type (EQUITY for stocks, OPTION for options).
Notes
Authorization: Ensure your access token is valid. Tokens expire after 30 minutes.
Sandbox Testing: TD Ameritrade does not offer a dedicated sandbox for testing live orders. Be careful when placing real orders.
Error Handling: Always check the API response for errors.
Here’s a simple example of placing a **buy order** using the TD Ameritrade API. This program assumes you already have a valid **access token**.
---
### Required Steps
1. **Obtain Access Token**:
2. **Account ID**: Get your account ID from your TD Ameritrade account.
3. **Buy Order Details**: Define the stock symbol, quantity, price, and order type.
---