Stock Exchange

API Reference

Complete REST API documentation for Stock Exchange

Base URL

All API endpoints are available at:

http://localhost:3000

Endpoints

Place Limit Order

Place a new limit order on the exchange.

POST /order
Content-Type: application/json

{
  "userID": 6,
  "type": "LIMIT",
  "bid": true,
  "size": 10,
  "price": 1000,
  "market": "INN"
}
{
  "OrderID": 60464691
}

Parameters

ParameterTypeRequiredDescription
userIDintegerYesUnique identifier for the user
typestringYesOrder type: LIMIT or MARKET
bidbooleanYestrue for buy orders, false for sell orders
sizeintegerYesNumber of shares to trade
pricefloatYes*Price per share (*required for LIMIT orders only)
marketstringYesTrading symbol/ticker (e.g., "INN", "AAPL")

Get User Orders

Retrieve all orders for a specific user.

GET /order/{userID}
{
  "orders": [
    {
      "ID": 60464691,
      "UserID": 6,
      "Price": 1000,
      "Size": 10,
      "Bid": true,
      "Timestamp": 1699887123000
    },
    {
      "ID": 85937264,
      "UserID": 6,
      "Price": 999,
      "Size": 44,
      "Bid": true,
      "Timestamp": 1699887125000
    }
  ]
}

Get Best Ask

Get the best (lowest) ask price for a market.

GET /book/{market}/ask
{
  "Bid": false,
  "ID": 0,
  "Price": 990,
  "Size": 0,
  "Timestamp": 0,
  "UserID": 8
}

Get Best Bid

Get the best (highest) bid price for a market.

GET /book/{market}/bid
{
  "Bid": true,
  "ID": 0,
  "Price": 970,
  "Size": 0,
  "Timestamp": 0,
  "UserID": 8
}

Get All Trades

Retrieve all executed trades for a specific market.

GET /trades/{market}
{
  "trades": [
    {
      "price": 1000,
      "size": 100,
      "timestamp": 1699887120000,
      "bid": true
    },
    {
      "price": 1001,
      "size": 50,
      "timestamp": 1699887125000,
      "bid": false
    }
  ]
}

Response Codes

CodeDescription
200Success
400Bad Request - Invalid parameters
404Not Found - Resource doesn't exist
500Internal Server Error

Rate Limiting

Currently, there are no rate limits implemented. In production, you should implement appropriate rate limiting to prevent abuse.

Error Responses

Error responses follow this format:

{
  "error": "Error message description",
  "code": "ERROR_CODE"
}

Next Steps

On this page