Main Content

Create Order Using X_TRADER

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

Connect to Trading Technologies X_TRADER

c = xtrdr;

Create Instrument for Contract

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 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 Order Set and Set Order Properties

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';

Set Position Limit Checks

c.OrderSet(1).Set('NetLimits',false)

Register Event Handlers for Order Status

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

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)

Build Order Profile with Existing Instrument

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

Set Customer Default Property

Assign the customer defaults for trading an instrument.

orderProfile.Customer = '<Default>';

Set Up Order Profile as Market Order

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')

Check Order Server Status

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

Verify Order Server Availability and Submit Order

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 Trading Technologies X_TRADER Connection

close(c)

See Also

| | | |

Related Examples

More About

External Websites