Struct tdameritrade_rust::SyncTDAClient
source · pub struct SyncTDAClient { /* private fields */ }
Implementations§
source§impl SyncTDAClient
impl SyncTDAClient
sourcepub fn new(
client_id: String,
redirect_uri: String,
token_path: String
) -> Result<SyncTDAClient, TDAClientError>
pub fn new( client_id: String, redirect_uri: String, token_path: String ) -> Result<SyncTDAClient, TDAClientError>
Create New Synchronous TDAClient
pub fn clone(&self) -> Self
sourcepub fn get_account(
&self,
acct_id: i64,
fields: Option<&Vec<&str>>
) -> Result<String, TDAClientError>
pub fn get_account( &self, acct_id: i64, fields: Option<&Vec<&str>> ) -> Result<String, TDAClientError>
Account balances, positions, and orders for a specific account
Parameters
- acct_id: Account number
- fields: Balances displayed by default. Valid fields are
positions
ororders
(Optional)
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts/%7BaccountId%7D-0
sourcepub fn get_accounts(
&self,
fields: Option<&Vec<&str>>
) -> Result<String, TDAClientError>
pub fn get_accounts( &self, fields: Option<&Vec<&str>> ) -> Result<String, TDAClientError>
Account balances, positions, and orders for all linked accounts
Parameters
- fields: Balances displayed by default. Valid fields are
positions
ororders
(Optional)
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts-0
sourcepub fn search_instruments(
&self,
symbol: &str,
projection: &str
) -> Result<String, TDAClientError>
pub fn search_instruments( &self, symbol: &str, projection: &str ) -> Result<String, TDAClientError>
Search or retrieve instrument data, including fundamental data
Parameters
- symbol: Value to pass to the search. See projection description for more information
- projection: The type of request
- symbol-search: Retrieve instrument data of a specific symbol or cusip
- symbol-regex: Retrieve instrument data for all symbols matching regex. Example: symbol=
XYZ.*
will return all symbols beginning with XYZ - desc-search: Retrieve instrument data for instruments whose description contains the word supplied. Example: symbol=
FakeCompany
will return all instruments with FakeCompany in the description - desc-regex: Search description with full regex support. Example: symbol=
XYZ.[A-C]
returns all instruments whose descriptions contain a word beginning with XYZ followed by a character A through C - fundamental: Returns fundamental data for a single instrument specified by exact symbol
Official Documentation: https://developer.tdameritrade.com/instruments/apis/get/instruments
sourcepub fn get_instrument(&self, cusip: &str) -> Result<String, TDAClientError>
pub fn get_instrument(&self, cusip: &str) -> Result<String, TDAClientError>
Get an instrument by CUSIP
Parameters
- cusip: CUSIP string
Official Documentation: https://developer.tdameritrade.com/instruments/apis/get/instruments/%7Bcusip%7D
sourcepub fn get_hours_for_multiple_markets(
&self,
markets: &Vec<&str>,
date: &str
) -> Result<String, TDAClientError>
pub fn get_hours_for_multiple_markets( &self, markets: &Vec<&str>, date: &str ) -> Result<String, TDAClientError>
Retrieve market hours for specified markets
Parameters
- markets: The markets for which you’re requesting market hours. Valid markets are
EQUITY
,OPTION
,FUTURE
,BOND
, orFOREX
- date: The date for which market hours information is requested. Valid ISO-8601 formats are
yyyy-MM-dd
oryyyy-MM-dd'T'HH:mm:ssz
Official Documentation: https://developer.tdameritrade.com/market-hours/apis/get/marketdata/hours
sourcepub fn get_hours_for_single_market(
&self,
market: &str,
date: &str
) -> Result<String, TDAClientError>
pub fn get_hours_for_single_market( &self, market: &str, date: &str ) -> Result<String, TDAClientError>
Retrieve market hours for specified single market
Parameters
- markets: The markets for which you’re requesting market hours. Valid markets are
EQUITY
,OPTION
,FUTURE
,BOND
, orFOREX
- date: The date for which market hours information is requested. Valid ISO-8601 formats are
yyyy-MM-dd
oryyyy-MM-dd'T'HH:mm:ssz
Official Documentation: https://developer.tdameritrade.com/market-hours/apis/get/marketdata/%7Bmarket%7D/hours
sourcepub fn get_movers(
&self,
index: &str,
direction: &str,
change: &str
) -> Result<String, TDAClientError>
pub fn get_movers( &self, index: &str, direction: &str, change: &str ) -> Result<String, TDAClientError>
Top 10 (up or down) movers by value or percent for a particular market
Parameters
- index: The index symbol to get movers from. Valid indexes are
$COMPX
,$DJI
, or$SPX.X
- direction: To return movers with the specified directions. Valid directions are
up
ordown
- change: To return movers with the specified change types. Valid change types are
percent
orvalue
Official Documentation: https://developer.tdameritrade.com/movers/apis/get/marketdata/%7Bindex%7D/movers
sourcepub fn get_option_chain(
&self,
option_params: &OptionChain
) -> Result<String, TDAClientError>
pub fn get_option_chain( &self, option_params: &OptionChain ) -> Result<String, TDAClientError>
Get option chain for an optionable symbol
Parameters
- option_params:
OptionChain
object- symbol: Enter one symbol (case-sensitive)
- contract_type: Type of contracts to return in the chain. Valid contract types are
CALL
,PUT
, orALL
. Default isALL
(Optional) - strike_count: The number of strikes to return above and below the at-the-money price (Optional)
- include_quotes: Include quotes for options in the option chain. Default is false (Optional)
- strategy: Passing a value returns a strategy chain. Valid strategy values are
SINGLE
,ANALYTICAL
(allows use of the volatility, underlyingPrice, interestRate, and daysToExpiration params to calculate theoretical values),COVERED
,VERTICAL
,CALENDAR
,STRANGLE
,STRADDLE
,BUTTERFLY
,CONDOR
,DIAGONAL
,COLLAR
, orROLL
. Default isSINGLE
(Optional) - interval: Strike interval for spread strategy chains (Optional)
- strike: Provide a strike price to return options only at that strike price (Optional)
- range: Returns options for the given range. Valid ranges are
ITM
(In the money),NTM
(Near the money),OTM
(Out of the money),SAK
(Strikes above market),SBK
(Strikes below market),SNK
(Strikes near market), orALL
(All strikes). Default isALL
(Optional) - from_date: Only return expirations after this date. For strategies, expiration refers to the nearest term expiration in the strategy. Valid ISO-8601 formats are
yyyy-MM-dd
oryyyy-MM-dd'T'HH:mm:ssz
(Optional) - to_date: Only return expirations before this date. For strategies, expiration refers to the nearest term expiration in the strategy. Valid ISO-8601 formats are
yyyy-MM-dd
oryyyy-MM-dd'T'HH:mm:ssz
(Optional) - volatility: Volatility to use in calculations. Applies only to
ANALYTICAL
strategy chains (Optional) - underlying_price: Underlying price to use in calculations. Applies only to
ANALYTICAL
strategy chains (Optional) - interest_rate: Interest rate to use in calculations. Applies only to
ANALYTICAL
strategy chains (Optional) - days_to_expiration: Days to expiration to use in calculations. Applies only to
ANALYTICAL
strategy chains (Optional) - expiration_month: Return only options expiring in the specified month. Month is given in the three character format. Example:
JAN
. Default isALL
(Optional) - option_type: Type of contracts to return. Valid option types are
S
(Standard contracts),NS
(Non-standard contracts), orALL
(All contracts). Default isALL
(Optional)
Official Documentation: https://developer.tdameritrade.com/option-chains/apis/get/marketdata/chains
sourcepub fn get_preferences(&self, acct_id: i64) -> Result<String, TDAClientError>
pub fn get_preferences(&self, acct_id: i64) -> Result<String, TDAClientError>
Preferences for a specific account
Parameters
- acct_id: Account number
Official Documentation: https://developer.tdameritrade.com/user-principal/apis/get/accounts/%7BaccountId%7D/preferences-0
sourcepub fn update_preferences(
&self,
acct_id: i64,
preference_spec: &str
) -> Result<(), TDAClientError>
pub fn update_preferences( &self, acct_id: i64, preference_spec: &str ) -> Result<(), TDAClientError>
Update preferences for a specific account. Please note that the directOptionsRouting and directEquityRouting values cannot be modified via this operation
Parameters
- acct_id: Account number
- preference_spec: Preference body
Official Documentation: https://developer.tdameritrade.com/user-principal/apis/put/accounts/%7BaccountId%7D/preferences-0
sourcepub fn get_price_history(
&self,
history_params: &PriceHistory
) -> Result<String, TDAClientError>
pub fn get_price_history( &self, history_params: &PriceHistory ) -> Result<String, TDAClientError>
Get price history for a symbol
Parameters
- history_params:
PriceHistory
object- symbol: Enter one symbol (case-sensitive)
- period_type: The type of period to show. Valid period types are
day
,month
,year
, orytd
(year to date) - period: The number of periods to show. Valid periods for day are
1
,2
,3
,4
,5
, or10
. Valid periods for month are1
,2
,3
, or6
. Valid periods for year are1
,2
,3
,5
,10
,15
, or20
. Valid periods for ytd are1
(Optional) - frequency_type: The type of frequency with which a new candle is formed. Valid frequency types for day are
minute
. Valid frequency types for month aredaily
orweekly
. Valid frequency types for year aredaily
,weekly
, ormonthly
. Valid frequency types for ytd aredaily
orweekly
- frequency: The number of the frequency_type to be included in each candle. Valid frequencies for minute are
1
,5
,10
,15
, or30
. Valid frequencies for daily are1
. Valid frequencies for weekly are1
. Valid frequencies for monthly are1
- start_date: Start date as milliseconds since epoch. If start_date and end_date are provided, period should not be provided (Optional)
- end_date: End date as milliseconds since epoch. If start_date and end_date are provided, period should not be provided (Optional)
- need_extended_hours_data: Returns extended hours data. Default is true (Optional)
Official Documentation: https://developer.tdameritrade.com/price-history/apis/get/marketdata/%7Bsymbol%7D/pricehistory
sourcepub fn get_quote(&self, symbol: &str) -> Result<String, TDAClientError>
pub fn get_quote(&self, symbol: &str) -> Result<String, TDAClientError>
Get quote for a symbol
Parameters
- symbol: Enter one symbol (case-sensitive)
Official Documentation: https://developer.tdameritrade.com/quotes/apis/get/marketdata/%7Bsymbol%7D/quotes
sourcepub fn get_quotes(&self, symbols: &Vec<&str>) -> Result<String, TDAClientError>
pub fn get_quotes(&self, symbols: &Vec<&str>) -> Result<String, TDAClientError>
Get quote for one or more symbols
Parameters
- symbols: Enter one or more symbols in a vector (case-sensitive)
Official Documentation: https://developer.tdameritrade.com/quotes/apis/get/marketdata/quotes
sourcepub fn get_order(
&self,
acct_id: i64,
order_id: i64
) -> Result<String, TDAClientError>
pub fn get_order( &self, acct_id: i64, order_id: i64 ) -> Result<String, TDAClientError>
Get a specific order for a specific account
Parameters
- acct_id: Account number
- order_id: Order number
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts/%7BaccountId%7D/orders/%7BorderId%7D-0
sourcepub fn get_orders_by_path(
&self,
acct_id: i64,
max_results: i64,
from_entered_time: &str,
to_entered_time: &str,
status: &str
) -> Result<String, TDAClientError>
pub fn get_orders_by_path( &self, acct_id: i64, max_results: i64, from_entered_time: &str, to_entered_time: &str, status: &str ) -> Result<String, TDAClientError>
Orders for a specific account
Parameters
- acct_id: Account number
- max_results: The max number of orders to retrieve
- from_entered_time: Specifies that no orders entered before this time should be returned. Valid ISO-8601 formats are
yyyy-MM-dd
- to_entered_time: Specifies that no orders entered after this time should be returned. Valid ISO-8601 formats are
yyyy-MM-dd
- status: Specifies that only orders of this status should be returned. Valid statuses are
AWAITING_PARENT_ORDER
,AWAITING_CONDITION
,AWAITING_MANUAL_REVIEW
,ACCEPTED
,AWAITING_UR_OUT
,PENDING_ACTIVATION
,QUEUED
,WORKING
,REJECTED
,PENDING_CANCEL
,CANCELLED
,PENDING_REPLACE
,REPLACED
,FILLED
, orEXPIRED
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts/%7BaccountId%7D/orders-0
sourcepub fn get_orders_by_query(
&self,
acct_id: Option<i64>,
max_results: i64,
from_entered_time: &str,
to_entered_time: &str,
status: &str
) -> Result<String, TDAClientError>
pub fn get_orders_by_query( &self, acct_id: Option<i64>, max_results: i64, from_entered_time: &str, to_entered_time: &str, status: &str ) -> Result<String, TDAClientError>
All orders for a specific account or, if acct_id isn’t specified, orders will be returned for all linked accounts
Parameters
- acct_id: Account number (Optional)
- max_results: The max number of orders to retrieve
- from_entered_time: Specifies that no orders entered before this time should be returned. Valid ISO-8601 formats are
yyyy-MM-dd
- to_entered_time: Specifies that no orders entered after this time should be returned. Valid ISO-8601 formats are
yyyy-MM-dd
- status: Specifies that only orders of this status should be returned. Valid statuses are
AWAITING_PARENT_ORDER
,AWAITING_CONDITION
,AWAITING_MANUAL_REVIEW
,ACCEPTED
,AWAITING_UR_OUT
,PENDING_ACTIVATION
,QUEUED
,WORKING
,REJECTED
,PENDING_CANCEL
,CANCELLED
,PENDING_REPLACE
,REPLACED
,FILLED
, orEXPIRED
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/orders-0
sourcepub fn place_order(
&self,
acct_id: i64,
order_spec: &str
) -> Result<(), TDAClientError>
pub fn place_order( &self, acct_id: i64, order_spec: &str ) -> Result<(), TDAClientError>
Place an order for a specific account. Order throttle limits may apply
Parameters
- acct_id: Account number
- order_spec: Order body
Order Examples: https://developer.tdameritrade.com/content/place-order-samples
Official Documentation: https://developer.tdameritrade.com/account-access/apis/post/accounts/%7BaccountId%7D/orders-0
sourcepub fn replace_order(
&self,
acct_id: i64,
order_id: i64,
order_spec: &str
) -> Result<(), TDAClientError>
pub fn replace_order( &self, acct_id: i64, order_id: i64, order_spec: &str ) -> Result<(), TDAClientError>
Replace an existing order for an account. The existing order will be replaced by the new order. Once replaced, the old order will be canceled and a new order will be created. Order throttle limits may apply
Parameters
- acct_id: Account number
- order_id: Order number
- order_spec: Order body
Order Examples: https://developer.tdameritrade.com/content/place-order-samples
Official Documentation: https://developer.tdameritrade.com/account-access/apis/put/accounts/%7BaccountId%7D/orders/%7BorderId%7D-0
sourcepub fn cancel_order(
&self,
acct_id: i64,
order_id: i64
) -> Result<(), TDAClientError>
pub fn cancel_order( &self, acct_id: i64, order_id: i64 ) -> Result<(), TDAClientError>
Cancel a specific order for a specific account. Order throttle limits may apply
Parameters
- acct_id: Account number
- order_id: Order number
Official Documentation: https://developer.tdameritrade.com/account-access/apis/delete/accounts/%7BaccountId%7D/orders/%7BorderId%7D-0
sourcepub fn get_saved_order(
&self,
acct_id: i64,
order_id: i64
) -> Result<String, TDAClientError>
pub fn get_saved_order( &self, acct_id: i64, order_id: i64 ) -> Result<String, TDAClientError>
Specific saved order by its ID, for a specific account
Parameters
- acct_id: Account number
- order_id: Saved order number
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts/%7BaccountId%7D/savedorders/%7BsavedOrderId%7D-0
sourcepub fn get_saved_orders_by_path(
&self,
acct_id: i64
) -> Result<String, TDAClientError>
pub fn get_saved_orders_by_path( &self, acct_id: i64 ) -> Result<String, TDAClientError>
Saved orders for a specific account
Parameters
- acct_id: Account number
Official Documentation: https://developer.tdameritrade.com/account-access/apis/get/accounts/%7BaccountId%7D/savedorders-0
sourcepub fn create_saved_order(
&self,
acct_id: i64,
order_spec: &str
) -> Result<(), TDAClientError>
pub fn create_saved_order( &self, acct_id: i64, order_spec: &str ) -> Result<(), TDAClientError>
Save an order for a specific account
Parameters
- acct_id: Account number
- order_spec: Order body
Order Examples: https://developer.tdameritrade.com/content/place-order-samples
Official Documentation: https://developer.tdameritrade.com/account-access/apis/post/accounts/%7BaccountId%7D/savedorders-0
sourcepub fn replace_saved_order(
&self,
acct_id: i64,
order_id: i64,
order_spec: &str
) -> Result<(), TDAClientError>
pub fn replace_saved_order( &self, acct_id: i64, order_id: i64, order_spec: &str ) -> Result<(), TDAClientError>
Replace an existing saved order for an account. The existing saved order will be replaced by the new order
Parameters
- acct_id: Account number
- order_id: Order number
- order_spec: Order body
Order Examples: https://developer.tdameritrade.com/content/place-order-samples
Official Documentation: https://developer.tdameritrade.com/account-access/apis/put/accounts/%7BaccountId%7D/savedorders/%7BsavedOrderId%7D-0
sourcepub fn delete_saved_order(
&self,
acct_id: i64,
order_id: i64
) -> Result<(), TDAClientError>
pub fn delete_saved_order( &self, acct_id: i64, order_id: i64 ) -> Result<(), TDAClientError>
Delete a specific saved order for a specific account
Parameters
- acct_id: Account number
- order_id: Order number
Official Documentation: https://developer.tdameritrade.com/account-access/apis/delete/accounts/%7BaccountId%7D/savedorders/%7BsavedOrderId%7D-0
sourcepub fn get_transaction(
&self,
acct_id: i64,
transaction_id: i64
) -> Result<String, TDAClientError>
pub fn get_transaction( &self, acct_id: i64, transaction_id: i64 ) -> Result<String, TDAClientError>
Transaction for a specific account
Parameters
- acct_id: Account number
- transaction_id: Transaction number
Official Documentation: https://developer.tdameritrade.com/transaction-history/apis/get/accounts/%7BaccountId%7D/transactions/%7BtransactionId%7D-0
sourcepub fn get_transactions(
&self,
acct_id: i64,
transaction_type: &str,
symbol: Option<&str>,
start_date: &str,
end_date: &str
) -> Result<String, TDAClientError>
pub fn get_transactions( &self, acct_id: i64, transaction_type: &str, symbol: Option<&str>, start_date: &str, end_date: &str ) -> Result<String, TDAClientError>
Transactions for a specific account
Parameters
- acct_id: Account number
- transaction_type: Only transactions with the specified type will be returned. Valid transaction types are
ALL
,TRADE
,BUY_ONLY
,SELL_ONLY
,CASH_IN_OR_CASH_OUT
,CHECKING
,DIVIDEND
,INTEREST
,OTHER
, orADVISOR_FEES
- symbol: Only transactions with the specified symbol will be returned (Optional)
- start_date: Only transactions after the start date will be returned. The maximum date range is one year. Valid ISO-8601 formats are
yyyy-MM-dd
- end_date: Only transactions before the end date will be returned. The maximum date range is one year. Valid ISO-8601 formats are
yyyy-MM-dd
Official Documentation: https://developer.tdameritrade.com/transaction-history/apis/get/accounts/%7BaccountId%7D/transactions-0
sourcepub fn get_streamer_subscription_keys(
&self,
acct_ids: &Vec<i64>
) -> Result<String, TDAClientError>
pub fn get_streamer_subscription_keys( &self, acct_ids: &Vec<i64> ) -> Result<String, TDAClientError>
SubscriptionKey for provided accounts or default accounts
Parameters
- acct_ids: Account number(s)
Official Documentation: https://developer.tdameritrade.com/user-principal/apis/get/userprincipals/streamersubscriptionkeys-0
sourcepub fn get_user_principals(
&self,
fields: Option<&Vec<&str>>
) -> Result<String, TDAClientError>
pub fn get_user_principals( &self, fields: Option<&Vec<&str>> ) -> Result<String, TDAClientError>
User principal details
Parameters
- fields: Enter additional fields into a vector. None of these fields are returned by default. Valid fields are
streamerSubscriptionKeys
,streamerConnectionInfo
,preferences
, orsurrogateIds
(Optional)
Official Documentation: https://developer.tdameritrade.com/user-principal/apis/get/userprincipals-0
sourcepub fn get_watchlist(
&self,
acct_id: i64,
watchlist_id: i64
) -> Result<String, TDAClientError>
pub fn get_watchlist( &self, acct_id: i64, watchlist_id: i64 ) -> Result<String, TDAClientError>
Specific watchlist for a specific account
Parameters
- acct_id: Account number
- watchlist_id: Watchlist number
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/get/accounts/%7BaccountId%7D/watchlists/%7BwatchlistId%7D-0
sourcepub fn get_watchlists_for_single_account(
&self,
acct_id: i64
) -> Result<String, TDAClientError>
pub fn get_watchlists_for_single_account( &self, acct_id: i64 ) -> Result<String, TDAClientError>
All watchlists of an account
Parameters
- acct_id: Account number
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/get/accounts/%7BaccountId%7D/watchlists-0
sourcepub fn get_watchlists_for_multiple_accounts(
&self
) -> Result<String, TDAClientError>
pub fn get_watchlists_for_multiple_accounts( &self ) -> Result<String, TDAClientError>
All watchlists for all of the user’s linked accounts
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/get/accounts/watchlists-0
sourcepub fn create_watchlist(
&self,
acct_id: i64,
watchlist_spec: &str
) -> Result<(), TDAClientError>
pub fn create_watchlist( &self, acct_id: i64, watchlist_spec: &str ) -> Result<(), TDAClientError>
Create watchlist for specific account. This method does not verify that the symbol or asset type are valid
Parameters
- acct_id: Account number
- watchlist_spec: Watchlist body
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/post/accounts/%7BaccountId%7D/watchlists-0
sourcepub fn replace_watchlist(
&self,
acct_id: i64,
watchlist_id: i64,
watchlist_spec: &str
) -> Result<(), TDAClientError>
pub fn replace_watchlist( &self, acct_id: i64, watchlist_id: i64, watchlist_spec: &str ) -> Result<(), TDAClientError>
Replace watchlist for a specific account. This method does not verify that the symbol or asset type are valid
Parameters
- acct_id: Account number
- watchlist_id: Watchlist number
- watchlist_spec: Watchlist body
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/put/accounts/%7BaccountId%7D/watchlists/%7BwatchlistId%7D-0
sourcepub fn update_watchlist(
&self,
acct_id: i64,
watchlist_id: i64,
watchlist_spec: &str
) -> Result<(), TDAClientError>
pub fn update_watchlist( &self, acct_id: i64, watchlist_id: i64, watchlist_spec: &str ) -> Result<(), TDAClientError>
Partially update watchlist for a specific account: change watchlist name, add to the beginning/end of a watchlist, update or delete items in a watchlist. This method does not verify that the symbol or asset type are valid
Parameters
- acct_id: Account number
- watchlist_id: Watchlist number
- watchlist_spec: Watchlist body
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/patch/accounts/%7BaccountId%7D/watchlists/%7BwatchlistId%7D-0
sourcepub fn delete_watchlist(
&self,
acct_id: i64,
watchlist_id: i64
) -> Result<(), TDAClientError>
pub fn delete_watchlist( &self, acct_id: i64, watchlist_id: i64 ) -> Result<(), TDAClientError>
Delete watchlist for a specific account
Parameters
- acct_id: Account number
- watchlist_id: Watchlist number
Official Documentation: https://developer.tdameritrade.com/watchlist/apis/delete/accounts/%7BaccountId%7D/watchlists/%7BwatchlistId%7D-0