Documentation Center

  • Trial Software
  • Product Updates

Bloomberg EMSX Order Management

This example shows how to connect to a Bloomberg® EMSX service, set up an order subscription, and create and manage an order.

Connect to Bloomberg EMSX.

b = emsx('//blp/emapisvc_beta');
processEvent(b)
SessionConnectionUp = {
    server = localhost/127.0.0.1:8194
}

SessionStarted = {
}

ServiceOpened = {
    serviceName = //blp/emapisvc_beta
}

Set up the order subscription.

r = b.orders({'EMSX_TICKER','EMSX_AMOUNT','EMSX_FILL'})
r = 

                       MSG_TYPE: {'E'}
                   MSG_SUB_TYPE: {'O'}
                   EVENT_STATUS: 4
                    API_SEQ_NUM: 1
                  EMSX_SEQUENCE: 342481
                  EMSX_ROUTE_ID: 0
                   EMSX_FILL_ID: 0
                      EMSX_SIDE: {''}
                    EMSX_AMOUNT: 300
                    EMSX_FILLED: 0
                 EMSX_AVG_PRICE: 0
                    EMSX_BROKER: {''}
                   EMSX_WORKING: 0
                    EMSX_TICKER: {'IBM US Equity'}

                  ...           

Create the request structure.

Create the request for the specific buy order for IBM® stock.

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

% For limit orders, limit price can be set
% reqStruct.EMSX_LIMIT_PRICE = 150;

Create the order.

Create a new order.

rCreateOrder = b.createOrder(reqStruct)
rCreateOrder = 

    EMSX_SEQUENCE: 344700
          MESSAGE: 'Order created'

Get the order status.

b.getOrderInfo(344700)
rOrderStatus1 = 

               EMSX_TICKER: 'IBM'
             EMSX_EXCHANGE: 'US'
                 EMSX_SIDE: 'BUY'
             EMSX_POSITION: 'BUY'
             EMSX_PORT_MGR: 'CF'
               EMSX_TRADER: 'CF'
                EMSX_NOTES: ''
               EMSX_AMOUNT: 400
          EMSX_IDLE_AMOUNT: 0
              EMSX_WORKING: 200
               EMSX_FILLED: 200
            EMSX_TS_ORDNUM: 200
          EMSX_LIMIT_PRICE: 0
            EMSX_AVG_PRICE: 189.5900
                 EMSX_FLAG: 2
             EMSX_SUB_FLAG: 0
           EMSX_YELLOW_KEY: 'Equity'
          EMSX_BASKET_NAME: ''
    EMSX_ORDER_CREATE_DATE: '12/06/12'
    EMSX_ORDER_CREATE_TIME: '14:28:37'
           EMSX_ORDER_TYPE: 'MKT'
                  EMSX_TIF: 'DAY'
               EMSX_BROKER: 'BB'
          EMSX_TRADER_UUID: '1244972'
      EMSX_STEP_OUT_BROKER: ''

Modify the order.

Change the properties for an existing order and then route the order.

modStruct.EMSX_SEQUENCE = rCreateOrder.EMSX_SEQUENCE;
modStruct.EMSX_TICKER = 'IBM';
modStruct.EMSX_AMOUNT = int32(300);
rModifyOrder = b.modifyOrder(modStruct)

%Route order
% routeStruct.EMSX_AMOUNT = modStruct.EMSX_AMOUNT;
% routeStruct.EMSX_SEQUENCE = rModifyOrder.EMSX_SEQUENCE;
% routeStruct.EMSX_TICKER = reqStruct.EMSX_TICKER;
% routeStruct.EMSX_ORDER_TYPE = reqStruct.EMSX_ORDER_TYPE;
% routeStruct.EMSX_BROKER = reqStruct.EMSX_BROKER;
% routeStruct.EMSX_TIF = reqStruct.EMSX_TIF;
% routeStruct.EMSX_HAND_INSTRUCTION = reqStruct.EMSX_HAND_INSTRUCTION;
% routeStruct.EMSX_ODD_LOT = '-1';
% routeStruct.EMSX_CFD_FLAG = '-1';
% routeStruct.EMSX_RELEASE_TIME = '-1';
% rRouteOrder = b.routeOrder(routeStruct);
rModifyOrder = 

    EMSX_SEQUENCE: 344700
          MESSAGE: 'Order Modified'

Get the modified order status.

rOrderStatus2 = b.getOrderInfo(344700)
rOrderStatus2 =

               EMSX_TICKER: 'IBM'
             EMSX_EXCHANGE: 'US'
                 EMSX_SIDE: 'BUY'
             EMSX_POSITION: 'BUY'
             EMSX_PORT_MGR: 'CF'
               EMSX_TRADER: 'CF'
                EMSX_NOTES: ''
               EMSX_AMOUNT: 300
          EMSX_IDLE_AMOUNT: 0
              EMSX_WORKING: 200
               EMSX_FILLED: 100
            EMSX_TS_ORDNUM: 200
          EMSX_LIMIT_PRICE: 0
            EMSX_AVG_PRICE: 189.5900
                 EMSX_FLAG: 2
             EMSX_SUB_FLAG: 0
           EMSX_YELLOW_KEY: 'Equity'
          EMSX_BASKET_NAME: ''
    EMSX_ORDER_CREATE_DATE: '12/06/12'
    EMSX_ORDER_CREATE_TIME: '14:28:37'
           EMSX_ORDER_TYPE: 'MKT'
                  EMSX_TIF: 'DAY'
               EMSX_BROKER: 'BB'
          EMSX_TRADER_UUID: '1244972'
      EMSX_STEP_OUT_BROKER: ''

Delete the order (if necessary).

The structure returned from the createOrder call can be used as the input to delete the order or you can create a new structure where the field EMSX_SEQUENCE contains the order number to be canceled.

delStruct.EMSX_SEQUENCE = rCreateOrder.EMSX_SEQUENCE;
rDeleteOrder = b.deleteOrder(delStruct)
rDeleteOrder = 

     STATUS: '0'
    MESSAGE: 'Order deleted'

Close the connection.

close(b)
processEvent(b)
SessionConnectionDown = {
    server = localhost/127.0.0.1:8194
}

See Also

| | | |

Related Examples

More About

Was this topic helpful?