Main Content

Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface

This example shows how to connect to Bloomberg® EMSX with the Bloomberg EMSX C++ interface, set up an order and route subscription, create and route an order, and interact with the route.

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

Connect to Bloomberg EMSX

Connect to the Bloomberg EMSX test service using the Bloomberg EMSX C++ interface.

c = bloombergEMSX('//blp/emapisvc_beta');
c = 
 
  bloombergEMSX with properties:

    Session: [1×1 datafeed.internal.BLPSession]
    Service: '//blp/emapisvc_beta'
    Ipaddress: "111.222.333.44"
    Port: 8194.00
    User: []

MATLAB® returns c as the connection to the Bloomberg EMSX test service with the following:

  • Bloomberg EMSX session object

  • Bloomberg EMSX service object

  • IP address of the machine running the Bloomberg EMSX test service

  • Port number of the machine running the Bloomberg EMSX test service

Set Up Order and Route Subscription

Subscribe to order events using the Bloomberg EMSX connection c associated with these Bloomberg EMSX fields.

fields = {'EMSX_TICKER','EMSX_AMOUNT','EMSX_FILL'};

events = orders(c,fields)
events = 

                       MSG_TYPE: {'E'}
                   MSG_SUB_TYPE: {'O'}
                   EVENT_STATUS: 4
                   ...

events contains fields for the events associated with the existing Bloomberg EMSX orders.

Subscribe to route events for the Bloomberg EMSX fields EMSX_BROKER and EMSX_WORKING using the Bloomberg EMSX connection c. Return the status for existing routes.

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

events = routes(c,fields)
events = 

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

events contains fields for the events currently in the event queue.

Create and Route Order

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 and route the order using the Bloomberg EMSX connection c and the order request structure order.

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. createOrderAndRoute returns events as a structure that contains these fields:

  • Bloomberg EMSX order number

  • Bloomberg EMSX route identifier

  • Bloomberg EMSX message

Modify Route

Define the modroute structure that contains these fields:

  • Bloomberg EMSX order sequence number EMSX_SEQUENCE

  • Bloomberg EMSX ticker symbol EMSX_TICKER

  • Bloomberg EMSX number of shares EMSX_AMOUNT

  • Bloomberg EMSX route identifier EMSX_ROUTE_ID

This code modifies the route to 50 shares of IBM for order sequence number 335877 and route identifier 1. Convert the numbers to 32-bit signed integers using int32.

modroute.EMSX_SEQUENCE = int32(335877)
modroute.EMSX_TICKER = 'IBM';
modroute.EMSX_AMOUNT = int32(50);
modroute.EMSX_ROUTE_ID = int32(1);

Modify the route using the Bloomberg EMSX connection c and modify route request modroute.

events = modifyRoute(c,modroute)
events = 
    
    EMSX_SEQUENCE: 0
    EMSX_ROUTE_ID: 0
          MESSAGE: 'Route modified'

The default event handler processes the events associated with modifying a route. modifyRoute returns events as a structure that contains these fields:

  • Bloomberg EMSX order number

  • Bloomberg EMSX route identifier

  • Bloomberg EMSX message

Delete Route

Define the structure routenum that contains the order sequence number EMSX_SEQUENCE for the routed order and route number EMSX_ROUTE_ID.

routenum.EMSX_SEQUENCE = 0;
routenum.EMSX_ROUTE_ID = 0;

Delete the route using the Bloomberg EMSX connection c and delete route number structure routenum.

events = deleteRoute(c,routenum)
events = 

     STATUS: '1'
    MESSAGE: 'Route cancellation request sent to broker'

The default event handler processes the events associated with deleting a route. deleteRoute returns events as a structure that contains these fields:

  • Bloomberg EMSX status

  • Bloomberg EMSX message

Stop Order and Route Subscription

Unsubscribe from order and route events using the Bloomberg EMSX subscriptions.

c.Session.stopSubscriptions

Close Bloomberg EMSX Connection

close(c)

See Also

Objects

Functions

Related Topics

External Websites