StockTraderAPI is a Java-based RESTful API that simulates a basic trading platform. It allows users to manage a virtual stock portfolio by performing operations such as buying and selling stocks, viewing real-time prices, checking portfolio performance, and monitoring cash balance. This project is designed to provide a simple yet functional trading experience for developers and enthusiasts.
- User Portfolio Management: Track owned stocks, including quantity and purchase price.
- Stock Trading:
- Buy stocks using virtual cash.
- Sell stocks from the portfolio.
- Real-Time Price Checking: Fetch current stock prices for supported symbols.
- Portfolio Summary: View a detailed breakdown of stock holdings and cash balance.
- RESTful Endpoints: API endpoints for easy integration and testing.
- Java: Core programming language.
- Spring Boot: Framework for building the RESTful API.
- HashMap: In-memory storage for user data and portfolio.
To run this project, ensure you have the following installed:
- Java 8 or higher.
- Maven or Gradle for dependency management.
git clone https://github.com/yourusername/StockTraderAPI.git
cd StockTraderAPI
Using Maven:
mvn spring-boot:run
Using Gradle:
gradle bootRun
The API will be accessible at http://localhost:8080/api/trade
.
Use a tool like Postman or cURL to test the following endpoints:
POST /api/trade/buy
Parameters: symbol, quantity
Example: /api/trade/buy?symbol=AAPL&quantity=1
POST /api/trade/sell
Parameters: symbol, quantity
Example: /api/trade/sell?symbol=AAPL&quantity=1
GET /api/trade/portfolio
GET /api/trade/price
Parameter: symbol
Example: /api/trade/price?symbol=TSLA
GET /api/trade/balance
StockTraderAPI
|├── src/main/java
| ├── TradingController.java
| └── (other supporting files)
|├── pom.xml (or build.gradle)
|└── README.md
- TradingController.java: The main REST controller handling API requests.
- pom.xml/build.gradle: Configuration file for Maven/Gradle dependencies.
- README.md: Documentation for the project.
Request:
curl -X POST "http://localhost:8080/api/trade/buy?symbol=AAPL&quantity=2"
Response:
Bought 2 shares of AAPL for $19.00
Request:
curl -X GET "http://localhost:8080/api/trade/portfolio"
Response:
{
"AAPL": "Shares: 2, Price: $9.50",
"Cash Balance": "$81.00"
}
We welcome contributions! To contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Make your changes and commit:
git commit -m "Add new feature"
- Push to your branch:
git push origin feature-name
- Open a pull request.
This project is licensed under the MIT License. See LICENSE
for details.
For questions or feedback, please reach out to:
- Michael Mordec (creator)
- GitHub: yourusername