
|
QT Trading API - TD AMERITRADE Specific (AMTRADE.TRD)
|

|
SEND COMMANDS (Client Application to QT Server)
The following SEND TYPE commands are supported for TD Ameritrade:
| NEWORDER | - Sends a New Order to the broker |
| MODIFYORDER | - Modifies an existing order |
| CANCELORDER | - Cancels one or more orders |
| REFTRAN | - Forces a refresh of transactions. No parameters |
| REFBAL | - Forces a refresh of Balances and Positions. No parameters |
NOTIFICATION RESPONSES (QT Server to Application)
The following is a list of Notification TYPES that can be returned:
| ACK | - acknowledgement of a successful order transaction. |
| ERROR | - Error while parsing command or error returned from the broker |
| TRANSACTIONS | - List of transactions for the day |
| BALANCES | - Current Balances information |
| POSITIONS | - Current Positions information |
SEND COMMANDS DETAILS
 |
NEWORDER - Send a New Order to the broker |
 |
|
| Parameter Name | Parameter Values and Description |
| ClientOrderID | (Optional) Some value specified by the calling application that helps it identify the order. Any ACK or ERROR message returned for the transaction will include the ClientOrderID if it was specified |
| SymbolType | STOCK or OPTION |
| Symbol | Symbol of the security to be traded |
| Action | For Stocks: BUY, SELL, SHORT, COVER
For Options: BUY_OPEN, BUY_CLOSE, SELL_OPEN, SELL_CLOSE |
| OrderType | LIMIT, MARKET, STOPMARKET, STOPLIMIT, TSTOP |
| Quantity | Number of Shares or Contracts in the transaction |
| LimitPrice | LIMIT Price for Limit orders |
| StopPrice | STOP Price (Activation Price) for STOP orders, or Trail Amount for Trailing Stop |
| StopBasis | If the OrderType is TSTOP, then specify either PERCENT or POINTS to indicate how the specified Trail Amount should be interpreted |
| DisplaySize | (INET Orders) Number of shares to dislay on Level II |
| TIF | Time In Force: DAY, DAY+, GTC, GTC+, MOC (Order type must be MARKET), PRE (Ext. Hours - Pre-Market), POST (Ext. Hours - Post-Market) |
| TIFDate | If the TIF is GTC, the DATE that the order should be good till (MM/DD/YYYY) |
| Route | For Stocks: SMART or AUTO, INET, ARCA
For Options: SMART or AUTO, BOSX, CBOE, AMEX, PHLX, PACX, ISEX |
| AON | All or None: YES if set. NO if omitted |
| DNR | Do Not Reduce: YES if set. NO if omitted |
| FOK | Fill or Kill: YES if set. NO if omitted |
NOTE: Very little error checking is done for API order prior to sending them to the broker.
Some parameter value combinations are not available, such as OrderType: MARKET Route: INET.
Invalid orders will be rejected by TD Ameritrade and the rejection will be returned to you in a NOTIFICATION message.
EXAMPLE:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<ACTION>SEND</ACTION>
<TYPE>NEWORDER</TYPE>
<PARAMS>
<ClientOrderID>TDA1234</ClientOrderID>
<SymbolType>STOCK</SymbolType>
<Symbol>DELL</Symbol>
<Action>BUY</Action>
<OrderType>LIMIT</OrderType>
<Quantity>500</Quantity>
<LimitPrice>41.72</LimitPrice>
<TIF>GTC</TIF>
<TIFDate>12/29/2004</TIFDate>
<Route>SMART</Route>
<AON>YES</AON>
</PARAMS>
</TRADEAPI>
{FF}
|
|
 |
MODIFYORDER - Modifies an existing order |
 |
|
| Parameter Name | Parameter Values and Description |
| ClientOrderID | (Optional) Some value specified by the calling application that helps it identify the order. Any ACK or ERROR message returned for the transaction will include the ClientOrderID if it was specified |
| OrderID | The Order ID of the order being modified. Should be retrieved from TRANSACTIONS |
| SYMBOL | OPTIONAL - the symbol of the security being traded (MUST be the same as original order) |
| ACTION | OPTIONAL - BUY,SELL, etc... (MUST be the same as original order) |
| OrderType | LIMIT, MARKET, STOPMARKET, STOPLIMIT |
| Quantity | Number of Shares or Contracts in the transaction |
| LimitPrice | LIMIT Price for Limit orders |
| StopPrice | STOP Price for STOP orders |
| TIF | Time In Force: DAY, DAY+, GTC, GTC+ |
| TIFDate | If the TIF is GTC, the DATE that the order should be good till (MM/DD/YYYY) |
NOTE: ALL Fields are required. If not changing a particular field, send the value that was returned in TRANSACTIONS.
EXAMPLE:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<ACTION>SEND</ACTION>
<TYPE>MODIFYORDER</TYPE>
<PARAMS>
<ClientOrderID>TDA1234</ClientOrderID>
<OrderID>1227175600</OrderID>
<OrderType>LIMIT</OrderType>
<Quantity>500</Quantity>
<LimitPrice>41.72</LimitPrice>
<TIF>GTC</TIF>
<TIFDate>05/14/05</TIFDate>
</PARAMS>
</TRADEAPI>
{FF}
|
|
 |
CANCELORDER - Cancels one or more orders |
 |
|
| Parameter Name | Parameter Values and Description |
| OrderID | The Order ID of the order to be canceled. |
NOTE: To cancel more than one order at a time, just include multiple OrderID XML tags, one for each order
EXAMPLE:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<ACTION>SEND</ACTION>
<TYPE>CANCELORDER</TYPE>
<PARAMS>
<OrderID>1227175600</OrderID>
<OrderID>1228893440</OrderID>
<OrderID>1220327423</OrderID>
</PARAMS>
</TRADEAPI>
{FF}
|
|
NOTIFICATION RESPONSES
NOTE: The examples below will not show Record ID or Record Length for simplicity, even though they are sent with every message.
 |
ACK - Acknowledgement of a successful order transaction |
 |
|
Result returned in XML.
EXAMPLES:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>ACK</TYPE>
<ORDERID>123456789</ORDERID>
<CLIENTORDERID>TDA1234</CLIENTORDERID>
<MESSAGE> Order ID: 123456789 NEW Submitted
</MESSAGE>
</TRADEAPI>
|
OR
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>ACK</TYPE>
<MESSAGE> The following order(s) have been submitted for cancellation, on Account xxxxxxxx
1372343999
1372034923
</MESSAGE>
</TRADEAPI>
|
|
 |
ERROR - Error while parsing command or error returned from the broker |
 |
|
Result returned in XML.
EXAMPLES:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>ERROR</TYPE>
<MESSAGE>Unable to get Positions data</MESSAGE>
</TRADEAPI>
|
OR
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>ERROR</TYPE>
<CLIENTORDERID>TDA1234</CLIENTORDERID>
<MESSAGE>Please enter any date between today and six months from today.</MESSAGE>
</TRADEAPI>
|
|
 |
TRANSACTIONS - List of transactions on the account for the day |
 |
|
Result returned in XML.
| Parameter Name | Parameter Values and Description |
| OrderID | Order ID of the order |
| OrderStatus | Current Status of the order |
| Open | YES/NO - Whether or not this is an OPEN order - Still being processed |
| Symbol | Symbol of the security being traded |
| SymbolType | Type security being traded (STOCK, OPTION) |
| Action | BUY,SELL,(Same as in NEWORDER)... |
| OrderType | LIMIT, MARKET, STOPMARKET, STOPLIMIT, TSTOP |
| Quantity | Number of Shares or Contracts in the transaction |
| LimitPrice | LIMIT Price for Limit orders |
| StopPrice | STOP Price for STOP orders, or Trail Amount for Trailing Stop |
| StopBasis | For TSTOP order, specifies either PERCENT or POINTS to indicate how the Trail Amount is specified |
| DisplaySize | (INET Orders) Number of shares to dislay on Level II |
| TIF | Time In Force: DAY, DAY+, GTC... (Same as in NEWORDER) |
| TIFDate | The date that the order expires |
| TIFTime | The Time that the order expires |
| Route | AUTO, INET, etc... (Same as in NEWORDER) |
| AON | All or None: YES if set. NO if omitted |
| DNR | Do Not Reduce: YES if set. NO if omitted |
| FOK | Fill or Kill: YES if set. NO if omitted |
| OrderDate | Date the order was Placed |
| OrderTime | Time the order was Placed |
| FillDate | Date the order was filled (If Partial Fills, last fill) |
| FillTime | Time the order was filled (If Partial Fills, last fill) |
| FilledQuantity | The # of shares/contracts of the order that have been filled |
| UnfilledQuantity | # of Shares or Contracts yet to be filled |
| FillPrice | The average price of the filled shares/contracts |
| PartialFills | The list of each partial fill - QTY@Price format, comma separated |
EXAMPLES:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>TRANSACTIONS</TYPE>
<TRANSACTIONS>
<ORDER>
<OrderID>1374443999</OrderID>
<Action>SELL</Action>
<Quantity>500</Quantity>
<FilledQuantity>0</FilledQuantity>
<UnfilledQuantity>500</UnfilledQuantity>
<Symbol>DELL</Symbol>
<SymbolType>STOCK</SymbolType>
<OrderType>TSTOP</OrderType>
<StopPrice>2.50</StopPrice>
<StopBasis>POINTS</StopBasis>
<TIF>GTC</TIF>
<TIFDate>06/29/2005</TIFDate>
<TIFTime>16:00:00</TIFTime>
<AON>YES</AON>
<OrderStatus>Canceled</OrderStatus>
<Open>NO</Open>
<Route>AUTO</Route>
<OrderDate>05/05/05</OrderDate>
<OrderTime>16:00:00</OrderTime>
</ORDER>
</TRANSACTIONS>
</TRADEAPI>
|
|
 |
BALANCES - Current Balances information |
 |
|
Result returned in XML.
NOTE: The values for the NAME Field are coming directly from TD Ameritrade. They can change without notice.
EXAMPLES:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>BALANCES</TYPE>
<BALANCES>
<Entry>
<Name>Available Funds</Name>
<Current>23,129.19</Current>
<Change>00129.00</Change>
</Entry>
<Entry>
<Name>Buying Power</Name>
<Current>23,129.19</Current>
<Change>129</Change>
</Entry>
... More Entries ...
</BALANCES>
</TRADEAPI>
|
|
 |
POSITIONS - Current Positions information |
 |
|
Result returned in XML.
EXAMPLES:
| |
<TRADEAPI>
<ID>AMTDS1</ID>
<TYPE>POSITIONS</TYPE>
<POSITIONS>
<POSITION>
<Symbol>DELL</Symbol>
<SymbolType>STOCK</SymbolType>
<Name>Dell Inc</Name>
<Quantity>400</Quantity>
<ClosePrice>41.61</ClosePrice>
<PositionType>LONG</PositionType>
<Commission>10.99</Commission>
<Cost>41.00</Cost>
</POSITION>
<POSITION>
<Symbol>GOOG</Symbol>
<SymbolType>STOCK</SymbolType>
<Name>Google Inc</Name>
<Quantity>500</Quantity>
<ClosePrice>183.75</ClosePrice>
<PositionType>LONG</PositionType>
<Commission>10.99</Commission>
<Cost>174.23</Cost>
</POSITION>
... More POSITION records ...
</POSITIONS>
</TRADEAPI>
|
|
|
|

|

|
|
|
|