This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create an Order Using CQG

This example shows how to connect to CQG® and create a market order.

Connect to CQG

c = cqg;

Establish Event Handlers

Start the CQG session. Set up event handlers for instrument subscription, orders, and associated events.


streamEventNames = {'InstrumentSubscribed', ...

for i = 1:length(streamEventNames)
  registerevent(c.Handle,{streamEventNames{i}, ...

orderEventNames = {'AccountChanged','OrderChanged','AllOrdersCanceled'};

for i = 1:length(orderEventNames)
  registerevent(c.Handle,{orderEventNames{i}, ...

Subscribe to Instrument

Subscribe to a security tied to the EURIBOR.


Create CQGInstrument Object

To use the instrument for creating an order, import the instrument name cqgInstrumentName into the current MATLAB® workspace. Then, create the CQGInstrument object cqgInst.

cqgInstrumentName = evalin('base','cqgInstrument');
cqgInst = c.Handle.Instruments.Item(cqgInstrumentName);

Set Up Account Credentials

Set the CQG flags to enable account information retrieval.

accountHandle = c.Handle.Accounts.ItemByIndex(0);

Create Market Order

Create a market order that buys one share of the subscribed security cqgInst using the account credentials accountHandle.

orderType = 1;  % Market order flag
quantity = 1;   % Positive quantity is Buy, negative is Sell
oMarket = createOrder(c,cqgInst,orderType,accountHandle,quantity);

Close CQG Connection


See Also

| | | |

Related Examples

More About

External Websites