我正在尝试使用 R 进行一些市场分析。有没有办法使用软件包每隔一分钟获取实时股票报价?我熟悉 quantmod 并使用了 getSymbols() 函数,但是,我能够挖掘的所有数据都是 15 分钟前的。谢谢你。
2 回答
我的qmao
包有getQuote
BATS 和 google 的“方法”,它们都是近乎实时的
Sys.time()
#[1] "2014-11-19 14:27:48.727988 CST"
getQuote("SPY", src="google")
# TradeTime Last Change PctChg Exchange GoogleID
#SPY 2014-11-19 15:27:00 205.17 -0.38 -0.18 NYSEARCA 700145
getQuote("SPY", src="bats", what="bbo")
# TradeTime BidSize BidPrice AskPrice AskSize Last LastSize row.names
#1 15:27:24 15000 205.16 205.17 300 205.17 300 SPY
getQuote.bats
对于您希望如何打印数据有几个选项:
getQuote("SPY", src="bats", what="ladder")
# SPDR S&P 500 ETF TR TR UNIT
# Time: 15:27:44
# Volume: 8779553
# Last: 300 @ 205.17
#
#+-------+--------+-------+
#| | 205.21 | 16700 |
#+-------+--------+-------+
#| | 205.2 | 21900 |
#+-------+--------+-------+
#| | 205.19 | 17300 |
#+-------+--------+-------+
#| | 205.18 | 5572 |
#+-------+--------+-------+
#| | 205.17 | 300 |
#+-------+--------+-------+
#| 15000 | 205.16 | |
#+-------+--------+-------+
#| 12100 | 205.15 | |
#+-------+--------+-------+
#| 11300 | 205.14 | |
#+-------+--------+-------+
#| 23900 | 205.13 | |
#+-------+--------+-------+
#| 10600 | 205.12 | |
#+-------+--------+-------+
getQuote("SPY", src="bats", what="depth")
#
#
# BidQty BidPrice AskPrice AskQty
#-------- ---------- ---------- --------
# 15000 205.16 205.17 300
# 12100 205.15 205.18 5572
# 11300 205.14 205.19 17300
# 23900 205.13 205.2 21900
# 10600 205.12 205.21 16700
还有绘图方法
plot(getQuote("SPY", src="bats"))
plot(getQuote("SPY", src="bats", what="ladder"))
plot(getQuote("SPY", src="bats", what="depth"))
而且,如果您仍在阅读,包中包含一个闪亮的应用程序,因此您可以实时更新这些“情节”。运行这个:
shinyBATS()
IB would probably be best for real-time stock data. You won't need to pay for it (*), but last time I looked you will need to open an account with a minimum amount of real money.
There is an R package: http://cran.r-project.org/web/packages/IBrokers/index.html
There is a vignette on getting real-time data, but it was last updated in 2009, so I would go with the general vignette: http://cran.r-project.org/web/packages/IBrokers/vignettes/IBrokers.pdf which was last update sep 2014.
(*: Not strictly true: for some exchanges you will need to pay an extra exchange fee.)