createOrder
Create CQG order
Syntax
Description
Examples
Create and Place a Market Order Using a CQGInstrument Object
To create and place a market order for shares of an
instrument with the CQG Trader Com API using a CQGInstrument
object to
specify the instrument, create the connection c
using
cqg
and startUp
. Register an event
handler for tracking events associated with the connection status. Set up the
API configuration properties. Then, register event handlers for tracking events
associated with the instrument subscription, order and account. Subscribe to the
instrument and create the CQGInstrument
object
cqgInst
. Then, set up the account credentials
accountHandle
. For an example demonstrating these
activities, see Create CQG Orders. See
CQG API Reference Guide to learn more about event
handlers, API configuration properties, and CQGInstrument
object.
Create a market order that buys one share of the subscribed security
cqgInst
using the account credentials
accountHandle
.
quantity = 1; oMarket = createOrder(c,cqgInst,1,accountHandle,quantity); oMarket.Place
ans = OrderChanged
The CQGOrder
object oMarket
contains
the order. The CQG API executes the market order using the CQG API function Place
. After execution, the
order status changes.
Close the CQG connection.
shutDown(c)
Create and Place a Market Order Using a CQG Instrument Character Vector
To create and place a market order for shares of an
instrument with the CQG Trader Com API, 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 event handlers for tracking events
associated with instrument subscription, order, and account. Subscribe to the
instrument. Then, set up the account credentials
accountHandle
. For an example demonstrating these
activities, see Create CQG Orders. To learn more
about the event handlers and the API configuration properties, see the
CQG API Reference Guide.
Create a market order that buys one share of the previously subscribed
security 'EZC'
using the defined account credentials
accountHandle
.
cqgInstrumentName = 'EZC'; quantity = 1; oMarket = createOrder(c,cqgInstrumentName,1,accountHandle, ... quantity); oMarket.Place
ans = OrderChanged
The CQGOrder
object oMarket
contains
the order. The CQG API executes the market order using the CQG API function Place
. After execution, the
order status changes.
Close the CQG connection.
shutDown(c)
Create and Place a Limit Order
To create and place a limit order for shares of an instrument
with the CQG Trader Com API using a CQGInstrument
object to
specify the 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 event handlers for tracking events
associated with instrument subscription, order and account. Subscribe to the
instrument and create the CQGInstrument
object
cqgInst
. Then, set up the account credentials
accountHandle
. For an example demonstrating these
activities, see Create CQG Orders. See
CQG API Reference Guide to learn more about the event
handlers, the API configuration properties, and the
CQGInstrument
object.
To create a limit order, you can use the bid price. Extract the
CQG bid object qtBid
from the previously
defined CQGInstrument
object
cqgInst
.
qtBid = cqgInst.get('Bid');
Create a limit order that buys one share of the previously subscribed
security cqgInst
using the previously defined account
credentials accountHandle
and qtBid
for the limit price.
quantity = 1; limitprice = qtBid.get('Price'); oLimit = createOrder(c,cqgInst,2,accountHandle,quantity, ... limitprice); oLimit.Place
ans = OrderChanged
The CQGOrder
object oLimit
contains
the order. The CQG API executes the limit order using the CQG API function Place
. After execution, the
order status changes.
Close the CQG connection.
shutDown(c)
Create and Place a Stop Order
To create and place a stop order for shares of an instrument
with the CQG Trader Com API using a CQGInstrument
object to
specify the 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 event handlers for tracking events
associated with instrument subscription, order and account. Subscribe to the
instrument and create the CQGInstrument
object
cqgInst
. Then, set up the account credentials
accountHandle
. For an example demonstrating these
activities, see Create CQG Orders. See
CQG API Reference Guide to learn more about the event
handlers, the API configuration properties, and the
CQGInstrument
object.
To create a stop order, you can use the trade price. Extract the
CQG trade object qtTrade
from the previously
defined CQGInstrument
object
cqgInst
.
qtTrade = cqgInst.get('Trade');
Create a stop order that buys one share of the previously subscribed
security cqgInst
using the previously defined account
credentials accountHandle
and qtTrade
for the stop price.
quantity = 1; stopprice = qtTrade.get('Price'); oStop = createOrder(c,cqgInst,3,accountHandle,quantity, ... stopprice); oStop.Place
ans = OrderChanged
The CQGOrder
object oStop
contains
the order. The CQG API executes the stop order using the CQG API function Place
. After execution, the
order status changes.
Close the CQG connection.
shutDown(c)
Create and Place a Stop Limit Order
To create and place a stop limit order for shares of an
instrument with the CQG Trader Com API using a CQGInstrument
object to
specify the 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 event handlers for tracking events
associated with instrument subscription, order and account. Subscribe to the
instrument and create the CQGInstrument
object
cqgInst
. Then, set up the account credentials
accountHandle
. For an example demonstrating these
activities, see Create CQG Orders. See
CQG API Reference Guide to learn more about the event
handlers, the API configuration properties, and the
CQGInstrument
object.
To create a stop limit order, you can use the bid and trade prices.
Extract the CQG bid object qtBid
and the CQG trade object qtTrade
from the previously
defined CQGInstrument
object
cqgInst
.
qtBid = cqgInst.get('Bid'); qtTrade = cqgInst.get('Trade');
Create a stop limit order that buys one share of the subscribed security
cqgInst
using the defined account credentials
accountHandle
and qtBid
for the
limit price and qtTrade
for the stop price.
quantity = 1; limitprice = qtBid.get('Price'); stopprice = qtTrade.get('Price'); oStopLimit = createOrder(c,cqgInst,4,accountHandle,quantity, ... limitprice,stopprice); oStopLimit.Place
ans = OrderChanged
The CQGOrder
object oStopLimit
contains the order. The CQG API executes the stop limit order using the CQG API function Place
. After execution, the
order status changes.
Close the CQG connection.
shutDown(c)
Input Arguments
c
— CQG connection
connection object
CQG connection, specified as a CQG connection object
created using cqg
.
s
— CQG instrument name
character vector | string scalar | CQGInstrument
object
CQG instrument name, specified as a character vector, string
scalar, or CQGInstrument
object, denoting the instrument
or security for the order transaction. For more information about creating a
CQGInstrument
object, see the CQG API Reference Guide. For a list of CQG instrument names, see Tradable Symbols.
account
— CQG account credentials
CQGAccount
object
CQG account credentials, specified as a
CQGAccount
object. This object encapsulates all data
pertinent to your account. For more information about creating a
CQGAccount
object, see CQG API Reference Guide.
quantity
— CQG order quantity
numeric scalar
CQG order quantity, specified as a numeric scalar denoting the number of shares to order. A positive number denotes a buy and a negative number denotes a sell.
Data Types: double
limitprice
— CQG limit price
double
CQG limit price, specified as a double denoting the limit order price.
Data Types: double
stopprice
— CQG stop price
double
CQG stop price, specified as a double denoting the stop order price.
Data Types: double
Output Arguments
o
— CQG order
CQGOrder
object
CQG order, returned as a CQGOrder
object. This
object encapsulates all data necessary to execute a CQG order. For more information about creating a
CQGOrder
object, see CQG API Reference Guide.
Version History
Introduced in R2013b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)