Skip to content

variable scope with ewrapper in IBrokers

4 messages · Brian G. Peterson, Jeff Ryan, Noah Silverman

#
Hello,

I'm looking at the iBrokers package.

The documentation has a nice example about copying and then modifying the ewrapper function to handle incoming data.  This works nicely.

My challenge is that I want to store some persistant values (update moving averages, etc.)

Since ewrapper()  is called for every tick by reqMktData(), I can't figure out the best way to keep some persistent variables.

How have other people handled this?

Thanks!


--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095
#
On Mon, 2011-07-18 at 10:36 -0700, Noah Silverman wrote:
One 'R-like' method for dealing with this would be to create an
environment to store these things in and update a variable in that
environment.

Regards,

   - Brian
#
Hi Noah,

I'll provide a complete example when I am back at my desk, but the eWrapper itself contains all you need to do this. 

Take a look t eWrapper.data for now. In effect you need to rbind incoming values to an object stored in the .Data variable. Again I'll provide more detail to this when I get back, but simply put it is trivial to accomplish once you see how it is done. 

Best,
Jeff

Jeffrey Ryan    |    Founder    |    jeffrey.ryan at lemnica.com

www.lemnica.com
On Jul 18, 2011, at 12:43 PM, "Brian G. Peterson" <brian at braverock.com> wrote:

            
#
Jeff,

I found the eWrapper methods for this.  It looks like I have to use the myWrapper$get.Data and myWrapper$set.Data

So, what I'm doing, in abbreviated form is the following:

-----------------------------------
MyWrapper <- function(curMsg, msg, timestamp, file, ... ){

# Load in the persistent vars for this round
a <- myWrapper$get.Data("a")
b <- myWrapper$get.Data("b")
c <- myWrapper$get.Data("c")

# Do a bunch of stuff


# Save the persistent vars
myWrapper$assign.Data("a", a)
myWrapper$assign.Data("b", b)
myWrapper$assign.Data("c", c)

}
----------------------------------


--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095
On Jul 18, 2011, at 11:23 AM, Jeff Ryan wrote: