-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live updating dataframe #9
Comments
Here's a very quick idea on how to keep historical dataframes up to date. library(rib)
# derive a new wrapper with customized historicalData() and historicalDataUpdate()
IBWrapTest <- R6::R6Class("IBWrapTest",
inherit= IBWrapSimple,
public= list(
initialize= function()
# list holding the data.frames
self$context$dflist <- list(),
historicalData= function(reqId, bar)
# store initial history
self$context$dflist[[reqId]] <- bar,
historicalDataUpdate= function(reqId, bar) {
df <- self$context$dflist[[reqId]]
n <- nrow(df)
if(bar$time == df$time[n])
# update the last bar
self$context$dflist[[reqId]][n, ] <- bar
else
# bar has changed, append a new one
self$context$dflist[[reqId]] <- rbind(df, bar)
}
)
)
wrap <- IBWrapTest$new()
ic <- IBClient$new(wrap)
ic$connect(port=7497, clientId=5)
tickers <- c("AAPL", "GOOG")
for(i in 1:length(tickers))
ic$reqHistoricalData(i, IBContract(tickers[i]), "", "1 D", "5 mins", "TRADES", TRUE, 1, TRUE)
repeat {
# keep history up-to-date
ic$checkMsg()
# do something with it
wrap$context$dflist[[1]] # AAPL
wrap$context$dflist[[2]] # GOOG
} |
@lbilli many thanks - I see the logic, and makes sense to me. I ran into the following error - any further guidance you can provide me?
|
It's difficult to say from here. |
Many thanks again @lbilli - data download and updating works like a charm. One further question I may ask is how do you place orders in the I did the following, namely inserted the calls to What I ultimately want to do is pull in the
|
As per IB API documentation, each new Upon connection, the server always responds with wrap <- IBWrapTest$new()
ic <- IBClient$new(wrap)
ic$connect(port=7497, clientId=5)
# wait to make sure you receive all initial messages
Sys.sleep(1)
ic$checkMsg()
orderId <- wrap$context$nextId
[...]
# send first order
ic$placeOrder(orderId, contract1, order1)
orderId <- orderId + 1
[...]
# send another order
ic$placeOrder(orderId, contract2, order2)
orderId <- orderId + 1
[...] |
Hello, I have the following code that I am using to stream data, and hopefully create a live updating plot in R.
Can you please guide me on how I can export the
wrap$context$historical
field into a R dataframe that is steadily updated as the streamed data comes through?The text was updated successfully, but these errors were encountered: