使用IBrokers包的问题

使用IBrokers包的问题,r,finance,ibrokers,R,Finance,Ibrokers,我试图用最简单的代码使用IBrokers包,如下所示: library(IBrokers) tws <- twsConnect() aapl.csv <- file("AAPL.csv", open="wa") # run an infinite-loop ( <C-c> to break ) reqMktData(tws, twsSTK("AAPL"), eventWrapper=eWrapper.MktData.CSV(1),

我试图用最简单的代码使用IBrokers包,如下所示:

library(IBrokers)

tws <- twsConnect()

aapl.csv <- file("AAPL.csv", open="wa")

# run an infinite-loop ( <C-c> to break )
reqMktData(tws, twsSTK("AAPL"), 
        eventWrapper=eWrapper.MktData.CSV(1), 
        file=aapl.csv)

close(aapl.csv)
close(tws)
一切都挂了

整个日志如下:

R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)

> library(IBrokers)
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following object(s) are masked from 'package:base':

    as.Date, as.Date.numeric

IBrokers version 0.9-3:
Implementing API Version 9.64
This software comes with NO WARRANTY.  Not intended for production use!
See ?IBrokers for details
Warning messages:
1: package 'IBrokers' was built under R version 2.13.2
2: package 'xts' was built under R version 2.13.2
3: package 'zoo' was built under R version 2.13.2
>
> tws <- twsConnect()
>
> aapl.csv <- file("AAPL.csv", open="a")
>
> # run an infinite-loop ( <C-c> to break )
> reqMktData(tws, twsSTK("AAPL"),
+         eventWrapper=eWrapper.MktData.CSV(1),
+         file=aapl.csv)
2 -1 2104 Market data farm connection is OK:cashfarm
2 -1 2104 Market data farm connection is OK:usfarm
2 -1 2106 HMDS data farm connection is OK:ushmds2a
2 1 321 Error validating request:-'oc' : cause - Incorrect generic tick list of 100,101,104,106,165,221,225,236.  Legal ones for (STK) are: 100(Option Volume),101(Option Open Interest),104(Historical Volatility),105(Average Opt Volume),106(Option Implied Volatility),107(Close Implied Volatility),125(Bond analytic data),165(Misc. Stats),166(CScreen),225(Auction),233(RTVolume),236(inventory),258/47(Fundamentals),291(Close Implied Volatility),293(TradeCount),294(TradeRate),295(VolumeRate),318(LastRTHTrade),370(ParticipationMonitor),370(ParticipationMonitor),377(CttTickTag),377(CttTickTag),381(IB Rate),384(RfqTickRespTag),384(RfqTickRespTag),387(DMM),388(Issuer Fundamentals),391(IBWarrantImpVolCompeteTick),407(FuturesMargins),411(Real-Time Historical Volatility)

> (Command cancelled)
>
> close(aapl.csv)
> close(tws)
R版本2.13.0(2011-04-13)
版权所有(C)2011统计计算基础
ISBN 3-900051-07-0
平台:x86_64-pc-mingw32/x64(64位)
>图书馆(IBrokers)
正在加载所需的包:xts
装载所需包裹:zoo
附上包裹:“动物园”
以下对象已从“package:base”屏蔽:
as.Date,as.Date.numeric
IBrokers版本0.9-3:
实现API版本9.64
此软件不提供保修。不用于生产用途!
有关详细信息,请参见IBrokers
警告信息:
1:包“IBrokers”是在R版本2.13.2下构建的
2:包“xts”是在R版本2.13.2下构建的
3:软件包“zoo”是在R版本2.13.2下构建的
>
>tws
>aapl.csv
>#运行无限循环(中断)
>需求数据(tws、twsSTK(“AAPL”),
+eventWrapper=eWrapper.MktData.CSV(1),
+文件=aapl.csv)
2-1 2104市场数据场连接正常:现金场
2-1 2104市场数据场连接正常:usfarm
2-1 2106 HMDS数据场连接正常:ushmds2a
2 1 321验证请求时出错:-“oc”:原因-100101104106165221225236的通用勾号列表不正确。STK的法定交易量为:100(期权成交量)、101(期权未平仓)、104(历史波动率)、105(期权平均成交量)、106(期权隐含波动率)、107(收盘隐含波动率)、125(债券分析数据)、165(杂项统计数据)、166(CScreen)、225(拍卖)、233(实时成交量)、236(存货)、258/47(基本面)、291(收盘隐含波动率)、293(交易计数)、294(交易利率)、295(交易量)、318(最新交易)、370(参与监控)、370(参与监控)、377(交易量监控)、377(交易量监控)、381(IB利率)、384(交易量监控)、384(交易量监控)、387(交易量监控)、388(发行人基本面)、391(交易量监控)、407(未来市场)、411(实时历史波动率)
>(命令取消)
>
>关闭(aapl.csv)
>关闭(tws)

我在这里做错了什么?非常感谢您对解析或指向引用的指针的任何想法。

错误表明您的勾号列表不好。如果您将其与它报告的有效勾号列表进行比较,您会发现221是罪魁祸首。谢天谢地,执行
?reqMktData
告诉我们您可以使用
勾号来指定您自己的勾号列表ics
选项。所以只需执行以下操作

> reqMktData(tws, twsSTK("AAPL"), 
         eventWrapper=eWrapper.MktData.CSV(1), 
         file=aapl.csv, tickGenerics="100,101,104,106,165,225,236")

你应该很乐意去。

我个人还没有看到这个问题,而且IBGateway几乎全天候运行。根据IB的文档,它似乎是有效的。
> reqMktData(tws, twsSTK("AAPL"), 
         eventWrapper=eWrapper.MktData.CSV(1), 
         file=aapl.csv, tickGenerics="100,101,104,106,165,225,236")