Listen for X_TRADER Price Updates
This example shows how to connect to X_TRADER® and listen for price update event data.
Connect to X_TRADER
X = xtrdr;
Create an Event Notifier
The event notifier is the X_TRADER mechanism that lets you define MATLAB® functions to use as callbacks for specific events.
createNotifier(X)
Create an Instrument
Create an instrument and attach it to the notifier.
createInstrument(X,'Exchange','CME','Product','2F',... 'ProdType','Future','Contract','Aug13',... 'Alias','PriceInstrument1') X.InstrNotify(1).AttachInstrument(X.Instrument(1))
Define Events
Assign callbacks for validating or invalidating an instrument, and for handling data updates for a previously validated instrument.
registerevent(X.InstrNotify(1),{'OnNotifyFound',... @(varargin)ttinstrumentfound(varargin{:})}) registerevent(X.InstrNotify(1),{'OnNotifyNotFound',... @(varargin)ttinstrumentnotfound(varargin{:})}) registerevent(X.InstrNotify(1),{'OnNotifyUpdate',... @(varargin)ttinstrumentupdate(varargin{:})})
Monitor Events
Set the update filter to monitor the desired fields. In this example, events are monitored for updates to last price, last quantity, previous last quantity, and a change in prices. Listen for this event data.
X.InstrNotify(1).UpdateFilter = 'Last$,LastQty$,~LastQty$,Change$';
X.Instrument(1).Open(0)
The last command tells X_TRADER to start monitoring the attached instruments using the specified event settings.
Close the Connection
close(X)
See Also
xtrdr
| close
| createInstrument
| createNotifier