softwarespartan / IB4m

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

Get returned messages #72

Open dakr001 opened 4 years ago

dakr001 commented 4 years ago

Hi,

Is there a way to get the returned message into a Matlab variable when calling session.eClientSocket.reqContractDetails(0,contract) when there is no data? i.e. dataBuf.size()=0.

This happens for example when there are no transactions for the instrument, no data subscription, or the candle time is not available for the instrument. Below is an example message:

2000001 162 Historical Market Data Service error message:No market data permissions for VENTURE STK

On a related note, is there a way to query the valid types of candle time for an instrument. For example 1 month daily candle is not available for options.

Thanks.

Despair2000 commented 4 years ago

You have to create a buffer and listener to catch the error messages:

[errorBuffer,errorListener] = TWS.initBufferForEvent(TWS.Events.ERROR);

You can then retrieve the error message from the buffer in the usual way.

dakr001 commented 4 years ago

Thanks Despair2000, very helpful.

Any hints on getting the list of valid candle times?

dakr001 commented 4 years ago

Hi Despair2000

I used the following: errormessage = collection2cell(errorBuffer.get().data);

and got the following error: Error using collection2cell (line 10) input arg1 must be of type java.util.Collection

Is there is mising request function similar to session.eClientSocket.reqContractDetails(0,contract);?

I went through the list of request functions but didn't find anything suitable.

Despair2000 commented 4 years ago

errormessage = collection2cell(errorBuffer)

This should do the trick. The get() method is already called in collection2cell. So your example does so twice and this is what causes the error. However this will give you a cell array of the error messages that came in. You can view them with for example:

disp(errorMessage{1}.data)

Your question regarding "candle times" I don't really understand. Are you asking which kind of data is available (daily bars, 1h bars and so on) or how much data of a special resolution is available?

dakr001 commented 4 years ago

Hi Despair2000 - thanks again - it works now. Yes the former. Which data is available (daily bars, 1h bars and so on) .

softwarespartan commented 4 years ago

I believe the docs specify how much historical data is available at particular resolutions

https://interactivebrokers.github.io/tws-api/historical_limitations.html

dakr001 commented 4 years ago

Thanks. Yes the doc explains it. The limitation EOD on Option/FOP/etc. seem unusual to me. For a monthly duration, EOD candles are not available but 8 hour candles are available...

Despair2000 commented 4 years ago

That's strange but you can always built your daily candles from 8h data.

dakr001 commented 4 years ago

Ok thanks