softwarespartan / IB4m

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

buffer is already empty #40

Closed Mark91P closed 6 years ago

Mark91P commented 6 years ago

Hi! I have an issue trying to collect the historical data for the S&P500 future (I have the subscription for that). The setup went well with no issues following your guide so the code allow me to connect to the TWS smoothly. The error seems to be java related but I am really ignorant in that language. The same error happens for every examples that are in the quick start guide. I can add that sometime I get also a missing handler for historicrequestdata but it seems to be random. Could you please point to what I could have missed or did wrong? Thanks!

Matlab 2018a

CODE: ` % initialize session with TWS session = TWS.Session.getInstance();

% create local buffer for historical data events [buf,lh] = TWS.initBufferForEvent(TWS.Events.HISTORICALDATA);

% connect to TWS session.eClientSocket.eConnect('127.0.0.1',7496,0);

% create an empty stock contract contract = com.tws.ContractFactory.GenericStockContract('ESZ8');

% request historical data for our contract for a year w/ 1-day bars session.eClientSocket.reqHistoricalData(1000001,contract,'20141230 16:00:00','1 Y','1 day','TRADES',1,1,[]); pause(0.5);

hde = buf.get();`

ERROR: Java exception occurred: org.apache.commons.collections.BufferUnderflowException: The buffer is already empty at org.apache.commons.collections.buffer.BoundedFifoBuffer.get(BoundedFifoBuffer.java:261)

softwarespartan commented 6 years ago

Thanks for reaching out.

It just means your buffer is empty. Calling ‘get’ on an empty buffer throws an exception.

I was just lazy in the docs. Much better is something like

hde = []; if buf.size ~=0; hde = buf.get(); end

Sometimes can take a while for TWS to respond so maybe wait with ‘pause(nsec)’. Although this is still a bit crude. Better to do things like

while(buf.size()==0); pause(0.1); end

Although this can wait forever so even better to do things like

ix = 0; while(buf.size() ==0 && ix < 1000); ix = ix=1; pause(0.1); end

Don't hesitate to reach out if you need anything additional.

Cheers -abel

On Oct 3, 2018, at 10:52 AM, Mark91P notifications@github.com wrote:

Hi! I have an issue trying to collect the historical data for the S&P500 future (I have the subscription for that). The setup went well with no issues following your guide so the code allow me to connect to the TWS smoothly. The error seems to be java related but I am really ignorant in that language. The same error happens for every examples that are in the quick start guide. I can add that sometime I get also a missing handler for historicrequestdata but it seems to be random. Could you please point to what I could have missed or did wrong? Thanks!

Matlab 2018a

CODE: ` % initialize session with TWS session = TWS.Session.getInstance();

% create local buffer for historical data events [buf,lh] = TWS.initBufferForEvent(TWS.Events.HISTORICALDATA);

% connect to TWS session.eClientSocket.eConnect('127.0.0.1',7496,0);

% create an empty stock contract contract = com.tws.ContractFactory.GenericStockContract('ESZ8');

% request historical data for our contract for a year w/ 1-day bars session.eClientSocket.reqHistoricalData(1000001,contract,'20141230 16:00:00','1 Y','1 day','TRADES',1,1,[]); pause(0.5);

hde = buf.get();`

ERROR: Java exception occurred: org.apache.commons.collections.BufferUnderflowException: The buffer is already empty at org.apache.commons.collections.buffer.BoundedFifoBuffer.get(BoundedFifoBuffer.java:261)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/40, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1MT4SgJD9GtFjw8Acq8Ydv54Hj1Jks5uhM82gaJpZM4XGNIZ.

Mark91P commented 6 years ago

Thanks for the fast reply! Unfortunately I have already tried the "wait more" approach but doesn't matter at all.

For the historical data error I get the following Matlab error: No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

I find it weird because in the Java API site reqHistoricalData is clearly mentioned.

Thanks again, Marco

softwarespartan commented 6 years ago

OK, can you run the example for historical data request?

-abel

On Oct 3, 2018, at 11:49 AM, Mark91P notifications@github.com wrote:

Thanks for the fast reply! Unfortunately I have already tried the "wait more" approach but doesn't matter at all.

For the historical data error I get the following Matlab error: No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

I find it weird because in the Java API site reqHistoricalData is clearly mentioned.

Thanks again, Marco

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/40#issuecomment-426688628, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1NAnahBs4_6tPw8L2kRpXWN6KcHnks5uhNxtgaJpZM4XGNIZ.

Mark91P commented 6 years ago

Sorry for the late reply. The issue is for the example for historical data request. I have not modified the code in any way. I have tested that in MacOSx and windows 10 home edition. Matlab is in both computers 2018a. Thank you again

softwarespartan commented 6 years ago

Hi Mark

Are you able to run the historical data example provided in IB4m?

Thanks -abel

On Oct 17, 2018, at 12:23 PM, Mark91P notifications@github.com wrote:

Sorry for the late reply. The issue is for the example for historical data request. I have not modified the code in any way. I have tested that in MacOSx and windows 10 home edition. Matlab is in both computers 2018a. Thank you again

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/40#issuecomment-430555821, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1H2zlPl_b6qSPgL-Nh5ChOX_ZiuZks5ulvcngaJpZM4XGNIZ.

Mark91P commented 6 years ago

Today it was ok to connect, but running the example i have got:

No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

can be due i have no subscription for FB data? if i wanted to apply the example to the S&P future 500 what instructions should i write? The subscription I have localsymbol ESZ8 SecType FUT Exchange GLOBEX Currency USD expiry 21,Dec,18

softwarespartan commented 6 years ago

Are you sure you’re running. The 973 version?

Sent from my iPhone

On Oct 17, 2018, at 12:49 PM, Mark91P notifications@github.com wrote:

Today it was ok to connect, but running the example i have got:

No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

can be due i have no subscription for FB data? if i wanted to apply the example to the S&P future 500 what instructions should i write? The subscription I have localsymbol ESZ8 SecType FUT Exchange GLOBEX Currency USD expiry 21,Dec,18

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Mark91P commented 6 years ago

yes Trader Workstation 973.

To be more specific, What works: AccountSummaryExample -> retrieve successfully data from my account

input: session = TWS.Session.getInstance()

added interface method: TWSNotification notification listener has been added

session =

Session with properties:

              proxy: [1×1 com.sun.proxy.$Proxy41]
            handler: [1×1 com.tws.Handler]
      eClientSocket: [1×1 com.ib.client.EClientSocket]
        eventBuffer: [0 org.apache.commons.collections.buffer.CircularFifoBuffer]
eventListenerHandle: [1×1 event.listener]
errorListenerHandle: [1×1 event.listener]

input: [buf,lh] = TWS.initBufferForEvent(TWS.Events.HISTORICALDATA)

buf =

[]

lh =

1×1 cell array

{1×1 event.listener}

input: session.eClientSocket.eConnect('127.0.0.1',7496,0) that provides as output -1 2104 Market data farm connection is OK:eufarm

-1 2104 Market data farm connection is OK:usfuture

-1 2104 Market data farm connection is OK:usfuture.us

-1 2104 Market data farm connection is OK:cashfarm

-1 2104 Market data farm connection is OK:usfarm

-1 2106 HMDS data farm connection is OK:ushmds

input: contract = com.tws.ContractFactory.GenericStockContract('ESZ8') that provides as output conid 0 symbol ESZ8 strike 0.0 exchange SMART currency USD primaryExch ISLAND

I have to change that options to the one i have written above. I have tried to use the example you provided in the mathworks page: contract = com.ib.client.Contract(); contract.m_symbol = 'ESZ8' ; contract.m_secType = 'FUT' ; contract.m_exchange = 'GLOBEX'; contract.m_currency = 'USD' ;

but all i get is No public field m_symbol exists for class com.ib.client.Contract.

If i want to use the example code: input: contract = com.tws.ContractFactory.GenericStockContract('FB') conid 0 symbol FB strike 0.0 exchange SMART currency USD primaryExch ISLAND

and if I type: input: session.eClientSocket.reqHistoricalData(1000001,contract,'20141230 16:00:00','1 Y','1 day','TRADES',1,1,[]); pause(0.5);

I get: No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

Thanks again for your patience!

softwarespartan commented 6 years ago

Hi Mark

The code you’re showing is using the older 972 API. Can you pull the latest src in the repo ?

Interactive Brokers updated api and has some changes. The examples were updated to reflect the new api calls.

Sent from my iPhone

On Oct 17, 2018, at 1:31 PM, Mark91P notifications@github.com wrote:

yes Trader Workstation 973.

To be more specific, What works: AccountSummaryExample -> retrieve successfully data from my account

input: session = TWS.Session.getInstance()

added interface method: TWSNotification notification listener has been added

session =

Session with properties:

          proxy: [1×1 com.sun.proxy.$Proxy41]
        handler: [1×1 com.tws.Handler]
  eClientSocket: [1×1 com.ib.client.EClientSocket]
    eventBuffer: [0 org.apache.commons.collections.buffer.CircularFifoBuffer]

eventListenerHandle: [1×1 event.listener] errorListenerHandle: [1×1 event.listener] input: [buf,lh] = TWS.initBufferForEvent(TWS.Events.HISTORICALDATA)

buf =

[]

lh =

1×1 cell array

{1×1 event.listener} input: session.eClientSocket.eConnect('127.0.0.1',7496,0) that provides as output -1 2104 Market data farm connection is OK:eufarm

-1 2104 Market data farm connection is OK:usfuture

-1 2104 Market data farm connection is OK:usfuture.us

-1 2104 Market data farm connection is OK:cashfarm

-1 2104 Market data farm connection is OK:usfarm

-1 2106 HMDS data farm connection is OK:ushmds

input: contract = com.tws.ContractFactory.GenericStockContract('ESZ8') that provides as output conid 0 symbol ESZ8 strike 0.0 exchange SMART currency USD primaryExch ISLAND

I have to change that options to the one i have written above. I have tried to use the example you provided in the mathworks page: contract = com.ib.client.Contract(); contract.m_symbol = 'ESZ8' ; contract.m_secType = 'FUT' ; contract.m_exchange = 'GLOBEX'; contract.m_currency = 'USD' ;

but all i get is No public field m_symbol exists for class com.ib.client.Contract.

If i want to use the example code: input: contract = com.tws.ContractFactory.GenericStockContract('FB') conid 0 symbol FB strike 0.0 exchange SMART currency USD primaryExch ISLAND

and if I type: input: session.eClientSocket.reqHistoricalData(1000001,contract,'20141230 16:00:00','1 Y','1 day','TRADES',1,1,[]); pause(0.5);

I get: No method 'reqHistoricalData' with matching signature found for class 'com.ib.client.EClientSocket'.

Thanks again for your patience!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Mark91P commented 6 years ago

You are right!!! Using the example in the doc works like a charm! Thank you again for your patience.

softwarespartan commented 6 years ago

Excellent! Don’t hesitate to reach out if you need anything additional.

Cheers

On Oct 17, 2018, at 4:21 PM, Mark91P notifications@github.com wrote:

You are right!!! Using the example in the doc works like a charm! Thank you again for your patience.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/40#issuecomment-430625748, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1D-vPEvZ8EaDh3otmmC8PzVWzRUcks5uly73gaJpZM4XGNIZ.