softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

-1 507 Bad Message Length null #98

Closed llagoudis closed 4 years ago

llagoudis commented 4 years ago

Hi,

I am using a demo IB account TWS API 979.01 OS Win10 x64 amd MatlabR2019a.

At TWS 'Enable ActiveX and Socket Client' is enable Trusted IPs created a new at 127.0.0.1

I just get started with IB connection and I have some difficulties to get connection.

`clc; clear all; addpath(path,pwd);
addpath(path,fullfile(pwd,'docs')) javaaddpath(fullfile(pwd,'Jar','TWS973.jar'));

AccountSummaryExample`

I am getting this error message :

notification listener has been removed added interface method: TWSNotification notification listener has been added -1 507 Bad Message Length null

Error using AccountSummaryExample (line 56) Java exception occurred: org.apache.commons.collections.BufferUnderflowException: The buffer is already empty

at org.apache.commons.collections.buffer.BoundedFifoBuffer.get(BoundedFifoBuffer.java:261)

Could you please advice what I am doing wrong?

Thanks

softwarespartan commented 4 years ago

Thanks for opening an issue. This is just the java way to say "buffer was empty". Whenbuf.size is zero (i.e. empty) and if call buf.get() on empty buf, then java throws exception. Probably just need to wait longer for response from TWS server. But, I am not totally sure how account summary works for demo accounts.

llagoudis commented 4 years ago

Thank you for your help. Why I am getting empty buffer? I have run a few examples from the docs library and I am facing the error 1 507 Bad Message Length null

In addition, why there are different contract configurations in docs vs examples docs : contract.symbol('IBM'); examples : contract.m_symbol='IBM';

softwarespartan commented 4 years ago

Empyt buf just means no events have been received from TWS. Depending on your internet speed, geography, etc, might take longer to get response from TWS servers.

Are you sure that you're adding the jar file that comes with IB4m? Also there is conflict with IB jar that comes with the Matlab Trading Toolbox so be sure not to have that installed.

I'm a bit delinquent in updating the examples for the +973 API changes. Docs should be up to date though.

Official IB docs are updated and can be used directly.

http://interactivebrokers.github.io/tws-api/basic_contracts.html

Not sure on bad msg length. I have never tested with demo account.

llagoudis commented 4 years ago

Hi,

I installed Trading Toolbox for MatlabR2019a. Where can I find this Java jar file? Do I need to delete it?

Jar file is added into path I have later on saved. see picture below

[cid:a0b37a7f-fe01-450e-9dc6-e24514079303]


From: Abel Brown notifications@github.com Sent: 25 April 2020 16:49 To: softwarespartan/IB4m IB4m@noreply.github.com Cc: llagoudis llagoudis@hotmail.co.uk; Author author@noreply.github.com Subject: Re: [softwarespartan/IB4m] -1 507 Bad Message Length null (#98)

Empyt buf just means no events have been received from TWS. Depending on your internet speed, geography, etc, might take longer to get response from TWS servers.

Are you sure that you're adding the jar file that comes with IB4m? Also there is conflict with IB jar that comes with the Matlab Trading Toolbox so be sure not to have that installed.

I'm a bit delinquent in updating the examples for the +973 API changes. Docs should be up to date though.

Official IB docs are updated and can be used directly.

http://interactivebrokers.github.io/tws-api/basic_contracts.html

Not sure on bad msg length. I have never tested with demo account.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/softwarespartan/IB4m/issues/98#issuecomment-619399352, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB2N3BOXHRA76FNASPLGSGDROMBBZANCNFSM4MQMLOCQ.

softwarespartan commented 4 years ago

I am not exactly sure where Matlab puts the Trading Toolbox jar (you could use Terminal to find it in the Applications dir for 2019a). Long story short, if want to use IB4m then need to uninstall the trading toolbox to stop the conflicting jar file from getting added to the class loader path. I realize it's a bit obnoxious to uninstall the toolbox.

llagoudis commented 4 years ago

Hi,

There many examples on the docs folder but what I am looking for is an end to end example like check portfolio positions and submit an order when a condition is met and then repeat the same check in 1 hour.

softwarespartan commented 4 years ago

There are examples for both account updates and portfolio updates in the docs folder. Also, be sure to checkout the IB API docs

http://interactivebrokers.github.io/tws-api/account_portfolio.html

And, Matlab has timer callbacks as well

https://www.mathworks.com/help/matlab/matlab_prog/timer-callback-functions.html

p.s. since this question/issue is not related to " Bad Message Length null", should probably open new/separate issue. Im going to close this issue but feel free to respond if you think topic is better discussed on this thread.