CreateCQG订单

此示例显示如何连接到CQG®,定义事件处理程序,订阅安全性,定义帐户句柄,并提交执行订单。

创造CQG连接

使用CQG Connection对象使用cqg

c = cqg;

定义事件处理程序

Register the sample event handlercqgconnectionEventHandler.跟踪与连接状态关联的事件。

Eventnames = {'CELStarted''dataerror''准备好了'......'DataConnectionStatusChanged'......'gwconnectionstatuschangeed'......'gwenvironmentchangeed'};对于i = 1:length(eventNames) registerevent(c.Handle,{eventNames{i},......@(varargin)cqgconnectionEventHandler(varargin {:})})结束

cqgconnectionEventHandler.被分配给事件eventNames

Set the API configuration properties. For example, to set the time zone to Eastern Time, enter the following.

c.APIConfig.TimeZoneCode ='tzeastern';

c.APIConfig是CQG配置对象。有关设置API配置属性的详细信息,请参阅CQG API参考指南

Establish the connection to CQG.

启动(c)
Celstarted DataConnectionStatusChanged GWConnectionStatusChanged.

连接事件处理程序显示成功CQG连接的事件名称。

Register an event handler to track events associated with a CQG instrument subscription.

streamEventNames = {'InstrumentSubscribed''instormanded'......'不正确的ysymbol'};对于i = 1:长度(StreameVentNames)注册(C.Handle,{StreameventNames {i},......@(varargin)cqgrealtimeeventhandler(varargin{:})})结束

Register an event handler to track events associated with a CQG order and account.

orderEventNames = {'AccountChanged''oriterChanged''allorderscanceled'};对于i = 1:长度(OrderEventNames)注册经验(C.Handle,{OrdereVentNames {i},......@(varargin)cqgordereventhandler(varargin {:})})结束

订阅CQGInstrument

With the connection established, subscribe to the CQG instrument. The instrument must be successfully subscribed first before it is available for transactions. You must format the instrument name in the CQG long symbol view. For example, to subscribe to a security tied to the EURIBOR, enter the following.

实时(C,'f.us.ie')暂停(2)
F.US.IEK13订阅

pause导致matlab.®继续等待2秒,然后继续为CQG提供时间来订阅仪器。

创建CQG仪器对象。

使用仪器createOrder.那import the name of the instrumentcqginstumentname.into the current MATLAB workspace. Then, create theCqginstument.目的cqginst.

cqginstrumentname =评估('base''cqginstrument');cqginst = c.handle.Instruments.Item(CQGinStrumentName);

设置帐户凭据

设置CQG标志以启用帐户信息检索。

set(c.Handle,'AccountSubscriptionLevel''aslnone')设置(C.Handle,'AccountSubscriptionLevel''aslaccountupdatesanders')暂停(2)
ans = AccountChanged

CQG API显示帐户信息已更改。

设置CQG帐户凭据。

检索cqgaccount.对象Accounthandle使用您的帐户信息createOrder.。For details about creating acqgaccount.对象,参见CQG API参考指南

Accounthandle = C.Handle.Accounts.ItembyIndex(0);

CreateCQG市场,限制,停止和停止限制订单

创建一个购买订阅安全的一份的市场订单cqginst.使用帐户凭据Accounthandle

数量= 1;oMarket = createOrder (c, cqgInst,1,accountHandle,quantity); oMarket.Place
ans = OrderChanged

cqgorder.目的Omarket.包含订单。该CQG API executes the market order using the CQG API function地点。执行后,订单状态更改。

要使用字符向量,为安全性,订阅安全性'ezc'as shown above. Then, create a market order that buys one share of the security'ezc'使用已定义的帐户凭据Accounthandle

cqginstrumentname ='ezc';数量= 1;oMarket = createOrder (c, cqgInstrumentName,1,accountHandle,quantity); oMarket.Place
ans = OrderChanged

cqgorder.目的Omarket.包含订单。该CQG API executes the market order using the CQG API function地点。执行后,订单状态更改。

To create a limit order, you can use the bid price. Extract the CQG bid objectqtBidfrom the previously definedCqginstument.目的cqginst.。有关的详细信息Cqginstument.对象,参见CQG API参考指南

qtbid = cqginst.get('Bid');

创建一个限制顺序,以购买先前订阅安全的一份cqginst.使用先前定义的帐户凭据AccounthandleandqtBid对于the limit price.

数量= 1;limitprice = qtBid.get('价钱');奥利米= createOrder(c,cqgInst,2,accountHandle,quantity,limitprice); oLimit.Place
ans = OrderChanged

cqgorder.目的奥利米包含订单。CQG API使用CQG API函数执行限制顺序地点。执行后,订单状态更改。

要创建停止订单,您可以使用贸易价格。提取CQG交易对象qtTradefrom the previously definedCqginstument.目的cqginst.

qttrade = cqginst.get(“交易”);

Create a stop order that buys one share of the previously subscribed securitycqginst.使用先前定义的帐户凭据AccounthandleandqtTrade停止价格。

数量= 1;stopprice = qtTrade.get('价钱');ostop.= createOrder(c,cqgInst,3,accountHandle,quantity,stopprice); oStop.Place
ans = OrderChanged

cqgorder.目的ostop.包含订单。该CQG API executes the stop order using the CQG API function地点。执行后,订单状态更改。

要创建停止限制订单,请使用上面定义的出价和贸易价格。创建一个停止限制顺序,可以购买订阅安全的一份cqginst.使用已定义的帐户凭据Accounthandle

数量= 1;OSTOPLIMIT = CreateOrder(C,Cqginst,4,Accountthandle,数量,......LimitPrice,Stopprice);Ostoplimit.Place
ans = OrderChanged

cqgorder.目的骨架包含订单。CQG API使用CQG API函数执行停止限制顺序地点。执行后,订单状态更改。

关上CQG连接

关机(c)

也可以看看

|||||||

相关例子

更多关于

外部网站