news
Syntax
Description
Retrieve Money.Net News Stories
specifies options using one or more name-value arguments. For example,
n
= news(c
,Name=Value
)Number=25
returns 25 news stories.
Subscribe to Real-Time Updates for Money.Net News Stories
news(
subscribes to real-time updates for news stories. This syntax executes the
specified event handler function when a new news story becomes available.c
,Subscription="on",EventHandler=eventhandler
)
Examples
Retrieve News Stories
Create Money.Net web socket interface connection c
using a user name
and password.
username = "user@company.com"; pwd = "999999"; c = moneynetws(username,pwd);
Retrieve news data n
for 50 news stories using the
Money.Net web socket interface connection c
.
n = news(c);
n
returns as a table with 50 rows.
Close the Money.Net web socket interface connection.
close(c)
Retrieve a Specific Number of Stories
Create Money.Net web socket interface connection c
using a user name
and password.
username = "user@company.com"; pwd = "999999"; c = moneynetws(username,pwd);
Retrieve news data n
for 10 news stories using the
Money.Net web socket interface connection c
.
n = news(c,Number=10);
n
returns as a table with 10 rows.
Close the Money.Net web socket interface connection.
close(c)
Filter News Story Retrieval by Specific Criteria
Create Money.Net web socket interface connection c
using a user name
and password.
username = "user@company.com"; pwd = "999999"; c = moneynetws(username,pwd);
Retrieve news stories in the general finance category. Specify that the
news stories mention the term "stock"
and contain the
symbol for IBM®.
category = "General Finance"; term = "stock"; symbol = "IBM"; n = news(c,Category=category,SearchTerm=term,Symbol=symbol);
n
is a table with 50 news stories.
Close the Money.Net web socket interface connection.
close(c)
Stream News Data
Create Money.Net web socket interface connection c
using a user name
and password.
username = "user@company.com"; pwd = "999999"; c = moneynetws(username,pwd);
Turn on the subscription to the Money.Net real-time news data stream using
the default event handler function
mnNewsStreamEventHandler
. The function
mnNewsStreamEventHandler
processes news data events
by populating the workspace variable mnNewsStreamLatest
with the latest news stories. News stories populate in the
mnNewsStreamLatest
variable until it contains 10
rows. Then, the latest news stories overwrite the older ones in
mnNewsStreamLatest
. To access the code for this
function, enter edit mnNewsStreamEventHandler.m
.
eventhandler = "mnNewsStreamEventHandler"; news(c,Subscription="on",EventHandler=eventhandler)
The workspace variable mnNewsStreamLatest
appears in
the MATLAB® Workspace. To see the latest 10 news stories, explore
mnNewsStreamLatest
in the Variables editor.
Turn off the real-time news data stream.
news(c,Subscription="off")
Real-time updates stop in the workspace variable
mnNewsStreamLatest
.
Close the Money.Net web socket interface connection.
close(c)
Stream News Data Using Custom Event Handler
Create Money.Net web socket interface connection c
using a user name
and password.
username = "user@company.com"; pwd = "999999"; c = moneynetws(username,pwd);
Turn on the subscription to the Money.Net real-time news data stream using
the custom event handler function myfnc
. Here, define
myfnc
to display Money.Net news data to the Command
Window. You can write a custom event handler function to process streaming
news stories differently. For details, see Writing and Running Custom Event Handler Functions.
myfnc = @(x)disp(x);
news(c,Subscription="on",EventHandler=myfnc)
Money.Net news stories stream to the Command Window.
Turn off the real-time news data stream.
news(c,Subscription="off")
Real-time updates stop in the Command Window.
Close the Money.Net web socket interface connection.
close(c)
Input Arguments
c
— Money.Net web socket interface connection
moneynetws
object
Money.Net web socket interface connection, specified as a moneynetws
object created using the moneynetws
function.
eventhandler
— Event handler
character vector | string scalar | function handle
Event handler, specified as a character vector, string scalar, or a function handle that specifies the name of the event handler function. Write a custom event handler function to process Money.Net events related to news stories. For details about custom event handler functions, see Writing and Running Custom Event Handler Functions.
Data Types: char
| function_handle
| string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: n = news(c,Number=10);
returns 10 Money.Net news
stories.
Note
The name-value arguments in the searching and streaming groups are
independent. If you combine these name-value arguments, you receive this error:
Invalid combination of Name-Value pairs. Type HELP MONEYNET/NEWS to
see the valid syntax
.
Number
— Number of news stories
50
(default) | numeric scalar
Number of news stories, specified as a numeric scalar. The maximum number of news stories that the Money.Net web socket interface can return is 500.
The number of news stories returned can be fewer than the specified
number because Money.Net provides only available news stories. When you
specify this option by itself, news
does not filter
the story content.
Example: n = news(c,Number=10);
Data Types: double
SearchTerm
— Search term
character vector | string scalar
Search term, specified as a character vector or string scalar.
news
returns available news stories that
contain the search term in the title or body of the news story.
Example: n = news(c,SearchTerm="Windows
10");
Data Types: char
| string
Symbol
— Symbol
character vector | cell array of character vectors | string scalar | string array
Symbol, specified as a character vector, cell array of character
vectors, string scalar, or a string array. To specify one symbol, use a
character vector or string scalar. To specify multiple symbols, use a
cell array of character vectors or a string array.
news
returns news stories related to the
specified symbols.
Example: n = news(c,Symbol=["IBM"
"YHOO"]);
Data Types: char
| cell
| string
Category
— News category
character vector | string scalar
News category, specified as a character vector or a string scalar.
news
returns stories only in the news category
specified.
Example: n = news(c,Category="General
Finance");
Data Types: char
| string
Subscription
— Money.Net real-time news subscription
"on"
| "off"
Money.Net real-time news subscription, specified as the values
"on"
or "off"
. To turn on the
Money.Net real-time news subscription, specify the value
"on"
. To turn off the subscription, specify the
value "off"
.
By default, the sample event handler function
mnNewsStreamEventHandler
processes the
retrieval of news stories during real-time news subscription. To access
the code for this function, enter edit
mnNewsStreamEventHandler.m
. The
mnNewsStreamEventHandler
function creates the
workspace variable mnNewsStreamLatest
. Then,
mnNewsStreamEventHandler
populates the table
mnNewsStreamLatest
with the latest 10 news
stories from Money.Net. The
mnNewsStreamEventHandler
function updates the
list to display the latest news stories.
To specify a custom event handler function, use the name-value
argument EventHandler
.
Example: news(c,Subscription="on")
Example: news(c,Subscription="on",EventHandler=myFcn)
EventHandler
— Custom event handler function
character vector | string scalar | function handle
Custom event handler function, specified as a character vector, string scalar, or function handle. To process the latest news stories, you can write your own custom event handler function. This function must have an input argument specified as a table. Each new news story from Money.Net is a single row in a table. For details about working with custom event handler functions, see Writing and Running Custom Event Handler Functions.
Specify this name-value argument only with the name-value argument
Subscription
and value
"on"
.
Example: news(c,Subscription="on",EventHandler=myFcn)
Data Types: char
| function_handle
| string
Output Arguments
n
— News stories
table
News stories, returned as a table with these variables. Each row in the table represents one news story.
News Story Variable | Data Type | Variable Description |
---|---|---|
| string array | News story identifier |
| table | Publisher name and identifier |
| string array | News story headline |
| string array | Portion of news story content |
| string array | URL for the website that contains the news story |
| cell array | List of tickers associated with the news story |
|
| Date and time the news story was posted |
|
| Date and time the news story was last updated |
| string array | Category for the news story |
Version History
Introduced in R2021b
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
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)