Re: Ibrokers package in R - Get option prices
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
toggle quoted message
Show quoted text
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 = 1 , ... <span class="m_5544574937103192364gmail-pun" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; box-sizing: inherit; color: #3033
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?