Main Content

createOrderAndRouteWithStrat

Create and route Bloomberg EMSX order with strategies

Since R2021a

Description

events = createOrderAndRouteWithStrat(c,order,strat) creates and routes a Bloomberg® EMSX order with strategies using Bloomberg EMSX connection c and the Bloomberg EMSX C++ interface, order request order, and order strategy strat. createOrderAndRouteWithStrat returns the order sequence number, route number, and status message using the default event handler.

example

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

example

createOrderAndRouteWithStrat(___,'useDefaultEventHandler',false) creates and routes a Bloomberg EMSX order with strategies using any of the input arguments in the previous syntaxes and a custom event handler. Write a custom event handler to process the events associated with creating and routing orders. 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

___ = createOrderAndRouteWithStrat(c,order,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 useDefaultEventHandler is set to true and omit this output argument when useDefaultEventHandler is set to false.

example

Examples

collapse all

To create and route a Bloomberg EMSX order with strategies, create the connection c using emsx and set up the order and route subscription using orders and routes. For an example showing these activities, see Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface.

Create the order request structure order to define the order parameters. This code creates a buy market order for 100 shares of IBM®. This code uses the broker BB with the time in force set to DAY and any hand instruction. Convert the number of shares to a 32-bit signed integer using int32.

order.EMSX_TICKER = 'IBM';
order.EMSX_AMOUNT = int32(100);
order.EMSX_ORDER_TYPE = 'MKT';
order.EMSX_BROKER = 'BB';
order.EMSX_TIF = 'DAY';
order.EMSX_HAND_INSTRUCTION = 'ANY';
order.EMSX_SIDE = 'BUY';

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 and route the order with strategies using the Bloomberg EMSX connection c, order, and strat.

events = createOrderAndRouteWithStrat(c,order,strat)
events = 
    
    EMSX_SEQUENCE: 335877
    EMSX_ROUTE_ID: 1
          MESSAGE: 'Order created and routed' 

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

  • Bloomberg EMSX order number

  • Bloomberg EMSX route identifier

  • 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 create and route a Bloomberg EMSX order with strategies, create the connection c using emsx and set up the order and route subscription using orders and routes. For an example showing these activities, see Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface.

Create the order request structure order to define the order parameters. This code creates a buy market order for 100 shares of IBM. This code uses the broker BB with the time in force set to DAY and any hand instruction. Convert the number of shares to a 32-bit signed integer using int32.

order.EMSX_TICKER = 'IBM';
order.EMSX_AMOUNT = int32(100);
order.EMSX_ORDER_TYPE = 'MKT';
order.EMSX_BROKER = 'BB';
order.EMSX_TIF = 'DAY';
order.EMSX_HAND_INSTRUCTION = 'ANY';
order.EMSX_SIDE = 'BUY';

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 and route the order with strategies using the Bloomberg EMSX connection c, order, and strat. Set the timeout value to 200 milliseconds.

events = createOrderAndRouteWithStrat(c,order,strat,'timeOut',200)
events = 
    
    EMSX_SEQUENCE: 335877
    EMSX_ROUTE_ID: 1
          MESSAGE: 'Order created and routed' 

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

  • Bloomberg EMSX order number

  • Bloomberg EMSX route identifier

  • 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 create and route a Bloomberg EMSX order with strategies, create the Bloomberg EMSX connection c using emsx and set up the order and route subscription using orders and routes. For an example showing these activities, see Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface.

Create the order request structure order to define the order parameters. This code creates a buy market order for 100 shares of IBM. This code uses the broker BB with the time in force set to DAY and any hand instruction. Convert the number of shares to a 32-bit signed integer using int32.

order.EMSX_TICKER = 'IBM';
order.EMSX_AMOUNT = int32(100);
order.EMSX_ORDER_TYPE = 'MKT';
order.EMSX_BROKER = 'BB';
order.EMSX_TIF = 'DAY';
order.EMSX_HAND_INSTRUCTION = 'ANY';
order.EMSX_SIDE = 'BUY';

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 you create a custom event handler function called eventhandler with input argument c. Run eventhandler using timer. Start the timer to run eventhandler immediately using start. For details, see Writing and Running Custom Event Handler Functions.

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

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

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

createOrderAndRouteWithStrat(c,order,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. Stop the timer to stop data updates 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 create and route a Bloomberg EMSX order with strategies, create the connection c using emsx and set up the order and route subscription using orders and routes. For an example showing these activities, see Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface.

Create the order request structure order to define the order parameters. This code creates a buy market order for 100 shares of IBM. This code uses the broker BB with the time in force set to DAY and any hand instruction. Convert the number of shares to a 32-bit signed integer using int32.

order.EMSX_TICKER = 'IBM';
order.EMSX_AMOUNT = int32(100);
order.EMSX_ORDER_TYPE = 'MKT';
order.EMSX_BROKER = 'BB';
order.EMSX_TIF = 'DAY';
order.EMSX_HAND_INSTRUCTION = 'ANY';
order.EMSX_SIDE = 'BUY';

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. Create and route the order using the Bloomberg EMSX connection c, order, strat, and options structure options.

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

events = createOrderAndRouteWithStrat(c,order,strat,options)
events = 
    
    EMSX_SEQUENCE: 728924
    EMSX_ROUTE_ID: 1
          MESSAGE: 'Order created and routed'

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

  • Bloomberg EMSX order number

  • Bloomberg EMSX route identifier

  • 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 bloombergEMSX object.

Order request, specified as a structure using Bloomberg EMSX field properties. Use getAllFieldMetaData to view all available field property options for order. Convert the number of shares to a 32-bit signed integer using int32. order contains these fields.

Field

Description

EMSX_TICKER

Bloomberg EMSX ticker symbol

EMSX_AMOUNT

Bloomberg EMSX amount of shares

EMSX_ORDER_TYPE

Bloomberg EMSX order type

EMSX_BROKER

Bloomberg EMSX broker name

EMSX_TIF

Bloomberg EMSX time in force

EMSX_HAND_INSTRUCTION

Bloomberg EMSX hand instruction

EMSX_SIDE

Bloomberg EMSX buy or sell specification

Example: order.EMSX_TICKER = 'XYZ';
order.EMSX_AMOUNT = int32(100);
order.EMSX_ORDER_TYPE = 'MKT';
order.EMSX_BROKER = 'BB';
order.EMSX_TIF = 'DAY';
order.EMSX_HAND_INSTRUCTION = 'ANY';
order.EMSX_SIDE = 'BUY';

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, that the event handler listens to the event queue for each iteration of the code. The event handler can be a default or custom event handler.

Data Types: double

Options for a 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.

For example, specify using a custom event handler and a timeout value of 200 milliseconds.

options.useDefaultEventHandler = false;
options.timeOut = 200;

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.

Version History

Introduced in R2021a