This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Listen for X_TRADER Price Market Depth Updates

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.

X.InstrNotify(1).EnableDepthUpdates = 1;

Create an Instrument


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.


Define Events

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


Set Up the Figure Window

Set up the figure window to display depth data.

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

Create Controls

Create controls for the last price data.

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

          'Position',[bspc 4*bspc+3*bhgt bwid bhgt])
          'Position',[2*bspc+bwid 4*bspc+3*bhgt bwid bhgt])
          'Position',[3*bspc+2*bwid 4*bspc+3*bhgt bwid bhgt])
          '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])
          '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


Listen for Event Data

Listen for event data with depth updates enabled.


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

Close the Connection


See Also

| | | |

Related Examples

More About

Was this topic helpful?