www.gusucode.com > trading工具箱matlab源码程序 > trading/trading/@cqg/history.m
function history(c,s,startdate,enddate,historicalPeriod,x) %HISTORY CQG historical data. % HISTORY(C,S,STARTDATE,ENDDATE,PERIOD) asynchronously requests CQG historical % data given the connection handle, C, security list, S, start date, % STARTDATE, end date, ENDDATE, and the periodicity, PERIOD. % % Valid settings for PERIOD are: % % 'hpDaily' - daily (default) % 'hpWeekly' - weekly % 'hpMonthly' - monthly % 'hpQuarterly' - quarterly % 'hpSemiannual' - semi-annually % 'hpYearly' - annually % % HISTORY(C,S,START,END,PERIOD,X) asynchronously requests CQG historical % data given the connection handle, C, security list, S, start date, % START, end date, END, and the periodicity, PERIOD. The input structure % X sets additional request properties. % % The example script CQGHistoricalDataRequestWorkflow outlines making % historical data requests and using event handlers to process the % asynchronous return data. % % See also CQG, CREATEORDER, REALTIME, TIMESERIES. % Copyright 2013 The MathWorks, Inc. %Validate security/field list. Security/field list should be cell array string if ischar(s) s = cellstr(s); end if ~iscell(s) || ~ischar(s{1}) error(message('trading:cqg:securityInputError')) end % Set default periodicity if not given if ~exist('historicalPeriod','var') || isempty(historicalPeriod) historicalPeriod = 'hpDaily'; end % Create request and set properties expressionRequest = c.Handle.CreateExpressionRequest; for i = 1:length(s) expressionRequest.AddSubExpression(s{i},['ts' num2str(i)]); end expressionRequest.HistoricalPeriod = historicalPeriod; expressionRequest.RangeStart = COM.date(datevec(startdate)); expressionRequest.RangeEnd = COM.date(datevec(enddate)); % Set or overwrite additional user specified properties if exist('x','var') settingFlds = fieldnames(x); for i = 1:length(settingFlds) expressionRequest.(settingFlds{i}) = x.(settingFlds{i}); end end % Submit request c.Handle.RequestExpression(expressionRequest);