Read this in other languages: 日本語.
This repository will not be updated. The repository will be kept available in read-only mode.
In this Code Pattern, we will create a web app for monitoring sentiment, price, and news for individual listed stocks, using IBM Watson Discovery and CloudantDB as well as Nodejs and Alpha Vantage. The web page is adapted from a template from Start Bootstrap by Blackrock Digital. You can find the repository for the template here, including its License.
When the reader has completed this Code Pattern, they will understand how to:
- Create and use Watson Discovery and Cloudant NoSQL Database
- Gather news from the Watson Discovery News service
- Obtain stock price information from Alpha Vantage
- Deploy a Nodejs application to input stock choices and display information
- The user adds and remove stocks they are interested in using the Web UI.
- User input is processed and routed to the backend server.
- The backend server stores stock information in a Cloudant NoSQL database for easy retrieval.
- The backend server uses Watson Discovery to find information about a specific company.
- The Watson Discovery Service queries the Watson News collection for articles related to the company.
- The Alpha Vantage APIs are queried to find market price for a given company.
- News, sentiment, and stock price are all returned and rendered in the web app to the user.
- Watson Discovery: A cognitive search and content analytics engine for applications to identify patterns, trends, and actionable insights.
- Cloudant NoSQL DB: A fully managed data layer designed for modern web and mobile applications that leverages a flexible JSON schema.
- NodeJS: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.
- Create an account on Alpha Vantage by clicking
Get Your Free API Key Today
. - Copy the Alpha Vantage API key for later use
Use the Deploy to IBM Cloud
button OR create the services and run locally.
- Press the above
Deploy to IBM Cloud
button and then click onDeploy
.
- In Toolchains, click on
Delivery Pipeline
to watch while the app is deployed. (Note, if you get an error on the first time you deploy such asServer error, status code: 409, error code: 60016, message: An operation for service instance wsa-discovery is in progress.
, just click on the re-deploy button again, and it should work). Once deployed, the app can be viewed by clickingView app
.
- To see the app and services created and configured for this Code Pattern, use the IBM Cloud dashboard. The app is named
watsonstockadvisor
with a unique suffix. The following services are created and easily identified by thewsa-
prefix:- wsa-discovery
- wsa-cloudant
You can Deploy the application simply by clicking the Deploy to IBM Cloud
button above to automatically create a toolchain to provision and run the application.
If you do not have an IBM Cloud account yet, you will need to create one.
- Navigate to https://cloud.ibm.com/dashboard/apps/
- Located and click on your newly created application (not the 'Route' link)
- Select 'Runtime' in the left menu
- Select the 'Environment Variables' tab in the middle of the page
- Scroll down to the User defined variables section
- Paste your API key from Alpha Vantage
- Clone the repo
- Create IBM Cloud services
- Configure Watson Discovery and Get Credentials
- Provision Cloudant NoSQL DB and Get Credentials
- Web Portal
- Add IBM Cloud Services Credentials to .env file
- Run the application
Clone the watson-stock-advisor
locally. In a terminal, run:
$ git clone https://github.com/ibm/watson-stock-advisor
Create the following services:
-
Launch the Watson Discovery tool. The first time you do this, you will see "Before working with private data, we will need to set up your storage". Click
Continue
and wait for the storage to be set up. -
Choose
Watson Discovery News
from theManage Data
tab. -
Under
Collection Info
section, clickUse this collection in API
and copy theEnvironment ID
into your .env file asDISCOVERY_ENV_ID
. This should besystem
for theWatson Discovery News
collection.
- From the top-level Discovery page, click
Service Credentials
. If there is no credential underView Credentials
clickNew Credential
and thenView Credentials
.
- Use the
username
andpassword
in the .env file, as instructed below.
-
Navigate to cloud.ibm.com
-
Click
Create Resource
-
Search for
cloudant nosql
-
Select the only search result under
Data & Analytics
calledCloudant NoSQL DB
-
Specify the settings you want
-
Click
Create
in the bottom right -
From the top-level Cloudant page, click
Service Credentials
. If there is no credential underView Credentials
clickNew Credential
and thenView Credentials
.
The web page is adapted from a template from Start Bootstrap by Blackrock Digital. You can find the repository for the template here, including its License.
As you create the Bluemix Services, you'll need to create service credentials and get the username and password:
Move the watson-stock-advisor/web/env.sample
file to watson-stock-advisor/web/.env
and populate the service
credentials (and Cloudant URL) as you create the credentials:
The credentials for IBM Cloud services (Discovery), can be found in the Services
menu in IBM Cloud,
by selecting the Service Credentials
option for each service.
The other settings for Discovery were collected during the
earlier setup steps (ENV_ID
).
Navigate to the web directory and Copy the env.sample
to .env
.
$ cp env.sample .env
Edit the .env
file with the necessary settings.
# Copy this file to .env and replace the credentials with
# your own before starting the app.
# Watson Discovery
DISCOVERY_VERSION_DATE="2018-03-05"
DISCOVERY_ENV_ID="system"
DISCOVERY_URL=<add_discovery_url>
## Un-comment and use either username+password or IAM apikey.
# DISCOVERY_USERNAME=<add_discovery_username>
# DISCOVERY_PASSWORD=<add_discovery_password>
# DISCOVERY_IAM_APIKEY=<add_discovery_iam_apikey>
# Cloudant
CLOUDANT_USERNAME=<add_cloudant_username>
CLOUDANT_PASSWORD=<add_cloudant_password>
CLOUDANT_HOST=<add_cloudant_host>
DB_NAME="stock-data"
# App Config
MAX_COMPANIES=20
MAX_ARTICLES_PER_COMPANY=100
# AlphaVantage
ALPHAVANTAGE_API_KEY="demo"
In the root directory, run:
$ npm install
$ npm start
The portal should now be accessible on port 8080
(or another port specified by PORT in .env)
- Artificial Intelligence Code Patterns: Enjoyed this Code Pattern? Check out our other AI Code Patterns.
- AI and Data Code Pattern Playlist: Bookmark our playlist with all of our Code Pattern videos
- With Watson: Want to take your Watson app to the next level? Looking to utilize Watson Brand assets? Join the With Watson program to leverage exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.