Skip to content

Dr-Katherine-Johnson/chart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chart

Price chart microservice for a Service-oriented architecture clone of the stock detail page from Robinhood.com

Table of Contents

Related Projects

Deployment

  • Create a file in the project directory named .env, based on .env.template. This file will need:

    1. The URL of the deployed EC2 instance for this service
    2. The URL of the deployed EC2 instance for the price chart service
    3. The absolute path to the private key file in order to authenticate into that instance.
  • From your LOCAL computer

# Makes the environment variables you just defined in `.env` available in your current shell
export $(cat .env)
# Only include the 1 at the end if this is the first time you've run this script on this instance (installs things like docker, docker-compose, etc...)
bash deploy.sh $pathToPEM $instance 1 && bash compose.sh $pathToPEM $instance
  • (if needed) Enter yes at the prompt.

  • The app is now running on the instance in a container at port 4444. The mongo database is available in its own container at port 1000.

If Needed

  • To stop (and clean up after yourself!) or restart the app, run these commands from your local machine (respectively)
bash compose.sh $pathToPEM $instance 1
  • To restart the app:
bash compose.sh $pathToPEM $instance
  • To connect to the mongo db running in the mongo container (ie, check if there is data there, etc ...), from the ec2 instance, run
docker exec -i chart_mongo_1 mongo "mongodb://localhost"

Additional Documentation

For documentation related to the database see:

Requirements

  • CLI like Bash
  • docker
  • docker-compose

Development using Docker

Make sure you have docker running on your machine.

Mount

  • From within the root directory:

Mount an external volume where dependencies will be installed

make setup

Dependencies

Install binary dependencies

make install

If you're installing new packages first start a shell in the container running node.

  1. Find the CONTAINER_NAME corresponding with the node image with:
docker ps

If make install ran successfully you should see "chart_chart_1". Start a shell in the container:

  1. Then start a shell in the container
docker exec -ti chart_chart_1 /bin/bash
  • You'll see something like:
root@2e3dba3578ae:/usr/src/service#
  1. You can then install additional dependencies with the command
npm install PACKAGE --save

where PACKAGE is the name of your npm package.

Develop

To start a development environment, use the commmand

make dev

This will create a bundle.js, start the server, seed the database and connect the server to the database.

For other commands see docker-compose.builder.yml and Makefile. Example: Build webpack bundle

make bundle

Run a MongoDB shell

From the root directory in your terminal, once your Mongo container is running (it should be called chart_mongo_1), you can run an interactive shell to query the database:

docker exec -ti chart_mongo_1 mongo

Build

  • Creates a webpack bundle, Builds a docker image, and pushes it to dockerhub
npm run build

API

Prices

Endpoint Output Shape (JSON) Example Resonse
GET /price/:ticker Returns all the prices for a ticker as objects in the prices array
      {
        "ticker": "APPL",
        "name": "Apple",
        "prices": [
          {
            "dateTime": "2019-11-16T22:27:19.319Z",
            "open": "264.03",
            "high": "264.40",
            "low": "264.02",
            "close": "264.35",
            "volume": "96770"
          },
          // ... about 1750 more prices
        ]
      }
      
      {
        "ticker": String,
        "name": String,
        "prices": [
          {
            "dateTime": String, // ISO 8601
            "open": Number,
            "high": Number,
            "low": Number,
            "close": Number,
            "volume": Number,
          },
          // ... about 1750 more prices
        ]
      }
      
POST /price/:ticker Creates a ticker with corresponding prices body
      {
        "ticker": String,
        "name": String,
        "prices": [
          {
            "dateTime": String, // ISO 8601
            "open": Number,
            "high": Number,
            "low": Number,
            "close": Number,
            "volume": Number,
          },
          // ... about 1750 more prices
        ]
      }
      
201 Ticker saved successfully 400 Could not save 409 Trying to post a duplicate ticker 500 Server error
PUT /price/:ticker Updates a ticker with a new prices body
      {
        "dateTime": String, // ISO 8601
            "open": Number,
            "high": Number,
            "low": Number,
            "close": Number,
            "volume": Number
      }
      
201 Ticker update successfully 403 Price sent was for a date that is older than current price 404 Could not find ticker 500 Server error
DELETE /price/:ticker Deletes a ticker Note: will delete all the information related to that ticker 201 Ticker deleted successfully 500 Server error

Current Price

Endpoint Output Shape (JSON) Example Resonse
GET /current-price/:ticker Returns the last available price for that stock
        {
          "price": NUMBER
        }
      
        {
          "price": "264.35"
        }
      
GET /current-price/:ticker Returns the last available price for that stock
        {
          "price": NUMBER
        }
      
        {
          "price": "264.35"
        }
      

Percent change

Endpoint Output Shape (JSON) Example Resonse
GET /percent-change/:ticker Returns the percent change between the last available price and the price immediately before that (ie, the penultimate data point)
        {
          "percentChange": NUMBER
        }
      
        {
          "percentChange": "-0.0014"
        }