Main Content

realtime

Snapshot and subscription WDS data

Description

d = realtime(c,s,f) returns the real-time snapshot Wind Data Feed Services (WDS) data for the specified securities and fields using the WDS connection.

example

[d,e] = realtime(c,s,f) also returns the WDS error identifier. For troubleshooting, contact Wind Information Co., Ltd.

requestid = realtime(c,s,f,eventhandler) subscribes to the specified securities by using the specified fields and an event handler function.

example

[requestid,e] = realtime(c,s,f,eventhandler) also returns the WDS error identifier.

Examples

collapse all

Using a WDS connection, retrieve snapshot data for two securities.

Create a WDS connection.

c = wind;

Format output data for currency.

format bank

Using the 0001.HK and 0003.HK securities and the WDS connection, retrieve real-time data for the last price and volume fields.

s = {'0001.HK','0003.HK'};
f = {'rt_last','rt_vol'};

d = realtime(c,s,f)
d =

  2×3 timetable

            Time              Codes      RT_LAST      RT_VOL   
    ____________________    _________    _______    ___________

    28-Nov-2017 10:54:14    '0001.HK'     97.75      3199866.00
    28-Nov-2017 10:54:14    '0003.HK'     15.28     19995745.00

d is a timetable that contains rows for each security with the time and these variables:

  • Security

  • Last price

  • Volume

Close the WDS connection.

close(c)

Using a WDS connection, subscribe to two securities and process real-time events by using an event handler function. Then cancel the subscription.

Create a WDS connection.

c = wind;

Format output data for currency.

format bank

Using the 0002.HK and 0003.HK securities and the WDS connection, retrieve real-time data for the last price, volume, and last volume fields. Process real-time data events using the sample event handler function windEventHandler. You can use the sample event handler function or create a custom event handler function to process events.

s = {'0002.HK','0003.HK'};
f = {'rt_last','rt_vol','rt_last_vol'}};

requestid = realtime(c,s,f,@(varargin)windEventHandler(varargin))
requestid =

  uint64

   5

requestid is the request identifier associated with the subscription. The event handler function windEventHandler creates a variable in the MATLAB® workspace named winddata. This variable contains the subscription data.

Display the subscription data.

winddata
winddata =

  2×4 timetable

            Time              Codes      RT_LAST      RT_VOL       RT_LAST_VOL
    ____________________    _________    _______    ___________    ___________

    28-Nov-2017 10:55:25    '0002.HK'     81.30      2106274.00     422500.00 
    28-Nov-2017 10:55:25    '0003.HK'     15.28     19995745.00    1398000.00 

winddata is a timetable that contains a row for each security with the time and these variables:

  • Security

  • Last price

  • Volume

  • Last volume

Stop the data subscription using the request identifier.

stop(c,requestid)

Close the WDS connection.

close(c)

Input Arguments

collapse all

WDS connection, specified as a connection object created with the wind function.

Securities, specified as a character vector, string scalar, cell array of character vectors, or string array. For a single security, use a character vector or string scalar. For multiple securities, use a cell array of character vectors or string array.

Example: '0001.HK'

Data Types: char | string | cell

Fields, specified as a character vector, string scalar, cell array of character vectors, or string array. For a single field, use a character vector or string scalar. For multiple fields, use a cell array of character vectors or string array.

For details about valid fields, contact Wind Information Co., Ltd.

Example: {"high","low"}

Data Types: char | string | cell

Event handler function, specified as a function handle. You can use the example event handling function windEventHandler to process real-time WDS events. Or, you can define a custom event handler function to process events of your choice.

The event handler function windEventHandler creates the variable winddata in the MATLAB workspace. The windEventHandler function returns winddata as a timetable that contains real-time WDS data. If an error occurs, the function returns winddata as a table that contains an error code. For troubleshooting, contact Wind Information Co., Ltd.

The winddata timetable contains rows for each real-time WDS event with the time. The first variable in this timetable is the specified securities in the s input argument. The remaining variables are the specified fields in the f input argument.

To access the code of the function, enter edit windEventHandler at the command line.

To define a custom event handler function:

  1. Choose the WDS events to process, monitor, or evaluate.

  2. Decide how the custom event handler 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.

After defining the function, you can run it by passing the name of the function as a function handle. For details about function handles, see Create Function Handle.

Example: @(varargin)windEventHandler(varargin)

Data Types: function_handle

Output Arguments

collapse all

Real-time snapshot WDS data, returned as a timetable. The rows of the timetable correspond to the real-time snapshots with the time. The first variable in the timetable is the specified securities in the s input argument. The remaining variables in the timetable are the specified fields in the f input argument.

Request identifier for the real-time data subscription, returned as a numeric scalar. To stop the real-time data subscription, specify the requestid output argument in the stop function.

WDS error identifier, returned as a numeric scalar. The value 0 indicates a successful execution of the realtime function. Otherwise, for details about the error, contact Wind Information Co., Ltd.

Version History

Introduced in R2018a