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.


Register Event Handler for Order Server

Register an event handler to check the order server status.

sExchange = c.Instrument.Exchange;
c.Gate.registerevent({'OnExchangeStateUpdate', ...

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.


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

Set Position Limit Checks


Register Event Handlers for Order Status

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


Enable Order Submission

Open the instrument for trading and enable the X_TRADER API to retrieve market depth information when opening the instrument.


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.


Check Order Server Status

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

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)])
  disp('Order server is down.  Unable to submit order.')

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


See Also

| | | |

Related Examples

More About

External Websites