[R-SIG-Finance] IBrokers R package: issue with class twsconn (R)

Jeffrey Ryan jeffrey.ryan at lemnica.com
Fri Mar 25 19:18:33 CET 2011


Hi Johnny,

Not a fan of S4 or Stack Overflow, so thanks for posting here!

The issue is S3 in S4.  This should work:

setOldClass("twsconn")  # this is what you are missing
setClass( "MktAsset",
  representation( IB.id = "character",
                          asset.type = "factor",
              ccy = "factor",
              IB.conn = "twsconn") )

# [1] "MktAsset"

a <- new("MktAsset")

ibg <- ibgConnect() # connect to IB Gateway

a at IB.conn <- ibg
a

An object of class "MktAsset"
Slot "IB.id":
character(0)

Slot "asset.type":
factor(0)
Levels:

Slot "ccy":
factor(0)
Levels:

Slot "IB.conn":
<twsConnection,1 @ 20110325 13:15:22 CST, nextId=1>

If you're able to come to R/Finance in Chicago next month
www.RinFinance.com, I'll be doing a two-hour workshop on Friday
morning regarding IBrokers (and algorithmic trading in general with R)
that would be of interest I suspect.

Best,
Jeff



On Fri, Mar 25, 2011 at 12:40 PM, Johnny Paulo <johnny.jp.22 at gmail.com> wrote:
> Hello,
>
> At the moment, I am switching from Python to R and I am trying to write some
> simple code to price a portfolio, using Jeff Ryan's Ibrokers package. I
> would like to have a field of class twsconn in one of my objects
>
> setClass( "MktAsset",
>  representation( IB.id = "character",
>                          asset.type = "factor",
>              ccy = "factor",
>              IB.conn = "twsconn") )
>
> but the system does not seem happy about it
>
> Msg is
>
> In .completeClassSlots(ClassDef, where) : undefined slot classes in
> definition of "MktAsset": IB.connection(class "twsconn")
>
> but when I ask the class of tws (initialized with tws <- twsConnect(), it
> returns
>
> [1] "twsconn" "environment"
>
> I tried to go through the code to check for the existence of a class twsconn
> but, I found nothing.
>
> Can someone help?
>
> Thanks a lot
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan at lemnica.com

www.lemnica.com

R/Finance 2011 April 29th and 30th in Chicago | www.RinFinance.com



More information about the R-SIG-Finance mailing list