routes

Obtain Bloomberg EMSX route subscription

Syntax

  • [events,subs] = routes(c,fields) example
  • [events,subs] = routes(c,fields,Name,Value) example
  • [events,subs] = routes(c,fields,options) example

Description

example

[events,subs] = routes(c,fields) subscribes to Bloomberg® EMSX fields fields using the Bloomberg EMSX connection c. routes returns existing event data events from the event queue and the Bloomberg EMSX subscription list subs.

example

[events,subs] = routes(c,fields,Name,Value) uses additional options specified by one or more Name,Value pair arguments to specify a custom event handler or timeout value for the event handler.

example

[events,subs] = routes(c,fields,options) uses the options structure to customize the output, which is useful to preconfigure and save your options for repeated use. The options structure fields and values correspond to names and values of name-value pair arguments, respectively.

Examples

expand all

Set Up Route Subscription Using the Default Event Handler

Create the Bloomberg EMSX connection c.

 c = emsx('//blp/emapisvc_beta');

Set up the route subscription for Bloomberg EMSX fields EMSX_BROKER and EMSX_WORKING using the Bloomberg EMSX connection c.

fields = {'EMSX_BROKER','EMSX_WORKING'};

[events,subs] = routes(c,fields)
events = 

                       MSG_TYPE: {5x1 cell}
                   MSG_SUB_TYPE: {5x1 cell}
                   EVENT_STATUS: [5x1 int32]
                   ...

subs =

com.bloomberglp.blpapi.SubscriptionList@463b9287

events contains fields for the events currently in the event queue. subs contains the Bloomberg EMSX subscription list object.

Unsubscribe from route events using the Bloomberg EMSX subscription list object subs.

b.Session.unsubscribe(subs)

Close the Bloomberg EMSX connection.

close(c)

Set Up Route Subscription Using a Custom Event Handler

Create the Bloomberg EMSX connection c.

 c = emsx('//blp/emapisvc_beta');

Write a custom event handler function named eventhandler. Run the custom event handler using timer. Start the timer to run eventhandler immediately using start. For details, see Writing and Running Custom Event Handler Functions.

t = timer('TimerFcn',{@eventhandler,c},'Period',1,...
          'ExecutionMode','fixedRate');
start(t)

t is the timer object.

Set up the route subscription for Bloomberg EMSX fields EMSX_BROKER and EMSX_WORKING using the Bloomberg EMSX connection c. Use the custom event handler by setting the name-value pair argument 'useDefaultEventHandler' to false.

fields = {'EMSX_BROKER','EMSX_WORKING'};

[events,subs] = routes(c,fields,'useDefaultEventHandler',false)
events =

     []

subs =

com.bloomberglp.blpapi.SubscriptionList@463b9287

events is an empty double. The custom event handler processes the event queue. subs contains the Bloomberg EMSX subscription list object.

Unsubscribe from route events using the Bloomberg EMSX subscription list object subs. Stop the timer to stop data updates using stop.

b.Session.unsubscribe(subs)
stop(t)

Delete the timer if you are done processing data updates using delete.

delete(t)

Close the Bloomberg EMSX connection.

close(c)

Set Up Route Subscription Using a Timeout

Create the Bloomberg EMSX connection c.

 c = emsx('//blp/emapisvc_beta');

Set up the route subscription for Bloomberg EMSX fields EMSX_BROKER and EMSX_WORKING using the Bloomberg EMSX connection c. Specify the name-value pair argument timeOut and set it to 200 milliseconds. timeOut specifies how long the event handler listens to the queue for an event for each iteration of the code.

fields = {'EMSX_BROKER','EMSX_WORKING'};

[events,subs] = routes(c,fields,'timeOut',200)
events = 

                       MSG_TYPE: {5x1 cell}
                   MSG_SUB_TYPE: {5x1 cell}
                   EVENT_STATUS: [5x1 int32]
                   ...

subs =

com.bloomberglp.blpapi.SubscriptionList@463b9287

events contains fields for the events currently in the event queue. subs contains the Bloomberg EMSX subscription list object.

Unsubscribe from route events using the Bloomberg EMSX subscription list object subs.

b.Session.unsubscribe(subs)

Close the Bloomberg EMSX connection.

close(c)

Set Up Route Subscription Using an Options Structure

Create the Bloomberg EMSX connection c.

 c = emsx('//blp/emapisvc_beta');

Create a structure options. To use the default event handler, set the field useDefaultEventHandler to true. Set the field timeOut to 200 milliseconds. timeOut specifies how long the event handler listens to the queue for an event for each iteration of the code. Set up the route subscription for Bloomberg EMSX fields EMSX_BROKER and EMSX_WORKING using the Bloomberg EMSX connection c and options structure options.

options.useDefaultEventHandler = true;
options.timeOut = 200;
fields = {'EMSX_BROKER','EMSX_WORKING'};

[events,subs] = routes(c,fields,options)
events = 

                       MSG_TYPE: {5x1 cell}
                   MSG_SUB_TYPE: {5x1 cell}
                   EVENT_STATUS: [5x1 int32]
                   ...

subs =

com.bloomberglp.blpapi.SubscriptionList@463b9287

events contains fields for the events currently in the event queue. subs contains the Bloomberg EMSX subscription list object.

Unsubscribe from route events using the Bloomberg EMSX subscription list object subs.

b.Session.unsubscribe(subs)

Close the Bloomberg EMSX connection.

close(c)

Input Arguments

expand all

c — Bloomberg EMSX service connectionconnection object

Bloomberg EMSX service connection, specified as a connection object created using emsx.

fields — Bloomberg EMSX field informationcell array

Bloomberg EMSX field information, specified using a cell array. Use getAllFieldMetaData to view available field information for the Bloomberg EMSX service.

Example: 'EMSX_TICKER'
'EMSX_AMOUNT'
'EMSX_ORDER_TYPE'

Data Types: cell

options — Options for custom event handler or timeout valuestructure

Options for custom event handler or timeout value, specified as a structure. Use the options structure instead of name-value pair arguments to reuse the optional name-value pair arguments to specify a custom event handler or timeout value for the event handler.

The options structure field and values correspond to names and values of the name-value pair arguments, respectively.

Specify using a custom event handler and a timeout value of 500 milliseconds.

Example: options.useDefaultEventHandler = false;
options.timeOut = 500;

Data Types: struct

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'useDefaultEventHandler',false

'useDefaultEventHandler' — Flag for event handler preferencetrue (default) | false

Flag for event handler preference, indicating whether to use the default or custom event handler to process order events, specified as the comma-separated pair consisting of 'useDefaultEventHandler' and the logical values true or false.

To specify the default event handler, set this flag to true.

Otherwise, set this flag to false to specify a custom event handler.

Data Types: logical

'timeOut' — Timeout value for event handler500 milliseconds (default) | nonnegative integer

Timeout value for event handler for the Bloomberg EMSX service, specified as the comma-separated pair consisting of 'timeOut' and a nonnegative integer in units of milliseconds.

Example: 'timeOut',200

Data Types: double

Output Arguments

expand all

events — Event queue contentsdouble | structure

Event queue contents, returned as a double or structure.

If the event queue contains events, events is a structure containing the current contents of the event queue. Otherwise, events is an empty double.

When the name-value pair argument 'useDefaultEventHandler' or the same field for the structure options is set to false, events is an empty double.

subs — Bloomberg EMSX subscription listsubscription list object

Bloomberg EMSX subscription list, returned as a Bloomberg EMSX subscription list object.

More About

expand all

Tips

  • For details about Bloomberg EMSX, see the EMSX API Programmer's Guide using the WAPI <GO> option from the Bloomberg terminal.

  • Suppose you create a custom event handler function called eventhandler with input argument c. Run eventhandler using this code.

    t = timer('TimerFcn',{@eventhandler,c},'Period',1,...
              'ExecutionMode','fixedRate')
    

    t is the MATLAB® timer object. For details, see timer.

Was this topic helpful?