Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan 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.

startUp(c)

streamEventNames = {'InstrumentSubscribed', ...
    'InstrumentChanged','IncorrectSymbol'};

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

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

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

Subscribe to Instrument

Subscribe to a security tied to the EURIBOR.

realtime(c,'F.US.IE')
pause(2)

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.

c.Handle.set('AccountSubscriptionLevel','aslNone');
c.Handle.set('AccountSubscriptionLevel','aslAccountUpdatesAndOrders');
pause(2)
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);
oMarket.Place

Close CQG Connection

close(c)

See Also

| | | |

Related Examples

More About

External Websites

Was this topic helpful?