Skip to content

Repository files navigation

StockSortingService

A sample request body looks like this:

{
  "sortBy": "price",
  "sortOrder": "asc",
  "stocks": [
    {
      "ticker": "AAPL",
      "price": 235.86,
      "changePercent": -0.26,
      "52WLow": 164.08,
      "52WHigh": 237.49,
      "recommendation": "buy" 
    },
    {
      "ticker": "TSLA",
      "price": 217.97,
      "changePercent": -0.4,
      "52WLow": 138.8,
      "52WHigh": 271.0,
      "recommendation": "hold"
    },
    {
      "ticker": "PLTR",
      "price": 42.94,
      "changePercent": 0.56,
      "52WLow": 14.48,
      "52WHigh": 44.39,
      "recommendation": "hold" 
    },
    {
      "ticker": "GOOG",
      "price": 166.82,
      "changePercent": 0.62,
      "52WLow": 121.46,
      "52WHigh": 193.31,
      "recommendation": "buy"
    }
  ]
}
  • The "sortBy" property specifies which stock object property to sort on. It must be present in each stock object or an error will be returned. If this property is not included in the request, it defaults to "price".
  • The "sortOrder" property specifies to sort on either ascending or descending. If this property is not included in the request, it defaults to "asc" for ascending.
  • The "stocks" property is the unordered array of stock objects to be sorted. This much be included in the request or an error will be returned. Additionally, as noted above, each object within this array must include the property specified in the "sortBy", or "price" if "sortBy" is not provided.

Note:

StockSortService.postman_collection.json provides a variety of sample requests which may be referenced.

Sample Request

An example call using the Python requests library may look like the below, where {request body} is referenced in the sample above.

stockSortRequest = requests.post("https://stocksortingservice.onrender.com/stocksort", json={request body})

Sample Response Handling

Additionally, the service returns a 200 status for successful requests along with the sorted array, or a 400 service for unsuccessful requests, along with error message.

A simple check on status in the requesting application's code can determine how to process the response. Example below is again using the Python requests library.

if stockSortRequest.status_code == 200:
  stockSortResponse = stockSortRequest.json()

Sequence Diagram UML

Sequence Diagram UML

About

RESTful Flask microservice for sorting stock data by client-defined fields and order. Validates JSON input and returns sorted results. Features a modular, testable design with a reusable StockSorter class.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages