Main Content

Create Order UsingX_TRADER

This example shows how to connect to Trading Technologies®X_TRADER®and create a market order.

Connect to交易技术X_TRADER

c = xtrdr;

Create Instrument for Contract

为CAISO NP15 EZ GEN HUB 5 MW峰值日历日实时LMP期货的合同创建工具,并在2014年8月在芝加哥商业交易所的到期日期。

CreateInstrument(c,'Exchange','CME','Product','2F',...'ProdType','Future','合同','Aug14',...'Alias','SubmitOrderInstrument3')

Register Event Handler for Order Server

Register an event handler to check the order server status.

sExchange = c.Instrument.Exchange; c.Gate.registerevent({'OnExchangeStateUpdate',...@(varargin)ttorderserverstatus(varargin{:},sExchange)})

创建订单设置并设置订单属性

Create an empty order set. Then, set order set properties. Setting the first property to true (1) enables the X_TRADER API to send order rejection notifications. Setting the second property to true (1) enables the X_TRADER API to add order pairs for all order updates to the order tracker list in this order set. Setting the third property toORD_NOTIFY_NORMALsets the X_TRADER API notification mode for order status events to normal.

CreateOrderSet(c) c.OrderSet(1).EnableOrderRejectData = 1; c.OrderSet(1).EnableOrderUpdateData = 1; c.OrderSet(1).OrderStatusNotifyMode ='ord_notify_normal';

Set Position Limit Checks

c.orderset(1).set(“ Netlimits”,错误的)

注册活动处理程序的订单状态

Register event handlers to track events associated with the order status.

registerevent(c.OrderSet(1),{'OnOrderFilled',...@(varargin)ttorderevent(varargin{:},c)}) registerevent(c.OrderSet(1),{'OnOrderRejected',...@(varargin)ttorderevent(varargin{:},c)}) registerevent(c.OrderSet(1),{'OnOrderSubmitted',...@(varargin)ttorderevent(varargin{:},c)}) registerevent(c.OrderSet(1),{'OnOrderDeleted',...@(varargin)ttorderevent(varargin{:},c)})

Enable Order Submission

打开交易仪器,并使X_Trader API在打开仪器时可以检索市场深度信息。

c.OrderSet(1).Open(1)

构建顺序配置文件与现有的仪器

orderProfile = createOrderProfile(c,'Instrument',c.Instrument(1));

Set Customer Default Property

Assign the customer defaults for trading an instrument.

orderProfile.Customer ='';

Set Up Order Profile as Market Order

设置订单配置文件作为购买225股的市场订单。

orderProfile.Set('BuySell','Buy') orderProfile.Set('Qty','225') orderProfile.Set('OrderType','M')

检查订单服务器状态

nCounter = 1;while~exist('bServerUp','var') && nCounter < 20% bServerUp is created by ttorderserverstatuspause(1) nCounter = nCounter + 1;end

Verify Order Server Availability and Submit Order

ifexist('bServerUp','var') && bServerUp% Submit the ordersubmittedQuantity = c.OrderSet(1).SendOrder(orderProfile); disp(['Quantity Sent: 'num2str(submittedQuantity)])elsedisp('Order server is down. Unable to submit order.')end

The X_TRADER API submits the order to the exchange and returns the number of contracts sent for lot-based contracts or the flow quantity sent for flow-based contracts in the output argumentsubmittedQuantity.

Close交易技术X_TRADERConnection

close(c)

See Also

||||

Related Examples

More About

External Websites