Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Contract for stock-exchange #40

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions crypto/stock-exchange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Stock Exchange

## Firestore Collections

* Stocks
> this will contain details of all stocks that should be listed

## Stock Object

```
{
"name": <stock_name>,
"price": <listed_price>,
"quantity": <available_quantity>
}
```

## Trading Request Object

```
{
"tradeType": "buy/sell",
"stockName": <name_of_the_stock>,
"quantity": <number_of_quantities>,
"listedPrice": <listed_stock_price>,
"totalPrice": <total_purchase_price>
}
```

## Trading Response Object

```
{
"userBalance": <balance left with user after successful trade>
}
```

## **Requests**

| Route | Description |
| :--------------------------------: | :---------------: |
| [GET /stocks](#get-stocks) | Returns all stocks to be listed |
| [POST /stocks](#post-stocks) | Creates new stock |
| [PATCH /trade/:username](#patch-tradeusername) | New trading request |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the username here? Can we not get the user details from the userId in the JWT?

Also, /trade/new seems to make a bit more sense about the order being a new trade


## **GET /stocks**

Returns all the stocks to be listed

- **Params**
None
- **Query**
None
- **Body**
None
- **Headers**
None
- **Cookie**
None
- **Success Response:**
- **Code:** 200
- **Content:**

```
{
message: 'Stocks returned successfully!'
stocks: [
{<stock_object>},
{<stock_object>}
]
}
```

- **Error Response:**
- **Code:** 500
- **Content:** `{ 'statusCode': 500, 'error': 'Internal Server Error', 'message': 'An internal server error occurred' }`

## **POST /stocks**

- **Params**
None
- **Query**
None
- **Headers**
Content-Type: application/json
- **Body** `{ <stock_object> }`
- **Success Response:**
- **Code:** 200
- **Content:**

```
{
message: 'Stock created successfully!'
stock: {<stock_object>}
id: <newly created stock id>
}
```

- **Error Response:**
- **Code:** 500
- **Content:** `{ 'statusCode': 500, 'error': 'Internal Server Error', 'message': 'An internal server error occurred' }`

## **PATCH /trade/:username**

- **Params**
_Required:_ `username=[string]`

- **Headers**
Content-Type: application/json
- **Cookie**
rds-session: `<JWT>`
- **Body** `{ <trading_request_object> }`
- **Success Response:**
- **Code:** 200
- **Content:** `{<trading_response_object>}`
- **Error Response:**
- **Code:** 403
- **Content:** `{ 'statusCode': 403, 'error': 'Forbidden', 'message': 'Trading failed due to insufficient funds'}`
- **Code:** 500
- **Content:** `{ 'statusCode': 500, 'error': 'Internal Server Error', 'message': 'An internal server error occurred' }`