Create and Manage Bloomberg EMSX Order
This example shows how to connect to Bloomberg® EMSX, create an order, and interact with the order.
For details about Bloomberg EMSX, see the EMSX API Programmer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
Connect to Bloomberg EMSX
Connect to the Bloomberg EMSX test service. Display the current event queue contents using
processEvent
.
c = emsx('//blp/emapisvc_beta');
processEvent(c)
c = emsx with properties: Session: [1x1 com.bloomberglp.blpapi.Session] Service: [1x1 com.bloomberglp.blpapi.impl.aQ] Ipaddress: 'localhost' Port: 8194 SessionConnectionUp = { server = localhost/127.0.0.1:8194 } SessionStarted = { } ServiceOpened = { serviceName = //blp/emapisvc_beta }
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
processEvent
displays events associated with connecting
to Bloomberg EMSX.
Set Up Order Subscription
Subscribe to order events using the Bloomberg EMSX connection c
associated with these
Bloomberg EMSX fields.
fields = {'EMSX_TICKER','EMSX_AMOUNT','EMSX_FILL'}; [events,subs] = orders(c,fields)
events = MSG_TYPE: {'E'} MSG_SUB_TYPE: {'O'} EVENT_STATUS: 4 ... subs = com.bloomberglp.blpapi.SubscriptionList@4bc3dc78
events
contains fields for the events associated with the
existing Bloomberg EMSX orders. subs
contains the Bloomberg EMSX subscription list object.
Create Order
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 the order using the Bloomberg EMSX connection c
and the order request
structure order
.
events = createOrder(c,order)
order_events = EMSX_SEQUENCE: 354646 MESSAGE: 'Order created'
The default event handler processes the events associated with creating the
order. createOrder
returns events
as a
structure that contains these fields:
Bloomberg EMSX order number
Bloomberg EMSX message
Modify Order
Define the structure modorder
that contains these fields:
Bloomberg EMSX order sequence number
EMSX_SEQUENCE
Bloomberg EMSX ticker symbol
EMSX_TICKER
Bloomberg EMSX number of shares
EMSX_AMOUNT
This code modifies order number 354646
for 200
shares of IBM. Convert the numbers to 32-bit signed integers using
int32
.
modorder.EMSX_SEQUENCE = int32(354646);
modorder.EMSX_TICKER = 'IBM';
modorder.EMSX_AMOUNT = int32(200);
Modify the order using the Bloomberg EMSX connection c
and modify order structure
modorder
.
events = modifyOrder(c,modorder)
events = EMSX_SEQUENCE: 354646 MESSAGE: 'Order Modified'
The default event handler processes the events associated with modifying an
order. modifyOrder
returns events
as a
structure that contains these fields:
Bloomberg EMSX order number
Bloomberg EMSX message
Delete Order
Define the structure ordernum
that contains the order
sequence number 354646
for the order to delete. Delete the
order using the Bloomberg EMSX connection c
and the delete order number
structure ordernum
.
ordernum.EMSX_SEQUENCE = 354646; events = deleteOrder(c,ordernum)
events = STATUS: '0' MESSAGE: 'Order deleted'
The default event handler processes the events associated with deleting an
order. deleteOrder
returns events
as a
structure that contains these fields:
Bloomberg EMSX status
Bloomberg EMSX message
Stop Order Subscription
Unsubscribe from order events using the Bloomberg EMSX subscription list object subs
.
c.Session.unsubscribe(subs)
Close Bloomberg EMSX Connection
close(c)
See Also
emsx
| close
| createOrder
| orders
| modifyOrder
| deleteOrder
Related Examples
- Create Order Using Bloomberg EMSX
- Create and Manage Bloomberg EMSX Route
- Manage Bloomberg EMSX Order and Route