realtime
Snapshot and subscription WDS data
Syntax
Description
Examples
Retrieve WDS Snapshot Data
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)
Retrieve WDS Subscription Data
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
c
— WDS connection
connection object
WDS connection, specified as a connection object created with the wind
function.
s
— Securities
character vector | string scalar | cell array of character vectors | string array
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
f
— Fields
character vector | string scalar | cell array of character vectors | string array
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
eventhandler
— Event handler function
function handle
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:
Choose the WDS events to process, monitor, or evaluate.
Decide how the custom event handler processes these events.
Determine the input and output arguments for the custom event handler function.
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
d
— Real-time snapshot WDS data
timetable
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.
requestid
— Request identifier
numeric scalar
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.
e
— WDS error identifier
numeric scalar
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)