www.gusucode.com > trading工具箱matlab源码程序 > trading/tradingdemos/IBStreamingDataWorkflow.m

    %% Interactive Brokers Streaming Data Workflow Example

% Connect to Interactive Brokers Trader Workstation
ib = ibtws('',7496);

% Create example dialog to display realtime data
f = findobj('Tag','IBStreamingDataWorkflow');
if isempty(f)
  f = figure('Tag','IBStreamingDataWorkflow','MenuBar','none','NumberTitle','off');
  pos = get(f,'Position');
  set(f,'Position',[pos(1) pos(2) pos(3)+37 109])
  colnames = {'Trade' 'Size' 'Bid' 'BidSize' 'Ask' 'AskSize','Total Volume'};
  rownames = {'GOOG','AAPL','YHOO'};
  data = cell(3,6);
  uitable(f,'Data',data,'RowName',rownames,'ColumnName',colnames,'Position',[10 30 582 76],'Tag','SecurityDataTable');
  uicontrol('Style','text','Position',[10 5 497 20],'Tag','IBMessage');
  uicontrol('Style','pushbutton','String','Close',...
    'Callback','evalin(''base'',''close(ib);close(findobj(''''Tag'''',''''IBStreamingDataWorkflow''''));'')',...
    'Position',[512 5 80 20]);
end

% Create contracts
ibContract1 = ib.Handle.createContract;
ibContract1.symbol = 'GOOG';
ibContract1.secType = 'STK';
ibContract1.exchange = 'SMART';
ibContract1.currency = 'USD';
ibContract2 = ib.Handle.createContract;
ibContract2.symbol = 'AAPL';
ibContract2.secType = 'STK';
ibContract2.exchange = 'SMART';
ibContract2.currency = 'USD';
ibContract3 = ib.Handle.createContract;
ibContract3.symbol = 'YHOO';
ibContract3.secType = 'STK';
ibContract3.exchange = 'SMART';
ibContract3.currency = 'USD';

% Request streaming data
tickerID = ib.realtime({ibContract1;ibContract2;ibContract3},'100',@(varargin)ibExampleRealtimeEventHandler(varargin{:}));