Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Writing and Running Custom Event Handler Functions with Bloomberg EMSX

Write a Custom Event Handler Function

You can process events related to any Bloomberg® EMSX orders and routes by writing a custom event handler function to use with Trading Toolbox™. For example, you can plot the changes in the number of shares routed. Follow these tasks to write a custom event handler.

  1. Choose the events that you want to process, monitor, or evaluate.

  2. Decide how the custom event handler function processes these events.

  3. Determine the input and output arguments for the custom event handler function.

  4. Write the code for the custom event handler function.

For details, see Create Functions in Files (MATLAB). For a code example of an event handler function, enter edit emsxOrderBlotter.m at the command line. Then, see the function processEventToBlotter in this file.

Run a Custom Event Handler Function

You can run the custom event handler function by using timer. Specify the custom event handler function name as a function handle and pass this function handle as an input argument to timer. For details about function handles, see Create Function Handle (MATLAB). For example, suppose you want to create an order using createOrderAndRoute with the custom event handler function named eventhandler. This code assumes a Bloomberg EMSX connection c, Bloomberg EMSX order order, and timer object t.

  1. Run timer to execute eventhandler. The name-value pair argument TimerFcn specifies the event handler function. The name-value pair argument Period specifies a 1-second delay between executions of the event handler function. When the name-value pair argument ExecutionMode is set to fixedRate, the event handler function executes immediately after it is added to the MATLAB® execution queue.

    t = timer('TimerFcn',{@c.eventhandler},'Period',1,...
              'ExecutionMode','fixedRate');
    
  2. Start the timer to initiate and execute eventhandler immediately.

    start(t)
    
  3. Run createOrderAndRoute using the custom event handler by setting useDefaultEventHandler to false.

    createOrderAndRoute(c,order,'useDefaultEventHandler',false)
    
  4. Stop the timer to stop data updates.

    stop(t)
    

    If you want to resume data updates, run start.

  5. Delete the timer once you are done with processing data updates for the Bloomberg EMSX connection.

    delete(t)

Workflow for Custom Event Handler Function

This workflow summarizes the tasks to work with a custom event handler function using Bloomberg EMSX.

  1. Write a custom event handler function and save it to a file.

  2. Create a connection using emsx.

  3. Subscribe to Bloomberg EMSX fields using orders and routes. You can also write custom event handler functions to process subscription events.

  4. Run the custom event handler function using timer. Use a function handle to specify the custom event handler function name to run timer.

  5. Start the timer to execute the custom event handler function immediately using start.

  6. Stop data updates using stop.

  7. Unsubscribe from Bloomberg EMSX fields by using the API syntax.

  8. Delete the timer using delete.

  9. Close the connection using close.

See Also

| | | | | | | |

Related Examples

More About

Was this topic helpful?