SimuTrade API is a RESTful API built using Express.js and Docker. It provides a platform for managing and trading simulated stocks and portfolios.
Swagger documentation would be written shortly. Please refer to Route Map (Usage) for more information regarding the implemented routes. For installation instructions, please follow the instructions in Usage below.
- POST
/api/v1/auth/register
- Start by sending a POST request to
/api/v1/auth/register
and registering a new account. - Request format:
{ "email": "[email protected]", "password": "password" }
- Note down the
accessToken
returned and set that as the Bearer token (in Postman perhaps) by setting the "Authorization" header asBearer [accessToken]
where[accessToken]
is the token you copied earlier. For more information on configuring request headers, see the Postman documentation.
- Start by sending a POST request to
- POST
/api/v1/auth/login
- To log in to an existing account, send a POST request to
/api/v1/auth/login
. Copy theaccessToken
and set it as the Bearer token similar to the registration step. - Request format:
{ "email": "[email]", "password": "[password]" }
- To log in to an existing account, send a POST request to
- POST
/api/v1/auth/refreshToken
- In order to generate a new refresh token, send a POST request to
/api/v1/auth/refreshToken
. - Request format:
{ "refreshToken": "[token]" }
- In order to generate a new refresh token, send a POST request to
- POST
/api/v1/auth/revokeRefreshTokens
(Do not expose this end-point in a production environment)- In order to revoke tokens for a user, send a POST request to
/api/v1/auth/revokeRefreshTokens
. Do not expose this end-point in production (only for development purposes)! - Request format:
{ "userId": "[userId]" }
- One possible use case for this end-point is for allowing a password reset functionality in the future.
- In order to revoke tokens for a user, send a POST request to
- GET
/api/v1/users/profile
- In order to get information about the logged-in user, send a GET request to
/api/v1/users/profile
.
- In order to get information about the logged-in user, send a GET request to
- GET
/api/v1/users/holdings
- In order to get all the holdings of the logged-in user, send a GET request to
/api/v1/users/holdings
.
- In order to get all the holdings of the logged-in user, send a GET request to
- GET
/api/v1/users/transactions
- In order to get all the past transactions of the logged-in user, send a GET request to
/api/v1/users/transactions
- In order to get all the past transactions of the logged-in user, send a GET request to
- GET
/api/v1/stocks/all
- In order to get all the tradeable stocks on SimuTrade, send a GET request to
/api/v1/stocks/all
.
- In order to get all the tradeable stocks on SimuTrade, send a GET request to
- POST
/api/v1/stocks/quote
- In order to get the quote of a specific quote, send a POST request to
/api/v1/stocks/quote
. - Request format:
{ "ticker": "[ticker]" }
- In order to get the quote of a specific quote, send a POST request to
- POST
/api/v1/stocks/buy
- To place a market buy order, send a POST request to
/api/v1/trade/buy
. - Request format:
{ "ticker": "[ticker]", "quantity": "[quantity]" }
- To place a market buy order, send a POST request to
- POST
/api/v1/stocks/sell
To get started with SimuTrade API, follow the steps below:
- Clone the repository.
git clone [email protected]:RishikeshNK/simtrade-api.git
cd simutrade-api
- Install the necessary dependencies by running
npm install
. - Configure the
.env
file by following the template in.env.example
. See Setting up the environment. - Run the docker container.
docker compose up -d
- Seed the database
npm run seed
- Run the application
npm start
- Implement the remaining REST endpoints. See Route Map for current progress.
- Write Zod validation schemas for validating and type-checking requests.
- Write a
seed.ts
script to fetch the latest closing prices of stocks (primarily in the S&P500) using a static API. - Write Swagger documentation for the API.
- Implement different user roles (e.g., admin, regular user) with varying levels of access.
- Implement email verification for new users to ensure the validity of email addresses using SMTP. As a result, implement a
/api/v1/auth/forgot-password
end-point. - Integrate with a real-time stock data provider to offer up-to-the-minute stock prices and market data. See Alpaca.
- Write unit tests for the codebase.
- Write a front-end for the API. Possibly port the application from Express.js to Next.js. Consider potential hosting options such as Vercel.
- Create a new file called
.env
or copy the.env.example
and rename it to.env
.
cp .env.example .env
- Complete the file to add your environment variables. It is prepopulated with potential arguments (for Postgres connection) and commands you can run (for generating JWT secret tokens) to get your
.env
file up and running.