ThinkHub Stock Quote Service is a Spring Boot application that provides real-time stock quotes. It fetches data from an external API, implements caching for improved performance, and offers robust error handling.
- Fetch individual stock quotes by symbol
- Retrieve batch quotes for multiple symbols
- Caching mechanism to reduce API calls and improve response time
- Comprehensive error handling and logging
- RESTful API endpoints
- Secure endpoints with basic authentication
- Java 22
- Spring Boot 3.3.2
- Spring Security
- Caffeine Cache
- Maven
- Logback for logging
- JUnit and Mockito for testing
- Ensure you have Java 22 and Maven installed on your system (binary included in project directory).
- Clone the repository:
git clone https://github.com/VishaL6i9/SpringBoot-StockQuotesAPI.git - Navigate to the project directory:
cd ThinkHub - Build the project:
mvn clean package - Run the application:
java -jar target/thinkhub-0.0.1-SNAPSHOT.jaror./mvnw spring-boot:run
Key configurations in application.properties:
server.port: The port on which the application runs (default: 8080)alphavantage.api.key: Your Alpha Vantage API key (A working API is being used by default)spring.security.user.nameandspring.security.user.password: Credentials for basic auth (vish:6190)- Cache configurations
Below is an overview of the directory structure for this project:
Folder PATH listing
Volume serial number is 789B-4402
C:.
| .gitignore
| application.log
| HELP.md
| mvnw
| mvnw.cmd
| pom.xml
| readme.md
|
+---.idea
| [collapsed]
|
+---.mvn
| [collapsed]
|
+---src
| +---main
| | +---java
| | | \---vish
| | | \---thinkhub
| | | | StockQuoteServiceApplication.java
| | | |
| | | +---cache
| | | | StockQuoteCache.java
| | | |
| | | +---config
| | | | CacheConfig.java
| | | | SecurityConfig.java
| | | | WebClientConfig.java
| | | |
| | | +---Controller
| | | | StockQuoteController.java
| | | |
| | | +---exception
| | | | ErrorResponse.java
| | | | ExternalApiException.java
| | | | GlobalExceptionHandler.java
| | | | StockQuoteException.java
| | | |
| | | +---model
| | | | StockQuote.java
| | | |
| | | \---service
| | | | ExternalStockApiService.java
| | | | StockQuoteService.java
| | | |
| | | \---impl
| | | StockQuoteServiceImpl.java
| | |
| | \---resources
| | | application-test.properties
| | | application.properties
| | | logback.xml
| | |
| | +---logs
| | | log.txt
| | |
| | +---static
| | \---templates
| \---test
| \---java
\---vish
\---thinkhub
StockQuoteServiceApplicationTests.java
|
\---target
[collapsed]
| Directory | Description |
|---|---|
.idea |
IntelliJ IDEA configuration files |
.mvn |
Maven configuration files |
src |
Source code directory |
src/main/java |
Java source code directory |
src/main/resources |
Resource files (e.g. properties, XML) |
src/test/java |
Test source code directory |
target |
Build output directory |
-
Get quote for a single symbol:
- GET
/api/v1/stock-quotes/{symbol}
- GET
-
Get quotes for multiple symbols:
- GET
/api/v1/stock-quotes/batch?symbols=AAPL,GOOGL,MSFT
- GET
-
Get cache statistics:
- GET
/api/v1/stock-quotes/cache-stats
- GET
The application uses a global exception handler to manage errors. Common exceptions include:
StockQuoteException: For errors related to stock quote retrievalExternalApiException: For errors from the external stock API- Generic exceptions: For unexpected errors
The application uses Caffeine Cache with the following configuration:
- Initial capacity: 100 entries
- Maximum size: 500 entries
- Expiration: Entries expire after 5 minutes
Logging is configured using Logback. Log files are stored in /application.log.
Run tests using:
./mvnw test
Build the Docker image:
docker build -t thinkhub-stock-quote-service .
Run the container:
docker run -p 8080:8080 thinkhub-stock-quote-service
For any queries, please contact vishalkandakatla@gmail.com.