www.gusucode.com > trading工具箱matlab源码程序 > trading/tradingdemos/IBOrderWorkflow.m
%% Interactive Brokers Order Workflow Example % Connect to Interactive Brokers Trader Workstation ib = ibtws('',7496); % % Define event handlers for error and order status events % eventNames = {'errMsg','orderStatus'}; % for i = 1:length(eventNames) % ib.Handle.registerevent({eventNames{i},@(varargin)ibExampleOrderEventHandler(varargin{:})}) % end % Create example order blotter to be populated by event handlers f = findobj('Tag','IBOrderBlotter'); if isempty(f) f = figure('Tag','IBOrderBlotter','MenuBar','none','NumberTitle','off','Name','IB Order Blotter'); pos = get(f,'Position'); set(f,'Position',[pos(1) pos(2) 687 335]) colnames = {'Status' 'Filled' 'Remaining' 'Avg Fill Price' 'Id' 'Parent Id','Last Fill Price','Client Id','Why Held'}; data = cell(15,9); uitable(f,'Data',data,'RowName',[],'ColumnName',colnames,'Position',[10 30 677 300],'Tag','OrderDataTable'); uicontrol('Style','text','Position',[10 5 592 20],'Tag','IBOrderMessage'); uicontrol('Style','pushbutton','String','Close',... 'Callback','evalin(''base'',''close(ib);close(findobj(''''Tag'''',''''IBOrderBlotter''''));'')',... 'Position',[607 5 80 20]); end % Request information on all open orders ib.orders(true,@ibExampleOrderEventHandler) % Create a contract ibContract = ib.Handle.createContract; ibContract.symbol = 'ELY'; ibContract.secType = 'STK'; ibContract.exchange = 'SMART'; ibContract.currency = 'USD'; % Create an order ibOrder = ib.Handle.createOrder; ibOrder.action = 'BUY'; ibOrder.totalQuantity = 2; ibOrder.orderType = 'MKT'; % Submit the order for execution with unique order id ib.createOrder(ibContract,ibOrder,ib.orderid,@ibExampleOrderEventHandler)