https://github.com/picadoh/stocks-api
Simple Stocks Spring Boot Application
https://github.com/picadoh/stocks-api
example java spring spring-boot
Last synced: about 1 month ago
JSON representation
Simple Stocks Spring Boot Application
- Host: GitHub
- URL: https://github.com/picadoh/stocks-api
- Owner: picadoh
- Created: 2016-08-29T14:43:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T22:52:22.000Z (about 6 years ago)
- Last Synced: 2025-03-31T04:41:15.588Z (3 months ago)
- Topics: example, java, spring, spring-boot
- Language: Java
- Size: 26.4 KB
- Stars: 12
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Simple Stocks API
This is an example application that provides the means of managing simple stocks and trades.
This is offered as a simple web service that provides the following operations:
- Record a trade
- Record a stock
- Get stock details
- Calculate stock dividend
- Calculate stock P/E ratio
- Calculate stock price based on trades recorded in the past X minutes (configurable)
- Calculate the GBCE All Share Index using geometric mean of prices for all stocks### Requirements
- Java 8
- Maven 3### Design
The application is structured in layers, namely:A *controller* is responsible for handling the requests and communicating with the layer service for providing a response. Here the internal domain is converted to DTOs to eliminate the coupling between the API and the internal domain.
A *service* is responsible for executing the business logic, here we know how to compute stock prices and GBCE indexes.
A *domain object* represents the model (Stock and Trade)
A *repository* abstracts the underlying datastore. For the sake of the example, the underlying datastore is a local hash set.
### Code structure
The *application* contains the main application source code and unit tests.The *integration-tests* module contains the end-to-end tests made at web service level.
### Build
project$ mvn clean install
### Running
project$ cd application
project$ mvn spring-boot:runFor validation purposes you can now access localhost:8080 in the corresponding endpoints in order to test the service. The following endpoints are available:
POST /stock - Create new stock
POST /trade - Create new tradeGET /stocks?symbol=GIN - Get stock details for stock with symbol GIN
GET /stocks/dividend?symbol=GIN - Calculate dividend yield for stock with symbol GIN
GET /stocks/peratio?symbol=GIN - Calculate P/E ratio for stock with symbol GIN
GET /stocks/price?symbol=GIN - Calculate the stock price for stock with symbol GIN
GET /stocks/gbceasi - Calculate GBCE all shares indexThe following CURL examples might come in handy while validating the application
curl -H "Content-Type: application/json" -X POST -d '{"symbol":"GIN","type": "COMMON","lastDividend": "8","fixedDividend": "0.02","parValue": "100","tickerPrice": "1.1"}' http://localhost:8080/stock
curl -H "Content-Type: application/json" -X POST -d '{"stockSymbol": "GIN","price": "10.6","quantity": "3","indicator": "BUY"}' http://localhost:8080/tradecurl -H "Content-Type: application/json" http://localhost:8080/stocks?symbol=GIN
curl -H "Content-Type: application/json" http://localhost:8080/stocks/dividend?symbol=GIN
curl -H "Content-Type: application/json" http://localhost:8080/stocks/peratio?symbol=GIN
curl -H "Content-Type: application/json" http://localhost:8080/stocks/price?symbol=GIN
curl -H "Content-Type: application/json" http://localhost:8080/stocks/gbceasi### Integration Tests
Integration tests run under a specific maven profile so it is possible to run them in a separate pipeline stage.project$ mvn clean install -Pintegration-tests