lbilli / rib

An R implementation of Interactive Brokers API
GNU General Public License v3.0
34 stars 7 forks source link

Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument #23

Open domvoe opened 1 year ago

domvoe commented 1 year ago

Many thanks sharing this package.

I already use it a while and randomly get the follwing error: Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument

The strange thing ist that this error is showing up randomly, i.e. when I run the same code 10 times in a row it can be that no error is showing up, but the next time each other request is showing the error.

Do you have an idea how this can happen? Your help is really appreciated.

Here is an example code snippet with reponse from the console:

library(rib) wrap <- IBWrapSimple$new() ic <- IBClient$new() ic$connect(port=7500, clientId=1) contract <- IBContract(symbol="GOOG", secType="STK", exchange="SMART", currency="USD") ic$reqContractDetails(11, contract) ic$checkMsg(wrap) Error in readBin(private$socket, raw(), n = len) : invalid 'n' argument

lbilli commented 1 year ago

Difficult to say without a way to reproduce. Here are some thoughts that first come to mind:

If reporting back, additional information can be useful such as OS, TWS version, rib version and any other error messages.

domvoe commented 1 year ago

Thanks a lot for your fast reply.

The last days I tested the TWS option which was referenced in the first bullet point. The system is now running more stable, but sometimes the error is still popping up.

I use Windows and the recent versions of TWS (10.20) and rib (0.19). The random behaviour makes the debugging hard. But I will still try and let you know in case I find something relevant.

Again many thanks for your help.

AndrewEndl commented 1 year ago

I used to get this error when I tried to open a connection via ic$connect that was already open (e.g. had not been properly closed earlier) with the same parameters (clientId, port)