API Reference
Client
class td_ameritrade_api.client(refresh_token, consumer_key, account_id)
Parameters
refresh_token (Required[str]) The oauth2 refresh token from the TD Ameritrade API used to obtain the access token to use the API.
consumer_key (Required[str]) The API consumer key from when you create an app on TD's developer website.
account_id (Optional[str]) Your account id which is needed to view account stats or place any orders. Trying to call any methods that require this to work will result in an error.
Methods
dict client.quote(symbol)
Returns a quote on the supplied symbol.
Parameters
symbol (Required[str]) The symbol to get the quote of.
Raises
ApiError - Raised when there is an error calling the API.
dict client.search(symbol)
Search or retrieve instrument data.
Parameters
symbol (Required[str]) An asset symbol.
Raises
ApiError - Raised when there is an error calling the API.
dict client.fundemental(symbol)
Returns fundamental data for the supplied symbol.
Parameters
symbol (Required[str]) An asset symbol.
Raises
ApiError - Raised when there is an error calling the API.
dict client.account()
Returns Account balances.
Raises
ApiError - Raised when there is an error calling the API.
dict client.orders()
Returns all orders for your account.
Raises
ApiError - Raised when there is an error calling the API.
dict client.transactions()
Returns all transactions for your account.
Raises
ApiError - Raised when there is an error calling the API.
dict client.watchlists()
Returns all watch lists for your account.
Raises
ApiError - Raised when there is an error calling the API.
dict client.watchlist(watchlist_id)
Returns a specific watch list.
Parameters
watchlist_id (Required[str]) The id of the watchlist you want to get.
Raises
ApiError - Raised when there is an error calling the API.
dict client.positions()
Returns all positions for your account.
Raises
ApiError - Raised when there is an error calling the API.
dict client.available_funds()
Returns the amount of available funds in your account.
Raises
ApiError - Raised when there is an error calling the API.
dict client.price_history(symbol, *, period_type='day', period=1, frequency_type='minute', frequency=1, start_date=None, end_date=None, need_extended_hours_data=False)
Returns price history for the specified symbol.
Parameters
symbol (Required[str]) An asset symbol.
period_type (Optional[str]) The type of period to show. Valid values are
day,month,year, orytd(year to date).period (Optional[int]) The number of periods to show.
frequency_type (Optional[str]) The type of frequency with which a new candle is formed. Valid frequency_types by period_type:
day: minutemonth: daily, weeklyyear: daily, weekly, monthlyytd: daily, weeklyfrequency (Optional[int]) The number of the frequency_type to be included in each candle. Valid frequencies by frequency_type:
minute: 1, 5, 10, 15, 30daily: 1weekly: 1monthly: 1start_date (Optional[int]) Start date as milliseconds since epoch. If start_date and end_date are provided, period should not be provided.
end_date (Optional[int]) End date as milliseconds since epoch. If start_date and end_date are provided, period should not be provided.
need_extended_hours_data (Optional[bool]) If true, extended hours data will be included.
Raises
ApiError - Raised when there is an error calling the API.
void client.buy_limit_equity(symbol, price, quanity)
Places a limit order to buy for the specified equity at the specified price for the specified quantity.
Parameters
symbol (Required[str]) An asset symbol.
price (Required[float]) The price that you want the limit order to be at.
quantity (Required[int]) The amount of the asset that you want to buy.
Raises
ApiError - Raised when there is an error calling the API.
void client.sell_limit_equity(symbol, price, quanity)
Places a limit order to sell for the specified equity at the specified price for the specified quantity.
Parameters
symbol (Required[str]) An asset symbol.
price (Required[float]) The price that you want the limit order to be at.
quantity (Required[int]) The amount of the asset that you want to sell.
Raises
ApiError - Raised when there is an error calling the API.
void client.place_custom_order(symbol, price, quanity)
Places a custom order. Check here for documentation on how to make custom orders.
Parameters
order(Required[dict]) The order to place.
Raises
ApiError - Raised when there is an error calling the API.
Exceptions
ApiError
exception td_ameritrade_api.ApiError(APIPath, status, error)
APIPath The path to the address where the error occurred.
status The HTTP request response code.
error The error message, may be nil.
Last updated
Was this helpful?