# NOT RUN {
# Get stored refresh token
refreshToken = readRDS('/secure/location/')
# generate a new access token
accessToken = td_auth_accessToken(refreshToken, 'consumerKey')
# Set Account Number
accountNumber = 1234567890
# Standard market buy order
# Every order must have at least these 4 paramters
td_placeOrder(accountNumber = accountNumber,
ticker = 'AAPL',
quantity = 1,
instruction = 'buy')
# Stop limit order - good until canceled
td_placeOrder(accountNumber = accountNumber,
ticker = 'AAPL',
quantity = 1,
instruction = 'sell',
duration = 'good_till_cancel',
orderType = 'stop_limit',
limitPrice = 98,
stopPrice = 100)
# Trailing Stop Order
td_placeOrder(accountNumber = accountNumber,
ticker='AAPL',
quantity = 1,
instruction='sell',
orderType = 'trailing_stop',
stopPriceBasis = 'BID',
stopPriceType = 'percent',
stopPriceOffset = 10)
# Option Order with a limit price
td_placeOrder(accountNumber = accountNumber,
ticker = 'SLV_091820P24.5',
quantity = 1,
instruction = 'BUY_TO_OPEN',
duration = 'Day',
orderType = 'LIMIT',
limitPrice = .02,
assetType = 'OPTION')
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab