Skip to content

SimuTrade API is a RESTful API that provides a platform for managing and trading simulated stocks and portfolios.

License

Notifications You must be signed in to change notification settings

RishikeshNK/simutrade-api

Repository files navigation

SimuTrade API

SimuTrade API is a RESTful API built using Express.js and Docker. It provides a platform for managing and trading simulated stocks and portfolios.

Getting Started

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.

Dependencies

Route Map (Usage)

  • 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 as Bearer [accessToken] where [accessToken] is the token you copied earlier. For more information on configuring request headers, see the Postman documentation.
  • POST /api/v1/auth/login
    • To log in to an existing account, send a POST request to /api/v1/auth/login. Copy the accessToken and set it as the Bearer token similar to the registration step.
    • Request format:
      {
          "email": "[email]",
          "password": "[password]"
      }
  • 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]"
      }
  • 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.
  • GET /api/v1/users/profile
    • In order to get information about the logged-in user, send a GET request to /api/v1/users/profile.
  • 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.
  • 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
  • GET /api/v1/stocks/all
    • In order to get all the tradeable stocks on SimuTrade, send a GET request to /api/v1/stocks/all.
  • 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]"
      }
  • 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]"
      }
  • POST /api/v1/stocks/sell

Usage

To get started with SimuTrade API, follow the steps below:

  1. Clone the repository.
git clone [email protected]:RishikeshNK/simtrade-api.git
cd simutrade-api
  1. Install the necessary dependencies by running npm install.
  2. Configure the .env file by following the template in .env.example. See Setting up the environment.
  3. Run the docker container.
docker compose up -d
  1. Seed the database
npm run seed
  1. Run the application
npm start

Future Plans

  • 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.

Setting up the environment

  1. Create a new file called .env or copy the .env.example and rename it to .env.
cp .env.example .env
  1. 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.

About

SimuTrade API is a RESTful API that provides a platform for managing and trading simulated stocks and portfolios.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •