IBrokers 要求历史期货合约数据?
我试图请求历史期货数据,但对于初学者来说,ibrokers.pdf 文档的记录不够充分。 例如 Gold Miny 合约 Dec11 NYSELIFFE:
goldminy<-twsFuture("YG","NYSELIFFE","201112",multiplier="33.2")
reqHistoricalData(conn,
Contract= "goldminy",
endDateTime"",
barSize = "1 S",
duration = "1 D",
useRTH = "0",
whatToShow = "TRADES","BID", "ASK", "BID_ASK",
timeFormat = "1",
tzone = "",
verbose = TRUE,
tickerId = "1",
eventHistoricalData,
file)
我也不知道如何正确指定一些数据参数?
显示什么?我需要日期、时间、出价、出价、询问、询问尺寸、最后、最后尺寸、交易量
tickerID ?
事件历史数据?
文件 ?
I tried to request historical futures data but for a beginner the ibrokers.pdf document is not well enough documented.
example Gold Miny Contract Dec11 NYSELIFFE:
goldminy<-twsFuture("YG","NYSELIFFE","201112",multiplier="33.2")
reqHistoricalData(conn,
Contract= "goldminy",
endDateTime"",
barSize = "1 S",
duration = "1 D",
useRTH = "0",
whatToShow = "TRADES","BID", "ASK", "BID_ASK",
timeFormat = "1",
tzone = "",
verbose = TRUE,
tickerId = "1",
eventHistoricalData,
file)
I also don't know how to specify some of the data parameters correctly ?
whatToShow ? i need Date,Time,BidSize,Bid,Ask,AskSize,Last,LastSize,Volume
tickerID ?
eventHistoricalData ?
file ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我编写了 twsInstrument 包(在 RForge 上)来缓解这些问题头痛。
如果您提供任何合理的信息,getContract 将为您找到合同。这些格式中的任何一种都应该有效:
“YG_Z1”、“YG_Z11”、“YGZ1”、“YGZ11”、“YGZ2011”、“YGDEC2011”、“YG_DEC2011”等
(您也可以使用 conId,或给它一个仪器对象,或者工具对象的名称)
我没有订阅 NYSELIFFE 的市场数据,因此我将使用 Dec 2011 年 e-mini S&P 未来为本答案的其余部分。
您可以获取这样的历史数据
这将为您返回这些列,并且全部都是“TRADES”数据,
whatToShow 必须是“TRADES”、“BID”、“ASK”或“其中之一”出价_问价'。如果您的请求使用whatToShow='BID',那么您将获得 BID 价格的 OHLC 等。 “BID_ASK”表示卖价将用于最高价,买价将用于最低价。
既然您说这个小插图太高级了,那么值得重复的是,盈透证券将历史数据请求限制为每 60 秒 6 次。因此,您应该在每个请求之间暂停 10 秒(或者为了获取大量数据,我通常在发出 3 个请求后暂停 30 秒,这样如果我有某个东西的 BID 数据,我也可能有它的 ASK 数据)
函数 getBAT将下载 BID、ASK 和 TRADES 数据,并仅将这些数据的收盘值合并到单个 xts 对象中,如下所示:
您要求提供 LastSize 和 Volume。 getBAT 返回的“交易量”是柱线时间内的交易总量。因此,对于 1 分钟柱,它是该 1 分钟内发生的总交易量。
这是不使用 twsInstrument 的答案:
我几乎可以肯定这会起作用,但正如我所说,我没有所需的市场数据订阅,所以我无法测试。
再次使用 e-mini S&P:
您尝试的问题之一是,如果您使用的 barSize 为“1 S”,则您的持续时间不能大于“60 S”,请参阅 IB历史数据限制
I wrote the twsInstrument package (on RForge) to alleviate these sorts of headaches.
getContract will find the contract for you if you give it anything reasonable. Any of these formats should work:
"YG_Z1", "YG_Z11", "YGZ1", "YGZ11", "YGZ2011", "YGDEC2011", "YG_DEC2011", etc.
(also you could use the conId, or give it an instrument object, or the name of an instrument object)
I don't have a subscription to market data for NYSELIFFE, so I will use the Dec 2011 e-mini S&P future for the rest of this answer.
You could get historical data like this
This will give you back these columns, and it will all be 'TRADES' data
whatToShow must be one of 'TRADES', 'BID', 'ASK', or 'BID_ASK'. If your request uses whatToShow='BID' then you will get the OHLC etc. of the BID prices. "BID_ASK" means that the Ask price will be used for the High and the Bid price will be used for the Low.
Since you said the vignette was too advanced, it bears repeating that Interactive Brokers limits historical data requests to 6 every 60 seconds. So you should pause for 10 seconds between each request (or for getting lots of data I usually pause for 30 seconds after I make 3 requests so that if I have BID data for something I am also likely have ASK data for it)
The function getBAT will download the BID, ASK and TRADES data, and merge together only the closing values of those into a single xts object that looks like this:
You asked for both LastSize and Volume. The "Volume" that getBAT returns is the total amount traded over the time of the bar. So, with 1 minute bars, it's the total volume that took place in that 1 minute.
Here's an answer that doesn't use twsInstrument:
I'm almost certain this will work, but as I said, I don't have the required market data subscription, so I can't test.
Using the e-mini S&P again:
One of the problems with your attempt is that if you're using a barSize of '1 S', your duration cannot be greater than '60 S' See IB Historical Data Limitations