This example shows how to connect to Trading Technologies® X_TRADER® and create a market order.
c = xtrdr;
Create an instrument for a contract of CAISO NP15 EZ Gen Hub 5 MW Peak Calendar-Day Real-Time LMP Futures with an expiration date of August 2014 on the Chicago Mercantile Exchange.
createInstrument(c,'Exchange','CME','Product','2F',... 'ProdType','Future','Contract','Aug14',... 'Alias','SubmitOrderInstrument3')
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 to ORD_NOTIFY_NORMAL
sets
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';
c.OrderSet(1).Set('NetLimits',false)
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)})
Open the instrument for trading and enable the X_TRADER API to retrieve market depth information when opening the instrument.
c.OrderSet(1).Open(1)
orderProfile = createOrderProfile(c,'Instrument',c.Instrument(1));
Assign the customer defaults for trading an instrument.
orderProfile.Customer = '<Default>';
Set up the order profile as a market order for buying 225 shares.
orderProfile.Set('BuySell','Buy') orderProfile.Set('Qty','225') orderProfile.Set('OrderType','M')
nCounter = 1; while ~exist('bServerUp','var') && nCounter < 20 % bServerUp is created by ttorderserverstatus pause(1) nCounter = nCounter + 1; end
if exist('bServerUp','var') && bServerUp % Submit the order submittedQuantity = c.OrderSet(1).SendOrder(orderProfile); disp(['Quantity Sent: ' num2str(submittedQuantity)]) else disp('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 argument submittedQuantity
.
close(c)
close
| createInstrument
| createOrderProfile
| createOrderSet
| xtrdr