joshuaulrich / IBrokers

R API to Interactive Brokers Trader Workstation
65 stars 54 forks source link

How to request Delayed Market Data #18

Closed SantoshSrinivas79 closed 4 years ago

SantoshSrinivas79 commented 6 years ago

Is there a way to request delayed market data as mentioned at TWS API v9.72+: Market Data Types

I am particularly looking for setting client.reqMarketDataType(3);

Thank you!

Guceri commented 5 years ago

Does anyone have an idea of how to invoke client.reqMarketDataType(3) at the start of each connection?

Testing using delayed data and/or a demo account is not possible when the default setting for the API is to only provide quotes of products that have real time data.

Since the package was written completely in R, it is a bit hard to figure out how these messages are sent to IB (packages like JSONLite or httr aren't being used).

If anyone could at least point to the write direction, I might be able to figure this out.

SantoshSrinivas79 commented 5 years ago

I've researched this a bit and understand that IBrokers needs further development to be made compatible with the latest API. However, I was able to use reticulate to obtain data using Python and then use R for the rest of the work. I did a short post on the way I went about it here

joshuaulrich commented 4 years ago

@SantoshSrinivas79, @Guceri Sorry this took so long to address. It should work now. For example:

tws <- twsConnect()
contract <- twsEquity("SPY", "SMART", "ISLAND")
# set market data type to 'delayed'
reqMktDataType(tws, 3)
reqMktData(tws, contract)
# TWS Message: 2 1 10167 Requested market data is not subscribed. Displaying delayed market data...
# <20190921 07:50:47.416076> id=1 symbol=SPY optionHistoricalVol: 0.14558828654421344 NA
# <20190921 07:50:47.417217> id=1 symbol=SPY optionImpliedVol: 0.12686279339814402
# <20190921 07:50:47.418757> id=1 symbol=SPY averageVolume: 693983
# <20190921 07:50:47.419823> id=1 symbol=SPY 13-week High: 301.2460022
# <20190921 07:50:47.420874> id=1 symbol=SPY 13-week Low: 280.33599854
# <20190921 07:50:47.421909> id=1 symbol=SPY 26-week High: 301.2460022
# <20190921 07:50:47.422999> id=1 symbol=SPY 26-week Low: 270.2749939
# <20190921 07:50:47.423723> id=1 symbol=SPY 52-week High: 301.2460022
# <20190921 07:50:47.424098> id=1 symbol=SPY 52-week Low: 229.73199463
# <20190921 07:50:47.424424> id=1 symbol=SPY <default tickPrice>  6 1 68 297.26 1 0
# <20190921 07:50:47.424765> id=1 symbol=SPY <default string>6 1 88 1569023994
# <20190921 07:50:47.424996> id=1 symbol=SPY <default tickPrice>  6 1 72 300.67 0 0
# <20190921 07:50:47.425277> id=1 symbol=SPY <default tickPrice>  6 1 73 297.41 0 0
# <20190921 07:50:47.425530> id=1 symbol=SPY <default size> 6 1 74 1005152
# <20190921 07:50:47.425786> id=1 symbol=SPY <default tickPrice>  6 1 75 299.70 0 0
# <20190921 07:50:47.426066> id=1 symbol=SPY <default tickPrice>  6 1 76 0 0 0
# <20190921 07:50:52.304777> id=1 symbol=SPY <default tickPrice>  6 1 66 -1.00 0 -1
# <20190921 07:50:52.306079> id=1 symbol=SPY <default tickPrice>  6 1 67 -1.00 0 -1