This document provides an overview of the Trading API endpoints and their usage.
Pull the repository and run the following commands. Make sure npm, docker and docker-compose are installed.
npm install
docker-compose up --build
Use the provided postman collection to test the api. API will be hosted on your localhost:3000.
- Method: GET
- URL:
http://localhost:3000/shares
- Description: Retrieves a list of all shares.
- Method: GET
- URL:
http://localhost:3000/shares/:symbol
- Description: Retrieves details of a share by its symbol.
- URL Parameters:
symbol
(string): The symbol of the share to retrieve.
- Method: POST
- URL:
http://localhost:3000/shares
- Description: Creates a new share.
- Request Body:
{ "name": "AAP", "price": 100 }
- Method: DELETE
- URL:
http://localhost:3000/shares/:symbol
- Description: Deletes a share by its symbol.
- URL Parameters:
symbol
(string): The symbol of the share to delete.
- Method: PUT
- URL:
http://localhost:3000/shares/:symbol
- Description: Updates the price of a share by its symbol.
- URL Parameters:
symbol
(string): The symbol of the share to update.
- Request Body:
{ "price": 110 }
- Method: GET
- URL:
http://localhost:3000/portfolios
- Description: Retrieves a list of all portfolios.
- Method: GET
- URL:
http://localhost:3000/portfolios/:id
- Description: Retrieves details of a portfolio by its ID.
- URL Parameters:
id
(integer): The ID of the portfolio to retrieve.
- Method: POST
- URL:
http://localhost:3000/portfolios
- Description: Creates a new portfolio.
- Request Body:
{ "balance": 1000 }
- Method: GET
- URL:
http://localhost:3000/trades
- Description: Retrieves a list of all trades.
- Method: POST
- URL:
http://localhost:3000/trades/:portfolioId/buy
- Description: Buys shares for a specified portfolio.
- URL Parameters:
portfolioId
(integer): The ID of the portfolio buying shares.
- Request Body:
{ "shareId": "AAP", "amount": 10 }
- Method: POST
- URL:
http://localhost:3000/trades/:portfolioId/sell
- Description: Sells shares for a specified portfolio.
- URL Parameters:
portfolioId
(integer): The ID of the portfolio selling shares.
- Request Body:
{ "shareId": "AAP", "amount": 5 }
- Method: GET
- URL:
http://localhost:3000/portfolios/:portfolioId/shares
- Description: Retrieves the shares associated with a specific portfolio.
- URL Parameters:
portfolioId
(integer): The ID of the portfolio to retrieve shares for.
- Make sure your server is running on
http://localhost:3000
. - Use a tool like Postman to send HTTP requests to the endpoints listed above.
- Ensure you set the
Content-Type: application/json
header for endpoints that require a request body.
curl -X POST http://localhost:3000/shares -H "Content-Type: application/json" -d '{
"name": "AAP",
"price": 100
}'
curl -X POST http://localhost:3000/trades/1/buy -H "Content-Type: application/json" -d '{
"shareId": "AAP",
"amount": 10
}'
curl -X POST http://localhost:3000/trades/1/sell -H "Content-Type: application/json" -d '{
"shareId": "AAP",
"amount": 5
}'
For more details, use the provided Postman collection to interact with the API endpoints.