mandoolala / reactive-stock-trader-scala

My implementation of reactive stock-trader system in Scala, following this tutorial written in Java. https://developer.ibm.com/series/reactive-in-practice/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reactive Stock Trader

My implementation of Reactive Stock Trader system (Portfolio, Broker, Wire Transfers Services) in Scala.

Tools - Lagom (Play, Akka, Cassandra and Kafka), Vue.js (for UI), Kubernetes
Patterns - Event Sourcing, CQRS
Architecture - Interface, gateway, services
Integration - Point to Point, streaming, pub/sub

Learning Materials:

Reactive in practice: A complete guide to event-driven systems development in Java

Java Implementation of Reactive Stock Trader by RedElastic

Installation

The following will help you get set up in the following contexts:

  • Local development
  • Deployment to local Kubernetes (using Minikube)
  • Interactions (UI, command line)

Local development

  • Install Java 8 SDK
  • Install sbt (brew install sbt on Mac)

This project has been generated by the lagom/lagom-scala.g8 template. For instructions on running and testing the project, see https://www.lagomframework.com/get-started-scala.html.

Running Lagom in development mode is simple. Start by launching the backend services using sbt.

  • sbt runAll

The Gateway exposes an API to the frontend on port 9100.

Deploying to Kubernetes

For instructions on how to deploy Reactive Stock Trader to Kubernetes, you can find the deployment instructions and Helm Charts for Kafka and Cassandra here: https://github.com/RedElastic/reactive-stock-trader/tree/master/deploy

Interacting with the UI

The UI is developed in Vue.js. You'll need to have Node.js and npm installed and then follow the instructions below.

Project setup and launching for development:

npm install
npm run serve

This will launch the UI on localhost:8080 for development. You can then use the UI to interact with the Lagom system.

Testing / debugging:

  • Run your tests: npm run test
  • Lints and fixes files: npm run lint

Reactive Stock Trader uses Rollbar for debugging purposes. In order to make use of Rollbar:

  • copy config.env to .env.local
  • sign up at Rollbar and create an access token
  • change VUE_APP_ROLLBAR_ACCESS_TOKEN to your token in .env.local

Visit Environment Variables and Modes and https://rollbar.com for more details.

For additional Vue configuration information, see Configuration Reference.

Interacting with the command line

If you would like to test the backend without installing the UI, you can use the following command line information to help.

The jq command line tool for JSON is very handy for pretty printing JSON responses, on Mac this can be installed with brew install jq.

Create a new portfolio named "piggy bank savings": PID=$(curl -X POST http:/localhost:9000/api/portfolio -F name="piggy bank savings" | jq -r .portfolioId); echo $PID

Place an order: curl -X POST http://localhost:9000/api/portfolio/$PID/order -F symbol=RHT -F shares=10 -F order=buy

View the portfolio curl http://localhost:9000/api/portfolio/$PID | jq .

Transfer funds into the portfolio curl -X POST http://localhost:9000/api/transfer -F amount=20000 -F sourceType=savings -F sourceId=123 -F destinationType=portfolio -F destinationId=$PID

PID=$(curl -X POST http:/localhost:9000/api/portfolio -F name="piggy bank savings" | jq -r .portfolioId); echo $PID

curl -X POST http://localhost:9000/api/transfer -F amount=20000 -F sourceType=savings -F sourceId=123 -F destinationType=portfolio -F destinationId=$PID

curl http://localhost:9000/api/portfolio/$PID | jq .

curl -X POST http://localhost:9000/api/portfolio/$PID/order -F symbol=IBM -F shares=10 -F order=buy

curl http://localhost:9000/api/portfolio/$PID | jq .

About

My implementation of reactive stock-trader system in Scala, following this tutorial written in Java. https://developer.ibm.com/series/reactive-in-practice/


Languages

Language:Scala 68.8%Language:Vue 27.0%Language:JavaScript 4.1%Language:HTML 0.1%