softwarespartan / IB4m

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

MarketDataExample #91

Closed dakr001 closed 4 years ago

dakr001 commented 4 years ago

Hi Abel, Despair2000;

Tried the MarketDataExample in the depository but it looks like it needs an update. Got the error below:

Unrecognized function or variable 'm_exchange'. Error in MarketDataExample (line 191) map.put(reqId,contract.m_exchange);

More importantly could I get some tips on the code to run a callback function whenever there a market data event?

The example you have simply dumps data from databuf immediately after the subscription request.

I have been reading on the Matlab Event and Listener concepts but not sure if this is compatible with IB4m. The Matlab doc says to create a handle request for the notification and listener. Can I get some help please...

Below is what I think I should do:

classdef MyClass < handle events MarketDataEvents end ... methods function triggerEvent(obj) ... notify(obj,'MarketDataEvents'); end end end

function lh=createListener(src) lh=addlistener(src, 'MarketDataEvents', @handlemarketevent) end

function handlemarketevent % Submit order ... end

obj=MyClass;

softwarespartan commented 4 years ago

@dakr001 can you make sure you're on the main branch. The MarketData example should have contract defined as follows

contract = com.ib.client.Contract();
contract.symbol('SPY')
contract.exchange('SMART');
contract.primaryExch('ISLAND');
contract.currency('USD');
contract.secType('STK');

note the changes in syntax for API ver +9.73

softwarespartan commented 4 years ago

Regarding callbacks, not sure what you're looking for specifically. The IB4m src has many examples. Most of the examples put the event in a buffer for processing or print to screen but that's pretty generic. There are no limitations -- just specify whatever callback function you want. Also check out +TWS/NextOrderId.m for class based example of creating objects that respond to events. Let me know if something more specific

dakr001 commented 4 years ago

@softwarespartan Thank you very much.

I have figured out what needs to be done. Sorry for the novice queries.

softwarespartan commented 4 years ago

No problem — happy to help