Re: Ibrokers package in R - Get option prices
Hi Mark,
I've checked my? data subscriptions,? OPRA (which includes SPX) is already included. ?Do you think other data subscriptions are required for SPX?
I tried also during trading hours to avoid deferred market data but the result is the same.
Is there an alternative way to get historical option prices (specifying for example yesterday at a particular hour)??
Thanks,
Simone
toggle quoted message
Show quoted text
Il giorno ven 31 ago 2018 alle ore 12:23 mark collins <
mark.collins@... > ha scritto:
My Italian is terrible, but I think it means you are not subscribed (lit. under written) and it suggests that you activate it.
Could that be the case, that you have not subscribed or activated the necessary subscription??
Someone with better Italian will probably be able to help more
M
Hi everyone,
?
I'm trying to get SPX put option prices for a given strike and expiration using the IBrokers package in R.
T
he final aim is to fill an option price chain from IB. Not necessarily with the latest option prices available, but also with bid/ask prices for a given date/hour would be useful. I'm using the following code:
?
require ( IBrokers )
tws= twsConnect ()
ticker="SPX"
exp="20181115"
k=2700
opt=twsOption(local="",symbol=ticker,expiry=exp,strike=k,right="P")
optPrice=reqMktData(tws,opt,eventWrapper=eWrapper.data.Last(1),CALLBACK=snapShot)
where the two functions eWrapper.data.Last and snapShot are below reported.
?
eWrapper.data.Last <- function ( n ) {
eW <- eWrapper ( NULL ) # use basic template
eW $ assign.Data ( "data" ,
rep ( list ( structure ( .xts ( matrix ( rep ( NA_real_ , 2 ), nc = 2 ), 0 ),
.Dimnames = list ( NULL , c ( "LastSize" , "Last" )))), n ))
eW $ tickPrice <- function ( curMsg , msg , timestamp , file , ... )
{
tickType = msg [ 3 ]
msg <- as.numeric ( msg )
id <- msg [ 2 ] #as.numeric(msg[2])
data <- eW $ get.Data ( "data" ) #[[1]] # list position of symbol (by id ==
msg [ 2 ])
attr ( data [[ id ]], "index" ) <- as.numeric ( Sys.time ())
nr.data <- NROW ( data [[ id ]])
if ( tickType == .twsTickType $ LAST ) {
data [[ id ]][ nr.data , 2 ] <- msg [ 4 ]
}
eW $ assign.Data ( "data" , data )
c ( curMsg , msg )
}
eW $ tickSize <- function ( curMsg , msg , timestamp , file , ... )
{
data <- eW $ get.Data ( "data" )
tickType = msg [ 3 ]
msg <- as.numeric ( msg )
id <- as.numeric ( msg [ 2 ])
attr ( data [[ id ]], "index" ) <- as.numeric ( Sys.time ())
nr.data <- NROW ( data [[ id ]])
if ( tickType == .twsTickType $ LAST_SIZE ) {
data [[ id ]][ nr.data , 1 ] <- msg [ 4 ]
}
eW $ assign.Data ( "data" , data )
c ( curMsg , msg )
}
return ( eW )
}
snapShot <- function ( twsCon , eWrapper , timestamp , file , playback
Are you sure you wish to delete this message from the message archives of
[email protected] ?
This cannot be undone.
Are you sure you wish to repost this message?