Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

groupRouteOrderWithStrat

Route multiple Bloomberg EMSX orders with strategies

Syntax

events = groupRouteOrderWithStrat(c,route,strat)
events = groupRouteOrderWithStrat(c,route,strat,'timeOut',timeout)
groupRouteOrderWithStrat(___,'useDefaultEventHandler',false)
___ = groupRouteOrderWithStrat(c,route,strat,options)

Description

example

events = groupRouteOrderWithStrat(c,route,strat) routes multiple Bloomberg® EMSX orders with strategies using the Bloomberg EMSX connection c, route request route, and strategy strat. routeOrderWithStrat returns the order sequence number, route number, and status message using the default event handler.

example

events = groupRouteOrderWithStrat(c,route,strat,'timeOut',timeout) specifies a timeout value timeout for the execution of the default event handler.

example

groupRouteOrderWithStrat(___,'useDefaultEventHandler',false) routes multiple Bloomberg EMSX orders with strategies using any of the input arguments in the previous syntaxes and a custom event handler. To process the events associated with routing orders, write a custom event handler. This syntax does not have an output argument because the custom event handler processes the contents of the event queue. If you want to use the default event handler instead, set the flag 'useDefaultEventHandler' to true and use the events output argument. By default, the flag 'useDefaultEventHandler' is set to true.

example

___ = groupRouteOrderWithStrat(c,route,strat,options) uses the options structure to customize the output, which is useful to preconfigure and save your options for repeated use. The available options structure fields are timeOut and useDefaultEventHandler. Use the events output argument when the flag useDefaultEventHandler is set to true and omit this output argument when useDefaultEventHandler is set to false.

Examples

collapse all

To route a Bloomberg EMSX order with strategies, create the connection c using emsx, set up the order subscription using orders, and create the order using createOrder. For an example showing these activities, see Create and Manage a Bloomberg EMSX Order. Set up the route subscription using routes.

Define the route request structure route. Convert the numbers to 32-bit signed integers using int32. This code specifies these route request fields:

  • Order numbers 335877 and 335878

  • Stock symbol IBM®

  • 100 percent of shares shown on the order to be routed

  • Broker BMTB

  • Any hand instruction

  • Time in force set to DAY

  • Market order type

route.EMSX_SEQUENCE = {int32(335877);int32(335878)};
route.EMSX_TICKER = 'IBM';
route.EMSX_AMOUNT_PERCENT = int32(100);
route.EMSX_BROKER = 'BMTB';
route.EMSX_HAND_INSTRUCTION = 'ANY';
route.EMSX_TIF = 'DAY';
route.EMSX_ORDER_TYPE = 'MKT';

Create the order strategies structure strat using the strategy SSP. Convert the field indicators to a 32-bit signed integer using int32.

strat.EMSX_STRATEGY_NAME = 'SSP';
strat.EMSX_STRATEGY_FIELD_INDICATORS = int32([0 0 0]);
strat.EMSX_STRATEGY_FIELDS = {'09:30:00','14:30:00',50};

Route the orders using the Bloomberg EMSX connection c, route, and strat.

events = groupRouteOrderWithStrat(c,route,strat)
events = 
 
     EMSX_SUCCESS_ROUTES: [1x1 struct]
      EMSX_FAILED_ROUTES: [1x1 struct]
                 MESSAGE: '1 of 1 Order(s) Routed'

   where

   events.EMSX_SUCCESS_ROUTES =

        EMSX_SEQUENCE: 335877
        EMSX_ROUTE_ID: 1

   and events.EMSX_FAILED_ROUTES =

        EMSX_SEQUENCE: 335878
           ERROR_CODE: 0
        ERROR_MESSAGE: {'Order 335878  View-only orders can not be routed'} 

The default event handler processes the events associated with routing the order. groupRouteOrderWithStrat returns events as a structure that contains these fields:

  • Bloomberg EMSX success routing structure, which contains the order number and route identifier for the orders that successfully routed

  • Bloomberg EMSX failed routing structure, which contains the order number, error code, and error message for the orders that failed to route

  • Bloomberg EMSX message

Unsubscribe from order and route events using the Bloomberg EMSX subscription list objects osubs and rsubs. This code assumes that orders creates osubs and routes creates rsubs.

c.Session.unsubscribe(osubs)
c.Session.unsubscribe(rsubs)

Close the Bloomberg EMSX connection.

close(c)

To route a Bloomberg EMSX order with strategies, create the connection c using emsx, set up the order subscription using orders, and create the order using createOrder. For an example showing these activities, see Create and Manage a Bloomberg EMSX Order. Set up the route subscription using routes.

Define the route request structure route. Convert the numbers to 32-bit signed integers using int32. This code specifies these route request fields:

  • Order numbers 335877 and 335878

  • Stock symbol IBM

  • 100 percent of shares shown on the order to be routed

  • Broker BMTB

  • Any hand instruction

  • Time in force set to DAY

  • Market order type

route.EMSX_SEQUENCE = {int32(335877);int32(335878)};
route.EMSX_TICKER = 'IBM';
route.EMSX_AMOUNT_PERCENT = int32(100);
route.EMSX_BROKER = 'BMTB';
route.EMSX_HAND_INSTRUCTION = 'ANY';
route.EMSX_TIF = 'DAY';
route.EMSX_ORDER_TYPE = 'MKT';

Create the order strategies structure strat using the strategy SSP. Convert the field indicators to a 32-bit signed integer using int32.

strat.EMSX_STRATEGY_NAME = 'SSP';
strat.EMSX_STRATEGY_FIELD_INDICATORS = int32([0 0 0]);
strat.EMSX_STRATEGY_FIELDS = {'09:30:00','14:30:00',50};

Route the orders using the Bloomberg EMSX connection c, route, and strat. Set the timeout value to 200 milliseconds.

events = groupRouteOrderWithStrat(c,route,strat,'timeOut',200)
events = 
 
     EMSX_SUCCESS_ROUTES: [1x1 struct]
      EMSX_FAILED_ROUTES: [1x1 struct]
                 MESSAGE: '1 of 1 Order(s) Routed'

   where

   events.EMSX_SUCCESS_ROUTES =

        EMSX_SEQUENCE: 335877
        EMSX_ROUTE_ID: 1

   and events.EMSX_FAILED_ROUTES =

        EMSX_SEQUENCE: 335878
           ERROR_CODE: 0
        ERROR_MESSAGE: {'Order 335878  View-only orders can not be routed'} 

The default event handler processes the events associated with routing the order. groupRouteOrderWithStrat returns events as a structure that contains these fields:

  • Bloomberg EMSX success routing structure, which contains the order number and route identifier for the orders that successfully routed

  • Bloomberg EMSX failed routing structure, which contains the order number, error code, and error message for the orders that failed to route

  • Bloomberg EMSX message

Unsubscribe from order and route events using the Bloomberg EMSX subscription list objects osubs and rsubs. This code assumes that orders creates osubs and routes creates rsubs.

c.Session.unsubscribe(osubs)
c.Session.unsubscribe(rsubs)

Close the Bloomberg EMSX connection.

close(c)

To route a Bloomberg EMSX order with strategies, create the connection c using emsx, set up the order subscription using orders, and create the order using createOrder. For an example showing these activities, see Create and Manage a Bloomberg EMSX Order. Set up the route subscription using routes.

Define the route request structure route. Convert the numbers to 32-bit signed integers using int32. This code specifies these route request fields:

  • Order numbers 335877 and 335878

  • Stock symbol IBM

  • 100 percent of shares shown on the order to be routed

  • Broker BMTB

  • Any hand instruction

  • Time in force set to DAY

  • Market order type

route.EMSX_SEQUENCE = {int32(335877);int32(335878)};
route.EMSX_TICKER = 'IBM';
route.EMSX_AMOUNT_PERCENT = int32(100);
route.EMSX_BROKER = 'BMTB';
route.EMSX_HAND_INSTRUCTION = 'ANY';
route.EMSX_TIF = 'DAY';
route.EMSX_ORDER_TYPE = 'MKT';

Create the order strategies structure strat using the strategy SSP. Convert the field indicators to a 32-bit signed integer using int32.

strat.EMSX_STRATEGY_NAME = 'SSP';
strat.EMSX_STRATEGY_FIELD_INDICATORS = int32([0 0 0]);
strat.EMSX_STRATEGY_FIELDS = {'09:30:00','14:30:00',50};

Suppose that you create a custom event handler function called eventhandler with input argument c. Run eventhandler using timer. To run eventhandler immediately, start the timer using start. For details, see Writing and Running Custom Event Handler Functions with Bloomberg EMSX.

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

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

Route the orders using the Bloomberg EMSX connection c, route, and strat. Set the flag 'useDefaultEventHandler' to false so that eventhandler processes the events associated with routing an order.

groupRouteOrderWithStrat(c,route,strat,'useDefaultEventHandler',false)

Unsubscribe from order and route events using the Bloomberg EMSX subscription list objects osubs and rsubs. This code assumes that orders creates osubs and routes creates rsubs. To stop data updates, stop the timer using stop.

c.Session.unsubscribe(osubs)
c.Session.unsubscribe(rsubs)
stop(t)

If you are done processing data updates, delete the timer using delete.

delete(t)

Close the Bloomberg EMSX connection.

close(c)

To route a Bloomberg EMSX order with strategies, create the connection c using emsx, set up the order subscription using orders, and create the order using createOrder. For an example showing these activities, see Create and Manage a Bloomberg EMSX Order. Set up the route subscription using routes.

Define the route request structure route. Convert the numbers to 32-bit signed integers using int32. This code specifies these route request fields:

  • Order numbers 335877 and 335878

  • Stock symbol IBM

  • 100 percent of shares shown on the order to be routed

  • Broker BMTB

  • Any hand instruction

  • Time in force set to DAY

  • Market order type

route.EMSX_SEQUENCE = {int32(335877);int32(335878)};
route.EMSX_TICKER = 'IBM';
route.EMSX_AMOUNT_PERCENT = int32(100);
route.EMSX_BROKER = 'BMTB';
route.EMSX_HAND_INSTRUCTION = 'ANY';
route.EMSX_TIF = 'DAY';
route.EMSX_ORDER_TYPE = 'MKT';

Create the order strategies structure strat using the strategy SSP. Convert the field indicators to a 32-bit signed integer using int32.

strat.EMSX_STRATEGY_NAME = 'SSP';
strat.EMSX_STRATEGY_FIELD_INDICATORS = int32([0 0 0]);
strat.EMSX_STRATEGY_FIELDS = {'09:30:00','14:30:00',50};

Create a structure options. To use the default event handler, set the field useDefaultEventHandler to true. Set the field timeOut to 200 milliseconds. Route the orders using the Bloomberg EMSX connection c, route, strat, and options structure options.

options.useDefaultEventHandler = true;
options.timeOut = 200;

events = groupRouteOrderWithStrat(c,route,strat,options)
events = 
 
     EMSX_SUCCESS_ROUTES: [1x1 struct]
      EMSX_FAILED_ROUTES: [1x1 struct]
                 MESSAGE: '1 of 1 Order(s) Routed'

   where

   events.EMSX_SUCCESS_ROUTES =

        EMSX_SEQUENCE: 335877
        EMSX_ROUTE_ID: 1

   and events.EMSX_FAILED_ROUTES =

        EMSX_SEQUENCE: 335878
           ERROR_CODE: 0
        ERROR_MESSAGE: {'Order 335878  View-only orders can not be routed'} 

The default event handler processes the events associated with routing the order. groupRouteOrderWithStrat returns events as a structure that contains these fields:

  • Bloomberg EMSX success routing structure, which contains the order number and route identifier for the orders that successfully routed

  • Bloomberg EMSX failed routing structure, which contains the order number, error code, and error message for the orders that failed to route

  • Bloomberg EMSX message

Unsubscribe from order and route events using the Bloomberg EMSX subscription list objects osubs and rsubs. This code assumes that orders creates osubs and routes creates rsubs.

c.Session.unsubscribe(osubs)
c.Session.unsubscribe(rsubs)

Close the Bloomberg EMSX connection.

close(c)

Input Arguments

collapse all

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

Route request, specified as a structure containing these fields.

Convert the numbers to 32-bit signed integers using int32. EMSX_SEQUENCE must denote an existing order sequence number.

Field

Description

EMSX_SEQUENCE

Bloomberg EMSX order sequence number

EMSX_TICKER

Bloomberg EMSX ticker symbol

EMSX_AMOUNT

Bloomberg EMSX number of shares

EMSX_BROKER

Bloomberg EMSX broker name

EMSX_HAND_INSTRUCTION

Bloomberg EMSX hand instruction

EMSX_TIF

Bloomberg EMSX time in force

EMSX_ORDER_TYPE

Bloomberg EMSX order type

Example: route.EMSX_SEQUENCE = int32(728918);
route.EMSX_TICKER = 'XYZ';
route.EMSX_AMOUNT = int32(100);
route.EMSX_BROKER = 'BB';
route.EMSX_HAND_INSTRUCTION = 'ANY';
route.EMSX_TIF = 'DAY';
route.EMSX_ORDER_TYPE = 'MKT';

Data Types: struct

Order strategies, specified as a structure that contains the fields: EMSX_STRATEGY_NAME, EMSX_STRATEGY_FIELD_INDICATORS, and EMSX_STRATEGY_FIELDS. The structure field values must align with the strategy fields specified by EMSX_STRATEGY_NAME. For details about strategy fields and ordering, see getBrokerInfo.

Convert EMSX_STRATEGY_FIELD_INDICATORS to a 32-bit signed integer using int32. Set EMSX_STRATEGY_FIELD_INDICATORS equal to 0 for each field to use the field data setting in EMSX_FIELD_DATA. Or, set EMSX_STRATEGY_FIELD_INDICATORS equal to 1 to ignore the data in EMSX_FIELD_DATA.

Example: strat.EMSX_STRATEGY_NAME = 'SSP';
strat.EMSX_STRATEGY_FIELD_INDICATORS = int32([0 0 0]);
strat.EMSX_STRATEGY_FIELDS = {'09:30:00','14:30:00',50};

Data Types: struct

Timeout value, specified as a nonnegative integer. This integer denotes the time in milliseconds the event handler listens to the queue for an event for each iteration of the code. The event handler can be a default or custom event handler.

Data Types: double

Options for custom event handler or timeout value, specified as a structure. To reuse the settings for specifying a custom event handler or timeout value for the event handler, use the options structure.

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

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

Data Types: struct

Output Arguments

collapse all

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.

Tips

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

Introduced in R2015b

Was this topic helpful?