Closed YuriWerewolf closed 1 year ago
Thanks for the report.
Though a bit cryptic, the meaning of the warnings is that the wrap
provided doesn't contain customized methods to handle certain responses, which in this case are related to existing pending orders in TWS.
I'm guessing that you used the very first example in README to define wrap
. That's rather a barebone self contained template that the user is supposed to customize in order to fit their needs.
I'd suggest to try again with this wrap
definition instead:
wrap <- IBWrapSimple$new()
which handles many responses by simply printing out or storing in wrap$context
their content.
You can look at IBWrapSimple
's implementation as a template to write your own.
Yes, you are correct. Works with IBWrapSimple and I will look into extending this class definition.
Is the only way to write it inside the main code I guess?
In the installed 'rib' package folder I only see .rdb and .rdx files, no source files.
You can look at the code right here on Github or clone the repo on your disk, no reason to mess with the installed package.
IBWrapSimple
is defined here.
Once you get the feeling of it, just add in your own project something along these lines:
MyCustomWrap <- R6::R6Class("MyCustomWrap",
class= FALSE,
cloneable= FALSE,
lock_class= TRUE,
inherit= IBWrap,
# And the customized method you need: e.g.
error= function(id, errorCode, errorString, advancedOrderRejectJson)
cat("Error:", id, errorCode, errorString, advancedOrderRejectJson, "\n"),
nextValidId= function(orderId)
cat("Next OrderId:", orderId, "\n"),
managedAccounts= function(accountsList)
cat("Managed Accounts:", accountsList, "\n"),
contractDetails= ...,
orderStatus= ...,
openOrder= ...,
# etc
)
)
A class like this, i.e. derived from IBWrap
, is a prerequisite in order to instantiate an IBClient
.
Later on you'll have:
wrap <- MyCustomWrap$new()
ic <- IBClient$new(wrap)
ic$connect(...)
# etc
When responses from TWS are processed, the appropriate function defined in MyCustomWrap
is invoked.
If such a function has not been provided inMyCustomWrap
, the warning "default implementation"
is issued.
That's how I will proceed from here. Thanks for the replies, very useful.
I get warnings when sending requests/receiving messages when using your example/other requests:
I have checked Decoder class but still not sure what's wrong, just getting 'default implementation' message...
Just to clarify, the client does get connected and I get responses from the TWS: