softwarespartan / IB4m

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

Can't connect Matlab to TWS #153

Closed Sortospino closed 1 year ago

Sortospino commented 1 year ago

image I followed the instructions and I added the paths addpath(path,pwd); addpath(path,fullfile(pwd,'docs')) javaaddpath(fullfile(pwd,'Jar','TWS973.jar')) javaaddpath(fullfile(pwd,'Jar','tws-101201.jar'))

(no problems here) %javaaddpath(fullfile(pwd,'Jar','TWS.jar')) --reference from document

but when I do AccountSummaryExample

the prompt says:

added interface method: TWSNotification notification listener has been added -1 504 Not connected

-1 502 Couldn't connect to TWS. Confirm that "Enable ActiveX and Socket Clients" is enabled and connection port is the same as "Socket Port" on the TWS "Edit->Global Configuration...->API->Settings" menu. Live Trading ports: TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations of version 954.1 or newer: TWS: 7497; IB Gateway: 4002

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)

same if i do session.eClientSocket.eConnect('127.0.0.1',7497,0)

image

what am I doing wrongly?

Windows 10, matlab R2020a

TukanKolor commented 1 year ago

So I replaced line 45 of AccountSummaryExample with

% establish connection with TWS status = session.eClientSocket.isConnected(); if status==0 session.eClientSocket.eConnect('127.0.0.1',portNum,0); end pause(1); %let it connect before more requests

Despair2000 commented 1 year ago

@Sortospino

Take away the line javaaddpath(fullfile(pwd,'Jar','tws-101201.jar')).

You can't use both jar-files and so far I don't know if anyone has been able to connect to the TWS with the tws-101201.jar file (I at least haven't). Let us know if the problem persists afterwards.

Sortospino commented 1 year ago

addpath(path,pwd); addpath(path,fullfile(pwd,'docs')) javaaddpath(fullfile(pwd,'Jar','TWS973.jar')) javaaddpath(fullfile(pwd,'Jar','tws-101201.jar'))

(no problems here) %javaaddpath(fullfile(pwd,'Jar','TWS.jar')) --reference from document

but when I do AccountSummaryExample

seems working now! thank you!