主要内容

编写和运行自定义事件处理程序功能

Write Custom Event Handler Function

You can process events related to any data updates by writing a custom event handler function for use with Datafeed Toolbox™. For example, you can monitor prices before creating an order or plot interval data in a graph. Follow these basic steps to write a custom event handler.

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

  2. 确定自定义事件处理程序如何处理这些事件。

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

  4. 编写自定义事件处理程序功能的代码。

For details, seeCreate Functions in Files。For a code example of a Bloomberg®event handler function, enter编辑v3stockticker.mat the command line.

运行自定义事件处理程序功能

You can run the custom event handler function by passing the function name as an input argument into an existing function. Specify the custom event handler function name either as a character vector, string, or function handle. For details about function handles, seeCreate Function Handle

For example, suppose you want to retrieve real-time data from Bloomberg using即时的with the custom event handler function namedeventhandler。You can use either of the following syntaxes to runeventhandler。This code assumes a Bloomberg connectionc, security lists,彭博数据字段f, Bloomberg subscriptionsubs, and MATLAB®计时器t

Use a character vector or string.

[subs,t] = realtime(c,s,f,'eventhandler');

Alternatively, use a function handle.

[subs,t] =实时(c,s,f,@eventhandler);

对于Bloomberg EMSX界面,您可以使用使用自定义事件处理程序功能计时器。指定自定义事件处理程序函数名称作为函数句柄,并将此函数作为输入参数传递给计时器。For details about function handles, seeCreate Function Handle。例如,假设您要使用createOrderAndRoutewith the custom event handler function namedeventhandler。This code assumes a Bloomberg EMSX connectionc, Bloomberg EMSX orderorder和计时器对象t

  1. Run计时器to executeeventhandler。The name-value argumentTIMERFCNspecifies the event handler function. The name-value argument时期指定事件处理程序函数执行之间的1秒延迟。当名称值参数ExecutionMode被设定为fixedRate, the event handler function executes immediately after it is added to the MATLAB execution queue.

    t =计时器('TimerFcn',{@c.eventhandler},'Period',1,。。。'ExecutionMode','fixedRate');
  2. Start the timer to initiate and executeeventhandlerimmediately.

    start(t)
  3. RuncreateOrderAndRouteusing the custom event handler by settingUsedefaultEventHandlertofalse

    createOrderAndRoute(c,order,“ underefeaulteventhandler”,错误的)
  4. Stop the timer to stop data updates.

    stop(t)

    If you want to resume data updates, runstart

  5. 完成彭博EMSX连接的处理数据更新后,删除计时器。

    删除(t)

自定义活动处理程序功能的工作流程

This workflow summarizes the basic steps to work with a custom event handler function for any of the data service providers, except Bloomberg EMSX.

  1. 编写一个定制的事件处理器函数并保存它to a file.

  2. Create a connection to the data service provider.

  3. Subscribe to a specific security using an existing function or API syntax.

  4. Run an existing function to receive data updates and use the custom event handler function as an input argument.

  5. Stop data updates by usingstopor by closing the connection to the data service provider.

  6. Close the connection to the data service provider if the connection is still open.

对于Bloomberg EMSX接口,请遵循此工作流程。

  1. 编写一个定制的事件处理器函数并保存它to a file.

  2. Create a connection usingemsx

  3. Subscribe to Bloomberg EMSX fields usingorders路线。您还可以编写自定义事件处理程序功能来处理订阅事件。

  4. 使用自定义事件处理程序功能使用计时器。Use a function handle to specify the custom event handler function name to run计时器

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

  6. Stop data updates usingstop

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

  8. 使用计时器删除计时器删除

  9. Close the connection usingclose

See Also

|||||||||

相关话题

External Websites