Quantcast

Documentation Center

  • Trial Software
  • Product Updates

history

Request CQG historical data

Syntax

  • history(c,s,startdate,enddate,period) example
  • history(c,s,startdate,enddate,period,x) example

Description

example

history(c,s,startdate,enddate,period) requests CQG® historical data asynchronously with bar size period between startdate and enddate for CQG instrument name s with CQG connection c.

example

history(c,s,startdate,enddate,period,x) requests CQG historical data asynchronously with additional request properties x.

Examples

expand all

Request CQG Historical Data

To request daily historical data for an instrument, create the connection c using cqg and startUp. Register an event handler for tracking events associated with connection status. Set up the API configuration properties. Then, register an event handler for tracking events associated with building and initializing the output data structure. For an example demonstrating these activities, see Request CQG Historical Data. See CQG API Reference Guide to learn more about event handlers and the API configuration properties.

Request historical daily data for instrument XYZ.XYZ for the last 10 days.

instrument = 'XYZ.XYZ';
startdate = floor(now) - 10;
enddate = floor(now);
period = 'hpDaily';

history(c,instrument,startdate,enddate,period); 

MATLAB® writes variable cqgHistoryData to the Workspace browser.

Display cqgHistoryData.

cqgHistoryData
cqgHistoryData =
   1.0e+05 *
    7.3533    0.0063    0.0063
    7.3533    0.0064    0.0064
    7.3533    0.0065    0.0065
    7.3534    0.0065    0.0065
    7.3534    0.0066    0.0066
    7.3534    0.0065    0.0065
    7.3534    0.0066    0.0066
    7.3534    0.0066    0.0066
    7.3534    0.0064    0.0064

Each row in cqgHistoryData represents data for 1 day. The columns in cqgHistoryData show the numerical representation of the timestamp, the close price, and the open price for the instrument during the day.

Close the CQG connection.

close(c);

Request CQG Historical Data with Additional Request Properties

To request daily historical data for an instrument with an additional property, create the connection c using cqg and startUp. Register an event handler for tracking events associated with connection status. Set up the API configuration properties. Then, register an event handler for tracking events associated with building and initializing the output data structure. For an example demonstrating these activities, see Request CQG Historical Data. See CQG API Reference Guide to learn more about event handlers and the API configuration properties.

Pass an additional optional request property by creating the structure x and setting the optional property.

x.UpdatesEnabled = false;

For additional optional properties you can set, see CQG API Reference Guide.

Request historical daily data for instrument XYZ.XYZ for the last 10 days using the additional optional request property x.

instrument = 'XYZ.XYZ';
startdate = floor(now) - 10;
enddate = floor(now);
period = 'hpDaily';

history(c,instrument,startdate,enddate,period,x); 

MATLAB writes the variable cqgHistoryData to the Workspace browser.

Display cqgHistoryData.

cqgHistoryData
cqgHistoryData =
   1.0e+05 *
    7.3533    0.0063    0.0063
    7.3533    0.0064    0.0064
    7.3533    0.0065    0.0065
    7.3534    0.0065    0.0065
    7.3534    0.0066    0.0066
    7.3534    0.0065    0.0065
    7.3534    0.0066    0.0066
    7.3534    0.0066    0.0066
    7.3534    0.0064    0.0064

Each row in cqgHistoryData represents data for 1 day. The columns in cqgHistoryData show the numerical representation of the timestamp, the close price, and the open price for the instrument during the day.

Close the CQG connection.

close(c);

Input Arguments

expand all

c — CQG connectionconnection object

CQG connection, specified as a CQG connection object created using cqg.

s — CQG instrument namestring

CQG instrument name, specified as a string identifying the instrument or security.

Data Types: char

startdate — Start datedate string | date scalar

Start date, specified as a starting date string or scalar.

Data Types: double | char

enddate — End datedate string | date scalar

End date, specified as an ending date string or scalar.

Data Types: double | char

period — Bar size'hpDaily' (default) | 'hpWeekly' | 'hpMonthly' | 'hpQuarterly' | 'hpSemiannual' | 'hpYearly'

Bar size, specified as one of the above enumerated strings predetermined by the CQG API that denotes the length of time to collect data.

x — CQG request properties request properties structure

CQG request properties, specified as a CQG request properties structure. Create this structure by writing MATLAB code to set additional optional request properties. For additional optional properties you can set, see CQG API Reference Guide.

Example: x.UpdatesEnabled = false;

Data Types: struct

See Also

| | |

Was this topic helpful?