Main Content

Create Order Using Bloomberg EMSX

This example shows how to connect to Bloomberg® EMSX and create and route a market order.

For details about connecting to Bloomberg EMSX and creating orders, see the EMSX API Programmer’s Guide.

Connect to Bloomberg EMSX

  1. If you are using emsx for the first time, install a Java® archive file from Bloomberg for emsx and other Bloomberg commands to work correctly.

    If you already have blpapi3.jar downloaded from Bloomberg, you can find it in your Bloomberg folders at ..\blp\api\APIv3\JavaAPI\lib\blpapi3.jar or ..\blp\api\APIv3\JavaAPI\v3.x\lib\blpapi3.jar. If you have blpapi3.jar, go to step 3.

    If blpapi3.jar is not downloaded from Bloomberg, then download it as follows:

    1. In your Bloomberg terminal, type WAPI {GO} to open the API Developer’s Help Site screen.

    2. Click API Download Center, then click Desktop API.

    3. After downloading blpapi3.jar on your system, add it to the MATLAB® Java class path using the javaaddpath function.

      Execute the javaaddpath function for every session of MATLAB. To avoid executing the javaaddpath function at every session, add javaaddpath to your startup.m file or add the full path for blpapi3.jar to your javaclasspath.txt file. For details about javaclasspath.txt, see Java Class Path. For details about editing your startup.m file, see Startup Options in MATLAB Startup File.

  2. Connect to the Bloomberg EMSX test service.

    c = emsx('//blp/emapisvc_beta') 
    c = 
      emsx with properties:
          Session: [1x1 com.bloomberglp.blpapi.Session]
          Service: [1x1 com.bloomberglp.blpapi.impl.aQ]
        Ipaddress: 'localhost'
             Port: 8194

    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

Create Market Order Request

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_SIDE = 'BUY';
order.EMSX_TICKER = 'IBM';
order.EMSX_AMOUNT = int32(400);
order.EMSX_TIF = 'DAY';

Create and Route Market Order

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

events = createOrderAndRoute(c,order)
events = 
    EMSX_SEQUENCE: 335877
          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

Close Bloomberg EMSX Connection


See Also

| |

Related Examples

More About

External Websites