Documentation Center

  • Trial Software
  • Product Updates

Bloomberg EMSX Order and Route Management

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

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 and route subscription.

o = b.orders({'EMSX_TICKER','EMSX_AMOUNT','EMSX_FILL'})
r = b.routes({'EMSX_BROKER','EMSX_WORKING'})
o = 

                       MSG_TYPE: {4x1 cell}
                   MSG_SUB_TYPE: {4x1 cell}
                   EVENT_STATUS: [4x1 int32]
                    API_SEQ_NUM: [4x1 int64]
                  EMSX_SEQUENCE: [4x1 int32]
                  EMSX_ROUTE_ID: [4x1 int32]
                   EMSX_FILL_ID: [4x1 int32]
                      EMSX_SIDE: {4x1 cell}
                    EMSX_AMOUNT: [4x1 int32]
                    EMSX_FILLED: [4x1 int32]
                 EMSX_AVG_PRICE: [4x1 double]
                    EMSX_BROKER: {4x1 cell}
                   EMSX_WORKING: [4x1 int32]
                    EMSX_TICKER: {4x1 cell}
                  EMSX_EXCHANGE: {4x1 cell}

                  ...

r = 

                       MSG_TYPE: {2x1 cell}
                   MSG_SUB_TYPE: {2x1 cell}
                   EVENT_STATUS: [2x1 int32]
                    API_SEQ_NUM: [2x1 int64]
                  EMSX_SEQUENCE: [2x1 int32]
                  EMSX_ROUTE_ID: [2x1 int32]
                   EMSX_FILL_ID: [2x1 int32]
                      EMSX_SIDE: {2x1 cell}
                    EMSX_AMOUNT: [2x1 int32]
                    EMSX_FILLED: [2x1 int32]
                 EMSX_AVG_PRICE: [2x1 double]
                    EMSX_BROKER: {2x1 cell}
                   EMSX_WORKING: [2x1 int32]
                    EMSX_TICKER: {2x1 cell}

                  ...              

Create the request structure.

Create a request for a 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 and route.

Create an order and route for execution.

rCreateOrderAndRoute = b.createOrderAndRoute(reqStruct)
rCreateOrderAndRoute = 

    EMSX_SEQUENCE: 344705
    EMSX_ROUTE_ID: 1
          MESSAGE: 'Order created and routed'   

Get the order status.

rOrderStatus1 = b.getOrderInfo(rCreateOrderAndRoute.EMSX_SEQUENCE) 
rOrderStatus1 = 

               EMSX_TICKER: 'IBM'
             EMSX_EXCHANGE: 'US'
                 EMSX_SIDE: 'BUY'
             EMSX_POSITION: 'BUY'
             EMSX_PORT_MGR: 'CG'
               EMSX_TRADER: 'CG'
                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'

Get the route status.

routeStat.EMSX_SEQUENCE = rCreateOrderAndRoute.EMSX_SEQUENCE
routeStat.EMSX_ROUTE_ID = rCreateOrderAndRoute.EMSX_ROUTE_ID

rRouteStatus1 = b.getRouteInfo(routeStat)
rRouteStatus1 = 

                 EMSX_AVG_PRICE: 189.5900
                     EMSX_YIELD: 0
         EMSX_ROUTE_CREATE_DATE: 20121206
         EMSX_ROUTE_CREATE_TIME: 142837
    EMSX_ROUTE_LAST_UPDATE_DATE: 20121206
    EMSX_ROUTE_LAST_UPDATE_TIME: 142838
               EMSX_SETTLE_DATE: 20121211
                    EMSX_AMOUNT: 400
                    EMSX_FILLED: 200
           EMSX_IS_MANUAL_ROUTE: 0
                    EMSX_BROKER: 'BB'
                   EMSX_ACCOUNT: ''
                 EMSX_STATUS_ID: 51088
                    EMSX_STATUS: 'PtlFil'
          EMSX_HAND_INSTRUCTION: 'ANY'
                EMSX_ORDER_TYPE: 'MKT'
                       EMSX_TIF: 'DAY'
                    EMSX_LOC_ID: ''
                EMSX_LOC_BROKER: 'DAY'
                EMSX_STOP_PRICE: 0
              EMSX_BLOT_SEQ_NUM: 1
                 EMSX_BLOT_DATE: 20121206
                 EMSX_COMM_TYPE: 'DAY'
                 EMSX_COMM_RATE: 0
          EMSX_USER_COMM_AMOUNT: 0
                 EMSX_LSTTR2ID0: 1.3548e+09
                 EMSX_LSTTR2ID1: 284950536
               EMSX_LIMIT_PRICE: 0

Modify the order on route.

Modify the previously routed order.

modStruct.EMSX_SEQUENCE = rCreateOrderAndRoute.EMSX_SEQUENCE;
modStruct.EMSX_ROUTE_ID = rCreateOrderAndRoute.EMSX_ROUTE_ID;
modStruct.EMSX_TICKER = 'IBM';
modStruct.EMSX_AMOUNT = int32(250);
modStruct.EMSX_ORDER_TYPE = 'MKT';
modStruct.EMSX_TIF = 'DAY';
rModifyRoute = b.modifyRoute(modStruct)
rModifyRoute = 

    EMSX_SEQUENCE: 0
    EMSX_ROUTE_ID: 0
          MESSAGE: 'Route modified'

Delete order.

The structure returned from the createOrderAndRoute 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 = rCreateOrderAndRoute.EMSX_SEQUENCE;
delStruct.EMSX_ROUTE_ID = rCreateOrderAndRoute.EMSX_ROUTE_ID;
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?