Documentation Center

  • Trial Software
  • Product Updates

X_TRADER Price Update Depth

This example shows how to connect to X_TRADER® and turn on event handling for level-two market data (for example, bid and ask orders in the market for an instrument) and then create a figure window to display the depth data.

Connect to X_TRADER.

X = xtrdr;

Create an event notifier.

Create an event notifier and enable depth updates. The event notifier is the X_TRADER mechanism lets you define MATLAB® functions to use as callbacks for specific events.

createNotifier(X);
X.InstrNotify(1).EnableDepthUpdates = 1;

Create an instrument.

createInstrument(X,'Exhange','CME','Product','2F','ProdType','Future',...
               'Contract','Aug13','Alias','PriceInstrumentDepthUpdate');

Attach an instrument to a notifier.

Assign one or more notifiers to an instrument. A notifier can have one or more instruments attached to it.

X.InstrNotify(1).AttachInstrument(X.Instrument(1));

Define events.

Assign callbacks for validating or invalidating an instrument, and updating the example order book window.

X.InstrNotify(1).registerevent({'OnNotifyFound',...
                                  @ttinstrumentfound});
X.InstrNotify(1).registerevent({'OnNotifyNotFound',...
                                  @ttinstrumentnotfound});
X.InstrNotify(1).registerevent({'OnNotifyDepthData',...
                                  @ttinstrumentdepthupdate});

Set up the figure window.

Set up the figure window to display depth data.

figure('Numbertitle','off','Tag','TTPriceUpdateDepthFigure',...
       'Name',['Order Book - ' X.Instrument(1).Alias]);
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1) pos(2) 360 315],'Resize','off');

Create controls.

Create controls for the last price data.

bspc = 5;
bwid = 80;
bhgt = 20;

uicontrol('Style','text','String','Exchange',...
          'Position',[bspc 4*bspc+3*bhgt bwid bhgt]);
uicontrol('Style','text','String','Product',...
          'Position',[2*bspc+bwid 4*bspc+3*bhgt bwid bhgt]);
uicontrol('Style','text','String','Type',...
          'Position',[3*bspc+2*bwid 4*bspc+3*bhgt bwid bhgt]);
uicontrol('Style','text','String','Contract',...
          'Position',[4*bspc+3*bwid 4*bspc+3*bhgt bwid bhgt]);
ui.Exchange = uicontrol('Style','text','Tag','',...
          'Position',[bspc 3*bspc+2*bhgt bwid bhgt]);
ui.Product = uicontrol('Style','text','Tag','',...
          'Position',[2*bspc+bwid 3*bspc+2*bhgt bwid bhgt]);
ui.Type = uicontrol('Style','text','Tag','',...
          'Position',[3*bspc+2*bwid 3*bspc+2*bhgt bwid bhgt]);
ui.Contract = uicontrol('Style','text','Tag','',...
          'Position',[4*bspc+3*bwid 3*bspc+2*bhgt bwid bhgt]);
uicontrol('Style','text','String','Last Price',...
          'Position',[bspc 2*bspc+bhgt bwid bhgt]);
uicontrol('Style','text','String','Last Qty',...
          'Position',[2*bspc+bwid 2*bspc+bhgt bwid bhgt]);
uicontrol('Style','text','String','Change',...
          'Position',[3*bspc+2*bwid 2*bspc+bhgt bwid bhgt]);
ui.Last = uicontrol('Style','text','Tag','',...
          'Position',[bspc bspc bwid bhgt]);
ui.Quantity = uicontrol('Style','text','Tag','',...
          'Position',[2*bspc+bwid bspc bwid bhgt]);
ui.Change = uicontrol('Style','text','Tag','',...
          'Position',[3*bspc+2*bwid bspc bwid bhgt]);

Create a table.

Create a table containing order information.

data = {' '};
data = data(ones(10,4));
uibook = uitable('Data',data,'ColumnName',...
                {'Bid','Bid Size','Ask','Ask Size'},...
                 'Position',[5 105 350 205]);

Store data.

setappdata(0,'TTOrderBookHandle',uibook)
setappdata(0,'TTOrderBookUIData',ui)

Listen for event data.

Listen for event data with depth updates enabled.

X.Instrument(1).Open(1);

The last command instructs X_TRADER to start monitoring the attached instruments using the specified event settings.

Close the connection.

close(X)

See Also

| | | |

Related Examples

More About

Was this topic helpful?