-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIBrokersFunction_v2.R
More file actions
36 lines (31 loc) · 1.48 KB
/
IBrokersFunction_v2.R
File metadata and controls
36 lines (31 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
if(!existsFunction("twsConnect")){# this makes for better code handling
library(IBrokers)
tws <- twsConnect()
}
#Pull equity prices "after hours (AH)" using reqHistoricalData function.
IB.EQ.1day.AH <- function(Connection=tws, ticker='?') {
equity.contract <- twsEquity(ticker)
equity.hist.price <- reqHistoricalData(Connection,
equity.contract,
whatToShow = "BID_ASK",
barSize = "1 day",
duration ="1 Y"
)
#Sys.sleep(10)
# mandatory 10s between request to avoid IB pacing violation see the following link for more info
#http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/api/historical_data_limitations.htm
return(equity.hist.price)
}
IB.EQ.1min.AH <- function(Connection=tws, ticker='?') {
equity.contract <- twsEquity(ticker)
equity.hist.price <- reqHistoricalData(Connection,
equity.contract,
whatToShow = "BID_ASK",
barSize = "1 min",
duration ="1 D"
)
#Sys.sleep(10)
# mandatory 10s between request to avoid IB pacing violation see the following link for more info
#http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/api/historical_data_limitations.htm
return(equity.hist.price)
}