[R-SIG-Finance] variable scope with ewrapper in IBrokers
Noah Silverman
noahsilverman at ucla.edu
Mon Jul 18 22:27:00 CEST 2011
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:
> 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:
>
>> On Mon, 2011-07-18 at 10:36 -0700, Noah Silverman wrote:
>>> 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?
>>
>> 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
>>
>> --
>> Brian G. Peterson
>> http://braverock.com/brian/
>> Ph: 773-459-4973
>> IM: bgpbraverock
>>
>> _______________________________________________
>> 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.
More information about the R-SIG-Finance
mailing list