faang-stonks

command module
v0.0.0-...-a9a37cd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: MIT Imports: 2 Imported by: 0

README

faang-stonks

No affiliation with, but inspired by r/Superstonks.

Requirements

  • Create a REST API where clients can retrieve stock data for FAANG companies
    • Optionally, clients can request historical data for one or more stocks
  • Service should update stock prices every N minutes where N is configurable
  • Service and supporting services (e.g., database, web layer, etc.) should be packages with Dockerfiles, and a docker-compose.yml file allowing full application instantiation.
  • Use git for version control and frequently commit changes.

Motivation

This project is my attempt to find a happy medium between scalable, simple, flexible, simple, readable (i.e., not clever to the point of illegible code), secure, and simple. Simple's the hard part.

Discussion

The project's requirements don't specify the scale at which this service should operate. As such, I took my usual approach: keep things simple yet flexible to meet future requirements without the need for a complete code refactor.

For example, SQLite isn't the best choice for time-series data storage at scale, but it's good enough for this MVP in the absence of detailed scale requirements. I've included a stub for InfluxDB to illustrate how I could add support for it without affecting the rest of the code. I also included an in- memory implementation.

You'll find a similar pattern for financial data providers. I define an interface the rest of the code consumes, and then add an implementation of that interface for my financial data provider (IEX Cloud in this case).

API Resources

The API exposes two endpoints: one for retrieving all stocks and another for requesting quotes of a specific stock symbol. The API endpoints are versioned with v1.

  • GET /v1/stocks
  • GET /v1/stock/[symbol]

All timestamps returned by the API are in UTC.

Last N Quotes

Each API endpoint allows for an optional parameter last that will direct the API to return the last n quotes, or the maximum observed quotes, whichever is less.

GET /v1/stocks

Example: http://localhost:18081/v1/stocks

Response body:

{
  "aapl": [
    {
      "price": 130.4,
      "symbol": "aapl",
      "time": "2021-05-07T19:31:07.000000272Z"
    }
  ],
  "amzn": [
    {
      "price": 3296.16,
      "symbol": "amzn",
      "time": "2021-05-07T19:31:07.000000623Z"
    }
  ],
  "fb": [
    {
      "price": 320.125,
      "symbol": "fb",
      "time": "2021-05-07T19:31:05.000000929Z"
    }
  ],
  "goog": [
    {
      "price": 2402.14,
      "symbol": "goog",
      "time": "2021-05-07T19:30:21.000000201Z"
    }
  ],
  "nflx": [
    {
      "price": 504.08,
      "symbol": "nflx",
      "time": "2021-05-07T19:31:00.000000053Z"
    }
  ]
}
GET /v1/stock/goog

Example: http://localhost:18081/v1/stock/goog

Response body:

[
  {
    "price": 2403.06,
    "symbol": "goog",
    "time": "2021-05-07T19:32:08.000000511Z"
  }
]
GET /v1/stock/fb?last=3

Example: http://localhost:18081/v1/stock/goog?last=3

Response body:

[
  {
    "price": 320.12,
    "symbol": "fb",
    "time": "2021-05-07T19:36:02.000000631Z"
  },
  {
    "price": 319.92,
    "symbol": "fb",
    "time": "2021-05-07T19:35:09.000000338Z"
  },
  {
    "price": 319.99,
    "symbol": "fb",
    "time": "2021-05-07T19:34:08.00000012Z"
  }
]

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package api provides a HTTP(S) server that serves a REST API that serves financial data for a subset of stock symbols.
Package api provides a HTTP(S) server that serves a REST API that serves financial data for a subset of stock symbols.
Package cmd adds command line support to this application.
Package cmd adds command line support to this application.
Package finance provides interfaces and types for financial data services.
Package finance provides interfaces and types for financial data services.
iexcloud
Package iexcloud provides a finance.Provider implementation that retrieves its data from IEX Cloud's API.
Package iexcloud provides a finance.Provider implementation that retrieves its data from IEX Cloud's API.
Package history provides interfaces and types for objects that store store a retrieve historical financial data.
Package history provides interfaces and types for objects that store store a retrieve historical financial data.
influxdb
Package influxdb provides history.Archiver and history.Provider implementations that use the time series database, InfluxDB.
Package influxdb provides history.Archiver and history.Provider implementations that use the time series database, InfluxDB.
memory
Package memory provides history.Archiver and history.Provider implementations that use RAM for volatile storage.
Package memory provides history.Archiver and history.Provider implementations that use RAM for volatile storage.
sqlite
Package sqlite provides history.Archiver and history.Provider implementations that use SQLite for storage.
Package sqlite provides history.Archiver and history.Provider implementations that use SQLite for storage.
Package metrics provides instrumentation for the rest of the application, and the requisite HTTP server to serve the Prometheus endpoint separate from the REST API endpoint.
Package metrics provides instrumentation for the rest of the application, and the requisite HTTP server to serve the Prometheus endpoint separate from the REST API endpoint.
Package poll provides a poller that retrieves financial data for the given stock symbols at the given interval and updates the archiver with the results.
Package poll provides a poller that retrieves financial data for the given stock symbols at the given interval and updates the archiver with the results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL