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.
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:
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
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 (MATLAB).
For details about editing your startup.m
file,
see Startup Options in MATLAB Startup File (MATLAB).
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 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 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(c)
close
| createOrderAndRoute
| emsx