- SuperTraders is a trading platform that allows users to buy and sell shares.
- This repo includes two project :
- Api project (developed with Node.js, PostgreSQL, Sequelize, and Express.js).
- Web project (developed with Reactjs)
-
Clone the repository:
git clone https://github.com/muratsercann/SuperTraders.git
-
Install the required dependencies for the api project:
cd supertraders npm install
-
Configure the database settings in
src/database/config.js
to match your setup. -
Start the api project:
cd supertrades npm start
When the application is first run, the database and tables will be created automatically if they do not already exist. And seeded with users and shares and transactions for buy and sell.
post http://localhost:3000/api/trade/buy
: buys a share for a user portfoliopost http://localhost:3000/api/trade/sell
: sells a share for a user portfolioget http://localhost:3000/api/trade/shares
: gets all sharesget http://localhost:3000/api/trade/users
: gets all users with relational dataget http://localhost:3000/api/trade/logs
: gets all transaction logs
Note : For testing buy and sell endpoints via postman, you can import and use the json file, I exported from the postman, in the .postman/
folder.
- URL:
/api/trade/buy
- Method:
POST
- Request Format:
{ "userId": 1, "shareId": 1, "quantity": 1 }
If the user has a portfolio and the portfolio limit is sufficient, the specified amount of the shares is purchased. The quantity
in the Share
table is reduced by the amount specified in the request body. The share are added to the user's portfolio by specified amount, and the portfolio limit is decreased by the total price.
- URL:
/api/trade/sell
- Method:
POST
- Request Format:
{ "userId": 1, "shareId": 1, "quantity": 1 }
If the user has enough of the specified share in his portfolio, the specified amount of the shares is sold. The quantity
in the Share
table is increased by the amount, the shares are removed from the user's portfolio by the amount specified in the request body, and the portfolio limit is increased by the total price.
-
Share: Stores share information.
id
: Share IDsymbol
: Share symbolcurrentPrice
: Current price of the sharequantity
: Quantity of the share- timestamps is true
-
User: Stores user information.
id
: User IDusername
: Usernameemail
: User email address- timestamps is true
-
Portfolio: Stores user portfolio information.
id
: Portfolio IDuserId (FK)
: User IDname
: Portfolio namedescription
: Portfolio descriptionlimit
: Portfolio limit for trading shares- timestamps is true
-
PortfolioShare: Stores information about shares in portfolios.
id
: Record IDportfolioId (FK)
: Portfolio IDshareId (FK)
: Share IDquantity
: Quantity of the share in the portfolio- timestamps is true
-
Transactionlog: Stores transaction logs.
id
: Record IDuserId
: User IDportfolioId
: Portfolio IDshareId
: Share IDtransactionType
: Type of transaction (buy/sell)quantity
: Transaction quantitypricePerShare
: Price per sharetotalPrice
: Total pricebeforeLimit
: Limit before the transactionafterLimit
: Limit after the transaction- timestamps is true
In the web
directory of this repo, there is a React.js
project that provides a web interface to view the data in the database. This web interface has three pages:
Shares
: Displays all shares.Portfolios
: Shows all portfolios with user info and the shares within those portfolios.Transactionlog
: Displays the transaction history
- Navigate to the
web
directory:cd web
- Install the required dependencies:
npm install
- Start the React application:
The web interface will be available at
npm start
http://localhost:3001
. If you want to change the PORT, update it from the.env
file