Documentation Center

  • Trial Software
  • Product Updates

Bloomberg EMSX Route Management

This example shows how to connect to a Bloomberg® EMSX service, set up a route subscription, and create and manage a 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 route subscription.

rRouteStatus1 = b.routes({'EMSX_BROKER','EMSX_WORKING'})
rRouteStatus1 = 

                       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}

                   ...                  

Create the request structure.

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

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

% create and route order
rOrder = b.createOrderAndRoute(reqStruct)
rOrder = 

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

Check the route status:

routeStruct.EMSX_SEQUENCE = rOrder.EMSX_SEQUENCE
routeStruct.EMSX_ROUTE_ID = rOrder.EMSX_ROUTE_ID

rRouteStatus2 = b.getRouteInfo(routeStruct)
rRouteStatus2 =

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

Modify the properties for the previously created route.

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

Check the route status for the modified route.

rRouteStatus3 = b.getRouteInfo(routeStruct)
rRouteStatus3 = 

                 EMSX_AVG_PRICE: 189.7900
                     EMSX_YIELD: 0
         EMSX_ROUTE_CREATE_DATE: 20121206
         EMSX_ROUTE_CREATE_TIME: 142837
    EMSX_ROUTE_LAST_UPDATE_DATE: 20121206
    EMSX_ROUTE_LAST_UPDATE_TIME: 143251
               EMSX_SETTLE_DATE: 20121211
                    EMSX_AMOUNT: 250
                    EMSX_FILLED: 250
           EMSX_IS_MANUAL_ROUTE: 0
                    EMSX_BROKER: 'BB'
                   EMSX_ACCOUNT: ''
                 EMSX_STATUS_ID: 199032
                    EMSX_STATUS: 'Filled'
          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

Delete the route.

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

delStruct.EMSX_SEQUENCE = rOrder.EMSX_SEQUENCE;
delStruct.EMSX_ROUTE_ID = rOrder.EMSX_ROUTE_ID;
rDeleteRoute = b.deleteRoute(delStruct)
rDeleteRoute = 
  
      STATUS: '0'
     MESSAGE: 'Route 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?