简体   繁体   中英

Using IBrokers for option trading

I can place a stock trade on Interactive Brokers using R (using IBrokers API ), however I can not do it for option trading .

I'm posting my sample code here, maybe someone in the community can help.

library('IBrokers')

tws <- twsConnect(port=7497)

orderid = reqIds( tws, numIds=1)
neworder = twsOrder( orderid, action='BUY', totalQuantity='4', orderType='LMT', lmtPrice='.1')
opt <- twsOption("AAPL",expiry="281707", strike="10.0", right="C")
placeOrder( tws, opt, neworder )

twsDisconnect(tws)

You haven't written the correct expiration date, you should try:

opt <- twsOption("AAPL", expiry="20180315", strike="170", right="C")

the format is yyyymmdd .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM