Skip to content

Instantly share code, notes, and snippets.

@Aneesh540
Last active May 30, 2020 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aneesh540/5cece956a7846057d2af05adff659509 to your computer and use it in GitHub Desktop.
Save Aneesh540/5cece956a7846057d2af05adff659509 to your computer and use it in GitHub Desktop.

API docs for Virtual Stock Exchange app

1. API to get company details by NSE_code

GET : api/NSE_code/:code Response Headers : 200 if found, 404 if not found, 500 for server error

Example

request - localhost:3000/api/NSE_code/LT response - (200)

    "statusCode": 200,
    "data": {
        "code": "LT",
        "name": "Larsen & Toubro Limited",
        "series": "EQ",
        "date_of_listing": "23-Jun-04",
        "paid_up_value": "2",
        "market_lot": "1",
        "ISIN_number": "INE018A01030",
        "face_value": "2"
    }
}

2. API to get possible companies by name

GET api/NSE_name/:name Response Headers : 200 if found, 404 if not found, 500 for server error

Example

request - localhost:3000/api/NSE_code/LT response (200) :

{
   "statusCode": 200,
   "data": [
       {
           "code": "LT",
           "name": "Larsen & Toubro Limited",
           "series": "EQ",
           "date_of_listing": "23-Jun-04",
           "paid_up_value": "2",
           "market_lot": "1",
           "ISIN_number": "INE018A01030",
           "face_value": "2"
       },
       {
           "code": "LTI",
           "name": "Larsen & Toubro Infotech Limited",
           "series": "EQ",
           "date_of_listing": "21-Jul-16",
           "paid_up_value": "1",
           "market_lot": "1",
           "ISIN_number": "INE214T01019",
           "face_value": "1"
       }
   ]
}

3. Login/Signup

POST : api/login/ with post data in json format

Example

POST url : localhost:3000/api/login POST url : localhost:3000/api/signup

JSON data with post request for signup

{
    "email" : "abcd@gmail.com",
    "username" : "bull",
    "password" : "bearish"
}

JSON data with post request for login

   "id" : "Guru",
   "password" : "12345"
}

OR

   "id" : "gururandhawa@gmail.com",
   "password" : "12345"
}

response (200)

{
    "statusCode": 200,
    "username": "Guru",
    "message": "Auth success",
    "token": "xhDUXe4LCEbToCyojsjbqlOIERg"
}

IMP : store this JWT token for further request

token should be passed in Authorization header with Bearer authentication like this

"Authorization" : "Bearer xhDUXe4LCEbToCyojsjbqlOIERg"

4. Show demat account

GET : api/:username (only username not email)

Example

request - localhost:3000/api/Guru Headers should be

  1. "Content-Type" : "application/json"
  2. "Authorization" : "Bearer xhDUXe4LCEbToCyojsjbqlOIERg"

response (200)

{
   "statusCode": 200,
   "data": {
       "total_buy": 63600,
       "total_sell": 28300,
       "available": [
           {
               "quantity": 5,
               "sell_price": -1,
               "buy_date": "2020-05-20T09:58:14.487Z",
               "_id": "5ec4ff36f79c533254132c32",
               "nse_code": "SBIN",
               "name": "State Bank of India",
               "buy_price": 200
           },
           
           
           {
               "quantity": 5,
               "sell_price": -1,
               "buy_date": "2020-05-26T15:06:21.912Z",
               "_id": "5ecd306d6be895198c34d4e9",
               "nse_code": "LT",
               "name": "Larsen & Toubro Limited",
               "buy_price": 1100
           }
       ]
   }
}

5. Share holding of particular share

GET : api/:username/:NSE_code

with Authorization Bearer JWT token of this particular user

Example

request - localhost:3000/api/Guru/LT Headers should be

  1. "Content-Type" : "application/json"
  2. "Authorization" : "Bearer xhDUXe4LCEbToCyojsjbqlOIERg"

response (200)

{
    "statusCode": 200,
    "data": [
        {
            "quantity": 15,
            "sell_price": -1,
            "buy_date": "2020-05-20T09:57:24.484Z",
            "_id": "5ec4ff04f79c533254132c30",
            "nse_code": "LT",
            "name": "Larsen & Toubro",
            "buy_price": 1000
        },
        {
            "quantity": 5,
            "sell_price": -1,
            "buy_date": "2020-05-26T15:06:21.912Z",
            "_id": "5ecd306d6be895198c34d4e9",
            "nse_code": "LT",
            "name": "Larsen & Toubro Limited",
            "buy_price": 1100
        }
    ]
}

6. Buy share

POST : api/:username/buy (buy is constant in url username is only the variable)

Example request - localhost:3000/api/Guru/buy Headers should be

  1. "Content-Type" : "application/json"
  2. "Authorization" : "Bearer xhDUXe4LCEbToCyojsjbqlOIERg"

Post Data

{   
    nse_code : "LT",
    name :"Larsen & Toubro",
    quantity : "10",
    buy_price : "900"
}

response (201) : is correct Just do and check what you get :)

7. Sell share

POST : api/:username/sell

With Content-Type & authorization Bearer header

Post Data ::: For this API call post data is list of json objects

[
{"id" : "5ecd306d6be895198c34d4e9", "quantity" : "5", "price" : 1200},
{"id" : "5ec4ff04f79c533254132c30", "quantity" : "3", "price" : 1300}
]

id is same as what you get during Show Demat account route or Show share holding route i.e. _id of that object quantity and price given by user

response (201) : is correct Just do and check what you get :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment