Main Content

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 option from the Bloomberg terminal.

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®returnscas 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

processEventdisplays events associated with connecting to Bloomberg EMSX.

Set Up Order Subscription

Subscribe to order events using the Bloomberg EMSX connectioncassociated 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

eventscontains fields for the events associated with the existing Bloomberg EMSX orders.潜艇contains the Bloomberg EMSX subscription list object.

Create Order

创建一个订单请求结构orderfor 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 connectioncand 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.createOrderreturnseventsas a structure that contains these fields:

  • Bloomberg EMSX order number

  • Bloomberg EMSX message

Modify Order

Define the structuremodorderthat contains these fields:

  • Bloomberg EMSX order sequence numberEMSX_SEQUENCE

  • Bloomberg EMSX ticker symbolEMSX_TICKER

  • Bloomberg EMSX number of sharesEMSX_AMOUNT

This code modifies order number354646for 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 connectioncand 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.modifyOrderreturnseventsas a structure that contains these fields:

  • Bloomberg EMSX order number

  • Bloomberg EMSX message

Delete Order

Define the structureordernumthat contains the order sequence number354646for the order to delete. Delete the order using the Bloomberg EMSX connectioncand 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.deleteOrderreturnseventsas 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

|||||

Related Examples

More About

External Websites