This backend api is designed for a brokerage firm to manage stock orders and customer finances. The service allows employees to interact with customer orders, including creating, listing, and canceling orders. It also supports deposit and withdrawal operations for customer funds. Additionally, an admin interface is provided to match pending transactions and handle customer assets.
- Order Management: Create, list and cancel orders for customers.
- Deposit and Withdrawal: Deposit and withdraw money for
TRY
assets. - Admin Features: Admin users can match pending orders.
- Authentication: All endpoints are authenticated with basic authentication.
- Transactional Integrity: Ensures admin transactions are atomic and consistent, especially in asset handling and order matching.
- Java 17
- Spring Boot 3.3.5
- H2 Database
- MapStruct for DTO mapping
- Lombok for boilerplate code
- Swagger for API documentation
All endpoints are accessible with only the basic authentication (admin user and password)
-
POST /api/orders
- Description: Create a new order for a given customer.
- Request Body:
{ "customerId": "123", "assetName": "AAPL", "orderSide": "BUY", "size": 10, "price": 150.50 }
-
GET /api/orders
- Description: List orders for a given customer and date range (optional filters).
- Query Parameters:
customerId
: (Optional) Filter by customer ID.startDate
: (Optional) Filter by start date.endDate
: (Optional) Filter by end date.
-
POST /api/orders/{orderId}/cancel
- Description: Cancel a pending order. Only orders with
PENDING
status can be canceled. - Path Parameter:
orderId
: The ID of the order to cancel.
- Description: Cancel a pending order. Only orders with
-
POST /api/assets/deposit
- Description: Deposit a certain amount of
TRY
for a given customer. - Request Body:
{ "customerId": "123", "amount": 1000 }
- Description: Deposit a certain amount of
-
POST /api/assets/withdraw
- Description: Withdraw a certain amount of
TRY
for a given customer. - Request Body:
{ "customerId": "123", "amount": 500 }
- Description: Withdraw a certain amount of
- GET /api/assets
- Description: List all assets for a given customer, including
TRY
as an asset. - Query Parameters:
customerId
: (Required) The customer ID.
- Description: List all assets for a given customer, including
- POST /api/v1/admin/matchOrders
- Description: Match all pending orders
HTTP Method | URL | Description |
---|---|---|
GET |
http://localhost:8080/ | Root page |
GET |
http://localhost:8080/swagger-ui/index.html | Swagger UI page |
GET |
http://localhost:8080/actuator | Actuator page |
|GET
|http://localhost:8080/h2-console| H2 database console page |
Column | Type | Description |
---|---|---|
id |
Long | The asset ID. |
customerId |
Long | The customer ID. |
assetName |
String | The name of the asset (e.g., AAPL , TRY ). |
size |
BigDecimal | Total amount/quantity of the asset. |
usableSize |
BigDecimal | The available amount of the asset for transactions. |
Column | Type | Description |
---|---|---|
id |
Long | The ID of the order. |
customerId |
Long | The ID of the customer placing the order. |
assetName |
String | The asset being bought or sold. |
orderSide |
Enum | The side of the order: BUY or SELL . |
size |
Long | The number of units of the asset. |
price |
BigDecimal | The price per unit of the asset. |
status |
Enum | The status of the order: PENDING , MATCHED , or CANCELED . |
createDate |
Date | The date the order was created. |
Column | Type | Description |
---|---|---|
id |
Long | The customer ID. |
name |
String | The customer name. |
surname |
String | The customer surname. |
email |
String | The customer email |
mvn clean install -Pdev
to build project
mvn spring-boot:run -Dspring-boot.run.profiles=dev
to run the project
mvn clean install -Pprod
to build project
mvn spring-boot:run -Dspring-boot.run.profiles=prod
to run the project
docker build -t brokerage-service .
to build project
docker run -p 8080:8080 brokerage-service
to run the project