Create and ManageBloombergEMSX Order
This example shows how to connect to Bloomberg®EMSX, create an order, and interact with the order.
For details about Bloomberg EMSX, see theEMSX API Programmer’s Guideusing theWAPI
Connect toBloombergEMSX
Connect to the Bloomberg EMSX test service. Display the current event queue contents usingprocessEvent
。
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®returnsc
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 connectionc
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.潜艇
contains the Bloomberg EMSX subscription list object.
Create Order
创建一个订单请求结构order
for a buy market order of 400 shares of IBM®。指定代理EFIX
, use any hand instruction, and set the time in force toDAY
。
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 connectionc
and the order request structureorder
。
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
returnsevents
as a structure that contains these fields:
Bloomberg EMSX order number
Bloomberg EMSX message
Modify Order
Define the structuremodorder
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 number354646
for 200 shares of IBM. Convert the numbers to 32-bit signed integers usingint32
。
modorder.EMSX_SEQUENCE = int32(354646); modorder.EMSX_TICKER ='IBM'; modorder.EMSX_AMOUNT = int32(200);
Modify the order using the Bloomberg EMSX connectionc
and modify order structuremodorder
。
events = modifyOrder(c,modorder)
events = EMSX_SEQUENCE: 354646 MESSAGE: 'Order Modified'
The default event handler processes the events associated with modifying an order.modifyOrder
returnsevents
as a structure that contains these fields:
Bloomberg EMSX order number
Bloomberg EMSX message
Delete Order
Define the structureordernum
that contains the order sequence number354646
for the order to delete. Delete the order using the Bloomberg EMSX connectionc
and the delete order number structureordernum
。
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
returnsevents
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潜艇
。
c.Session.unsubscribe(subs)
CloseBloombergEMSX 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