Main Content

createOrderAndRoute

Create and routeBloombergEMSX order

Description

example

events= createOrderAndRoute(c,order)creates and routes a Bloomberg®EMSX order using Bloomberg EMSX connectioncand order requestorder.createOrderAndRoutereturns the order sequence number, route number, and status message using the default event handler.

example

events= createOrderAndRoute(c,order,'timeOut',timeout)specifies a timeout valuetimeoutfor the execution of the default event handler.

example

createOrderAndRoute(___,'useDefaultEventHandler',false)creates and routes a Bloomberg EMSX order 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'totrueand use theeventsoutput argument. By default, the flag'useDefaultEventHandler'is set totrue.

example

___= createOrderAndRoute(c,order,options)uses theoptionsstructure to customize the output, which is useful to preconfigure and save your options for repeated use. The availableoptionsstructure fields aretimeOutanduseDefaultEventHandler. Use theeventsoutput argument whenuseDefaultEventHandleris set totrueand omit this output argument whenuseDefaultEventHandleris set tofalse.

Examples

collapse all

To create and route a Bloomberg EMSX order, create the connectioncusingemsxand set up the order and route subscription usingordersandroutes. For an example showing these activities, seeManage Bloomberg EMSX Order and Route.

Create the order request structureorder定义参数。这个公司de creates a buy market order for 100 shares of IBM®. This code uses the brokerBBwith the time in force set toDAYand any hand instruction. Convert the number of shares to a 32-bit signed integer usingint32.

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 and route the order using the Bloomberg EMSX connectioncandorder.

events = createOrderAndRoute(c,order)
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.createOrderAndRoutereturnseventsas 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 objectsosubsandrsubs. This code assumes thatorderscreatesosubsandroutescreatesrsubs.

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

Close the Bloomberg EMSX connection.

close(c)

To create and route a Bloomberg EMSX order, create the connectioncusingemsxand set up the order and route subscription usingordersandroutes. For an example showing these activities, seeManage Bloomberg EMSX Order and Route.

Create the order request structureorder定义参数。这个公司de creates a buy market order for 100 shares of IBM. This code uses the brokerBBwith the time in force set toDAYand any hand instruction. Convert the number of shares to a 32-bit signed integer usingint32.

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 and route the order using the Bloomberg EMSX connectioncandorder. Set the timeout value to 200 milliseconds.

events = createOrderAndRoute(c,order,'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.createOrderAndRoutereturnseventsas 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 objectsosubsandrsubs. This code assumes thatorderscreatesosubsandroutescreatesrsubs.

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

Close the Bloomberg EMSX connection.

close(c)

To create and route a Bloomberg EMSX order, create the Bloomberg EMSX connectioncusingemsxand set up the order and route subscription usingordersandroutes. For an example showing these activities, seeManage Bloomberg EMSX Order and Route.

Create the order request structureorder定义参数。这个公司de creates a buy market order for 100 shares of IBM. This code uses the brokerBBwith the time in force set toDAYand any hand instruction. Convert the number of shares to a 32-bit signed integer usingint32.

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';

Suppose you create a custom event handler function calledeventhandlerwith input argumentc. Runeventhandlerusingtimer. Start the timer to runeventhandlerimmediately usingstart. For details, seeWriting and Running Custom Event Handler Functions.

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

tis the MATLAB®timer object. For details, seetimer.

Create and route the order using the Bloomberg EMSX connectioncandorder. Set the flag'useDefaultEventHandler'tofalseso thateventhandlerprocesses the events associated with creating and routing an order.

createOrderAndRoute(c,order,'useDefaultEventHandler',false)

Unsubscribe from order and route events using the Bloomberg EMSX subscription list objectsosubsandrsubs. This code assumes thatorderscreatesosubsandroutescreatesrsubs. Stop the timer to stop data updates usingstop.

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

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

delete(t)

Close the Bloomberg EMSX connection.

close(c)

To create and route a Bloomberg EMSX order, create the connectioncusingemsxand set up the order and route subscription usingordersandroutes. For an example showing these activities, seeManage Bloomberg EMSX Order and Route.

Create the order request structureorder定义参数。这个公司de creates a buy market order for 100 shares of IBM. This code uses the brokerBBwith the time in force set toDAYand any hand instruction. Convert the number of shares to a 32-bit signed integer usingint32.

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 a structureoptions. To use the default event handler, set the fielduseDefaultEventHandlertotrue. Set the fieldtimeOutto 200 milliseconds. Create and route the order using the Bloomberg EMSX connectionc,order, and options structureoptions.

options.useDefaultEventHandler = true; options.timeOut = 200; events = createOrderAndRoute(c,order,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.createOrderAndRoutereturnseventsas 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 objectsosubsandrsubs. This code assumes thatorderscreatesosubsandroutescreatesrsubs.

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 usingemsx.

Order request, specified as a structure using Bloomberg EMSX field properties. UsegetAllFieldMetaDatato view all available field property options fororder. Convert the number of shares to a 32-bit signed integer usingint32.ordercontains 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

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 theoptionsstructure.

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,eventsis a structure containing the current contents of the event queue. Otherwise,eventsis an empty double.

Version History

Introduced in R2013a