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
If you are using
emsx
for the first time, install a Java® archive file from Bloomberg foremsx
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 haveblpapi3.jar
, go to step 3.If
blpapi3.jar
is not downloaded from Bloomberg, then download it as follows:In your Bloomberg terminal, type
WAPI {GO}
to open the API Developer’s Help Site screen.Click API Download Center, then click Desktop API.
After downloading
blpapi3.jar
on your system, add it to the MATLAB® Java class path using thejavaaddpath
function.Execute the
javaaddpath
function for every session of MATLAB. To avoid executing thejavaaddpath
function at every session, addjavaaddpath
to yourstartup.m
file or add the full path forblpapi3.jar
to yourjavaclasspath.txt
file. For details aboutjavaclasspath.txt
, see Java Class Path. For details about editing yourstartup.m
file, see Startup Options in MATLAB Startup File.
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_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 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 EMSX_ROUTE_ID: 1 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
close(c)
See Also
emsx
| createOrderAndRoute
| close
Related Examples
- Create and Manage Bloomberg EMSX Order
- Create and Manage Bloomberg EMSX Route
- Manage Bloomberg EMSX Order and Route