Main Content

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

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

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

Create Order

Create an order request structure order for a buy market order of 400 shares of IBM®. Specify the broker as EFIX, use any hand instruction, and set the time in force to DAY.

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

Create the order using the Bloomberg EMSX connection c and the order request structure order.

events = createOrder(c,order)
order_events = 
    
		EMSX_SEQUENCE: 354646
		      MESSAGE: 'Order created'

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

  • Bloomberg EMSX order number

  • Bloomberg EMSX message

Modify Order

Define the structure modorder that contains these fields:

  • Bloomberg EMSX order sequence number EMSX_SEQUENCE

  • Bloomberg EMSX ticker symbol EMSX_TICKER

  • Bloomberg EMSX number of shares EMSX_AMOUNT

This code modifies order number 354646 for 200 shares of IBM. Convert the numbers to 32-bit signed integers using int32.

modorder.EMSX_SEQUENCE = int32(354646);
modorder.EMSX_TICKER = 'IBM';
modorder.EMSX_AMOUNT = int32(200);

Modify the order using the Bloomberg EMSX connection c and modify order structure modorder.

events = modifyOrder(c,modorder)
events = 

    EMSX_SEQUENCE: 354646
          MESSAGE: 'Order Modified'

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

  • Bloomberg EMSX order number

  • Bloomberg EMSX message

Delete Order

Define the structure ordernum that contains the order sequence number 354646 for the order to delete. Delete the order using the Bloomberg EMSX connection c and the delete order number structure ordernum.

ordernum.EMSX_SEQUENCE = 354646;

events = deleteOrder(c,ordernum)
events = 
    
      STATUS: '0'
     MESSAGE: 'Order deleted'

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

  • Bloomberg EMSX status

  • Bloomberg EMSX message

Stop Order Subscription

Unsubscribe from order events using the Bloomberg EMSX subscriptions.

c.Session.stopSubscriptions

Close Bloomberg EMSX Connection

close(c)

See Also

Objects

Functions

Related Topics

External Websites