www.gusucode.com > trading工具箱matlab源码程序 > trading/tradingdemos/cqgrealtimeeventhandler.m
function cqgrealtimeeventhandler(varargin) %CQGREALTIMEEVENTHANDLER Example CQG realtime instrument event handler. switch varargin{end} case 'IncorrectSymbol' disp('Incorrect Symbol') case {'InstrumentSubscribed','InstrumentChanged'} switch varargin{end} case 'InstrumentSubscribed' % Show full instrument name for later use instName = varargin{4}.get('FullName'); disp([instName ' subscribed']) assignin('base','cqgInstrument',instName) % Get instrument cqgInst = varargin{4}; case 'InstrumentChanged' cqgInst = varargin{3}; end % Get quotes quotes = cqgInst.get('Quotes'); numQuotes = quotes.Count; % Parse quote data into structure for i = 0:numQuotes-1 subQuote = quotes.Item(i); if ~isempty(subQuote) flds = fieldnames(subQuote); for j = 1:length(flds); cqgData.(flds{j}){i+1,1} = subQuote.get(flds{j}); end end end % Send data to base workspace assignin('base',['cqgData' cqgInst.Commodity],cqgData) end