reqMktData(tws,twsOPT("AAPL 110820C00390000"))或
reqMktData(tws,twsOPT("AAPL110820C00390000"))结果: TWS消息:2 1 200未找到请求的安全定义
为什么?
reqMktData(tws,twsSTK("AAPL"))工作正常。
手册页上写着:
twsOption(local,
expiry="",
strike="",
right="",
exch="SMART",
primary="",
currency='USD',
symbol='',
multiplier="100",
include_expired='0',
conId=0)TWS上的期权合约具有与标准数据请求不同的某些规则。
本地符号是必需的。这可以在合同详细信息下的TWS主屏幕上找到,也可以通过网站www.interactivebrokers.com找到
由于本地符号是必需的,因此所有其他值都是多余的。最好是简单地指定本地名称,让TWS管理查找。
发布于 2011-08-17 22:25:06
您没有获得正确的本地设置。正确的格式使用6个字符宽的字段(OSI规范),您分别尝试使用5和4。
当然,您不需要使用local,但这需要跨不同arg的更多细节。
> reqContractDetails(ibg, twsOPT("AAPL 110820C00390000"))
[[1]]
List of 18
$ version : chr "6"
$ contract :List of 16
..$ conId : chr "86896934"
..$ symbol : chr "AAPL"
..$ sectype : chr "OPT"
..$ exch : chr "SMART"
..$ primary : chr ""
..$ expiry : chr "20110819"
..$ strike : chr "390.0"
..$ currency : chr "USD"
..$ right : chr "C"
..$ local : chr "AAPL 110820C00390000"
..$ multiplier : chr "100"
..$ combo_legs_desc: chr ""
..$ comboleg : chr ""
..$ include_expired: chr ""
..$ secIdType : chr ""
..$ secId : chr ""
..- attr(*, "class")= chr "twsContract"
$ marketName : chr "AAPL"
$ tradingClass : chr "AAPL"
$ conId : chr "86896934"
$ minTick : chr "0.01"
$ orderTypes : chr [1:44] "ACTIVETIM" "ADJUST" "ALERT" "ALGO" ...
$ validExchanges: chr [1:12] "SMART" "AMEX" "BATS" "BOX" ...
$ priceMagnifier: chr "1"
$ underConId : chr "265598"
$ longName : chr "APPLE INC"
$ contractMonth : chr "201108"
$ industry : chr "Technology"
$ category : chr "Computers"
$ subcategory : chr "Computers"
$ timeZoneId : chr "EST"
$ tradingHours : chr "20110817:0930-1600;20110818:0930-1600"
$ liquidHours : chr "20110817:0930-1600;20110818:0930-1600"您可以使用as.twsContract提取合同:
as.twsContract(reqContractDetails(ibg, twsOPT("AAPL 110820C00390000")))或者直接调用reqMktData请求:
reqMktData(ibg, twsOPT("AAPL 110820C00390000"))
## OR
reqMktData(ibg, twsOPT("",symbol="AAPL",right="C", strike="390", expiry="201108"))发布于 2011-09-28 05:31:26
通过使用twsInstrument包on R-Forge,可以避免这些类型的问题
library(twsInstrument)它们中的任何一个都将获得twsContract
getContract("AAPL 111217P00390000")
getContract("AAPL 111217P00390000") #number of spaces does not matter
getContract("AAPL20111217P00390000") #year can be 4 digits or 2
getContract("AAPL_111217P00390000")
getContract("AAPL111217P00390000")
getContract("AAPL111217P390")
getContract("AAPL_111217P390")
getContract("AAPL_20111217P390")
getContract("AAPL_111217P390.00")
#by conId
getContract("93189601")
getContract(93189601) 所有这些都会给你提供相同的东西:
> getContract(93189601)
List of 16
$ conId : chr "93189601"
$ symbol : chr "AAPL"
$ sectype : chr "OPT"
$ exch : chr "SMART"
$ primary : chr ""
$ expiry : chr "20111216"
$ strike : chr "390"
$ currency : chr "USD"
$ right : chr "P"
$ local : chr "AAPL 111217P00390000"
$ multiplier : chr "100"
$ combo_legs_desc: chr ""
$ comboleg : chr ""
$ include_expired: chr ""
$ secIdType : chr ""
$ secId : chr ""遗憾的是,您无法获取已过期的选项的合同详细信息。我不知道这是不是IBrokers的问题,或者是Interactive Broker不支持它,但获取已经到期的期货的合约详细信息没有问题
> getContract("ESM1")
Connected with clientId 100.
Trying to resolve error in contract details. Using include_expired=1
Contract details request complete. Disconnected.
List of 16
$ conId : chr "73462897"
$ symbol : chr "ES"
$ sectype : chr "FUT"
$ exch : chr "GLOBEX"
$ primary : chr ""
$ expiry : chr "20110617"
$ strike : chr "0"
$ currency : chr "USD"
$ right : chr ""
$ local : chr "ESM1"
$ multiplier : chr "50"
$ combo_legs_desc: chr ""
$ comboleg : chr ""
$ include_expired: chr "1"
$ secIdType : chr ""
$ secId : chr ""https://stackoverflow.com/questions/7087776
复制相似问题