Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=16-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}

WORKDIR /reference-data
COPY . .
EXPOSE 18085

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
ARG EXTRA_NODE_VERSION=18
RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
RUN npm install
ENTRYPOINT npm run start
152 changes: 150 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,150 @@
# traderXReferenceDataService
Microservice containing the reference data service from the TraderXCognitionDemos repo
# TraderX Reference Data Service

![DEV Only Warning](https://badgen.net/badge/warning/not-for-production/red) ![Local Dev Machine Supported](http://badgen.net/badge/local-dev/supported/green)

A standalone Node.js/NestJS REST service that provides stock ticker symbol reference data from S&P 500 companies. This service was extracted from the TraderX sample trading application to run independently.

## Features

- RESTful API for stock reference data
- S&P 500 companies dataset (505+ securities)
- OpenAPI/Swagger documentation
- Health check endpoint
- Docker support for containerized deployment

## Prerequisites

- Node.js (version 16 or higher)
- npm package manager
- Docker (optional, for containerized deployment)

## Configuration

The service can be configured using the following environment variables:

| Environment Variable Name | Default Value | Description |
| --------------------------- | ------------- | ----------- |
| REFERENCE_DATA_SERVICE_PORT | 18085 | Port number for the service |
| REFERENCE_DATA_HOSTNAME | 0.0.0.0 | Hostname/IP to bind to |

## Installation

```bash
$ npm install
```

## Running the Service

### Local Development

```bash
# Install dependencies
$ npm install

# Start the service
$ npm run start

# Development mode with file watching
$ npm run start:dev

# Production mode
$ npm run start:prod
```

### Docker Deployment

```bash
# Build and start with Docker Compose
$ docker-compose up --build

# Or build and run manually
$ docker build -t reference-data-service .
$ docker run -p 18085:18085 reference-data-service
```

## API Endpoints

Once the service is running (default: http://localhost:18085), the following endpoints are available:

### REST API
- **GET /stocks** - Returns all securities in the S&P 500 dataset
- **GET /stocks/{ticker}** - Returns specific security by ticker symbol (e.g., AAPL, MSFT)
- **GET /health** - Health check endpoint

### Documentation
- **GET /api** - Interactive OpenAPI/Swagger documentation

### Example Usage

```bash
# Get all stocks
curl http://localhost:18085/stocks

# Get specific stock by ticker
curl http://localhost:18085/stocks/AAPL

# Health check
curl http://localhost:18085/health
```

## API Response Format

### Stock Object
```json
{
"ticker": "AAPL",
"companyName": "Apple Inc."
}
```

### All Stocks Response
```json
[
{
"ticker": "AAPL",
"companyName": "Apple Inc."
},
{
"ticker": "MSFT",
"companyName": "Microsoft Corporation"
}
]
```

## Data Source

The service uses S&P 500 company data from a CSV file located at `./data/s-and-p-500-companies.csv`. This dataset includes:
- Stock ticker symbols
- Company names
- Additional metadata (SEC filings, GICS sectors, headquarters, etc.)

The CSV data was sourced from [Wikipedia's List of S&P 500 companies](https://en.wikipedia.org/wiki/List_of_S%26P_500_companies#S&P_500_component_stocks).

## Development and Testing

### Running Tests
```bash
# Unit tests
$ npm run test

# End-to-end tests
$ npm run test:e2e

# Test coverage
$ npm run test:cov
```

### Mock Service (Optional)
For testing purposes, you can run a mock service using Prism:

```bash
# Install Prism CLI globally
npm install -g @stoplight/prism-cli

# Run mock service
prism mock openapi.yaml --port 18085 --cors
```

## License

Apache-2.0
55 changes: 55 additions & 0 deletions base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=20-bullseye
FROM node:${VARIANT}

# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="true"

# Install needed packages, yarn, nvm and setup non-root user. Use a separate RUN statement to add your own dependencies.
ARG USERNAME=node
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ARG NPM_GLOBAL=/usr/local/share/npm-global
ENV NVM_DIR=/usr/local/share/nvm
ENV NVM_SYMLINK_CURRENT=true \
PATH=${NPM_GLOBAL}/bin:${NVM_DIR}/current/bin:${PATH}
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common \
# Install common packages, non-root user, update yarn and install nvm
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
# Install yarn, nvm
&& rm -rf /opt/yarn-* /usr/local/bin/yarn /usr/local/bin/yarnpkg \
&& bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "none" "${USERNAME}" \
# Configure global npm install location, use group to adapt to UID/GID changes
&& if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \
&& usermod -a -G npm ${USERNAME} \
&& umask 0002 \
&& mkdir -p ${NPM_GLOBAL} \
&& touch /usr/local/etc/npmrc \
&& chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \
&& chmod g+s ${NPM_GLOBAL} \
&& npm config -g set prefix ${NPM_GLOBAL} \
&& sudo -u ${USERNAME} npm config -g set prefix ${NPM_GLOBAL} \
# Install eslint
&& su ${USERNAME} -c "umask 0002 && npm install -g eslint" \
&& npm cache clean --force > /dev/null 2>&1 \
# Install python-is-python3 on bullseye to prevent node-gyp regressions
&& . /etc/os-release \
&& if [ "${VERSION_CODENAME}" = "bullseye" ]; then apt-get -y install --no-install-recommends python-is-python3; fi \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /root/.gnupg /tmp/library-scripts

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>""
Loading