I'm trying to download data from IBrokers but currently getting an error. I'm not sure how to solve it.
Note: I don't have a subscription to live quotes but I do get delayed market data.
My steps are:
security = twsSTK("AAPL")
is.twsContract(security)
1 TRUE
security_copy= twsEquity('AAPL')
reqMktData(tws,security)
Error output:
TWS Message: 2 1 162 Historical Market Data Service error message:No market data permissions for ISLAND STK TWS Message: 2 1 366 No historical data query found for ticker id:1 TWS Message: 2 1 10168 Requested market data is not subscribed. Delayed market data is not enabled
The historical data function also seems to have issues.
data_AAPL=reqHistoricalData(tws, security)
I have also tried the example in Link
IBrokersRef() # IBrokers Reference Card in PDF viewer
tws <- twsConnect() # make a new connection to the TWS
reqCurrentTime(tws) # check the server's timestamp
contract <- twsEquity('IBKR','SMART','ISLAND') # equity specification
reqHistoricalData(tws,contract) # request historical data
Result:
waiting for TWS reply on IBKR....failed. NULL Warning message: In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, :
Historical Market Data Service error message:No market data permissions for ISLAND
Based on TWS documentation ( here ) one can get delayed market data using reqMarketDataType(4).
That being said I would recommend using the ib_insync package from Ewald de Wit & Co.
Below is an code example I use to fetch delayed market data:
from ib_insync import *
util.startLoop()
ib = IB()
ib.sleep(2)
ib.connect('127.0.0.1', port=7490, clientId=12) # NB: Non default port could be 7498 on your machine by default when using TWS
ib.reqMarketDataType(4) # This line is the one that counts to get delayed data without subscription if available
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.