/stock-quote

Microservice to retrieve stock quotes

Primary LanguageJavaApache License 2.0Apache-2.0

The stock-quote microservice gets the price of a specified stock. It hits an API in API Connect, which drives a call to IEXTrading.com to get the actual data.

It responds to a GET /{symbol} REST request, where you pass in a stock ticker symbol, and it returns a JSON object containing that symbol, the price, and the date it was quoted.

For example, if you hit the http://localhost:9080/stock-quote/IBM URL, it would return {"symbol": "IBM", "price": 155.23, "date": "2016-06-27"}

This service uses Redis for caching. When a quote is requested, it first checks to see if the answer is in the cache, and if so, whether the quote is less that 24 hours old (Quandl only returns the previous business day's closing price), and if so, just uses that. Otherwise (or if any exceptions occur communicating with Redis), it drives the REST call to API Connect as usual, then adds it to Redis so it's there for next time.

The Java for Redis, or Jedis, library is used for communicating with Redis.

Build and Deploy to ICP

To build stock-quote clone this repo and run:

mvn package
docker build -t stock-quote:latest -t <ICP_CLUSTER>.icp:8500/stock-trader/stock-quote:latest .
docker tag stock-quote:latest <ICP_CLUSTER>.icp:8500/stock-trader/stock-quote:latest
docker push <ICP_CLUSTER>.icp:8500/stock-trader/stock-quote:latest

Use WebSphere Liberty helm chart to deploy Stock Quote microservice to ICP:

helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
helm install ibm-charts/ibm-websphere-liberty -f <VALUES_YAML> -n <RELEASE_NAME> --tls

In practice this means you'll run something like:

docker build -t stock-quote:latest -t mycluster.icp:8500/stock-trader/stock-quote:latest .
docker tag stock-quote:latest mycluster.icp:8500/stock-trader/stock-quote:latest
docker push mycluster.icp:8500/stock-trader/stock-quote:latest

helm repo add ibm-charts https://raw.githubusercontent.com/IBM/charts/master/repo/stable/
helm install ibm-charts/ibm-websphere-liberty -f manifests/stock-quote-values.yaml -n stock-quote --namespace stock-trader --tls