Create and Manage Bloomberg EMSX Route Using Bloomberg EMSX C++ Interface
This example shows how to connect to Bloomberg® EMSX with the Bloomberg EMSX C++ interface, set up a 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 Route Subscription
Set up the route subscription for 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 Modified Route
Define the structure routenum
that contains the order sequence
number EMSX_SEQUENCE
and the route number
EMSX_ROUTE_ID
associated with the modified route.
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 Route Subscription
Unsubscribe from route events using the Bloomberg EMSX subscriptions.
c.Session.stopSubscriptions
Close Bloomberg EMSX Connection
close(c)
See Also
Objects
Functions
Related Topics
- Create Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface
- Create and Manage Bloomberg EMSX Order Using Bloomberg EMSX C++ Interface
- Manage Bloomberg EMSX Order and Route Using Bloomberg EMSX C++ Interface