No description
Find a file
2025-11-28 20:35:40 +00:00
src Last update 2025-11-28 20:33:15 +00:00
tests Last update 2025-11-28 20:33:15 +00:00
.dockerignore Changes to logging and db logic 2025-11-27 17:12:06 +00:00
.env Better error handling, caching and deduplication. Added tests to api and db logic 2025-11-28 15:07:10 +00:00
.env.example Updated readme, stats and api server 2025-11-28 18:56:21 +00:00
.gitignore Updated gitignore 2025-11-28 20:35:40 +00:00
compose.yml Updated compose file for better Docker integration 2025-11-28 20:21:57 +00:00
Containerfile Updated readme, stats and api server 2025-11-28 18:56:21 +00:00
index.js Last update 2025-11-28 20:33:15 +00:00
package.json Better error handling, caching and deduplication. Added tests to api and db logic 2025-11-28 15:07:10 +00:00
README.md Updated README 2025-11-28 20:34:29 +00:00

Uphold currency rate bot for interview

Requirements

  • Node.js >= v20
  • Docker and Docker Compose (optionally, Podman and Podman compose)
  • PostgreSQL (if running outside of Docker)

Quick Start

1. Install Dependencies

npm install

2. Run the Bot

With default parameters, no DB or API:

node index.js

or

npm start

With custom parameters:

node index.js --pairs BTC-USD,ETH-USD --interval 10000 --threshold 0.05

or

npm start -- --pairs BTC-USD,ETH-USD --interval 10000 --threshold 0.01

With environment file:

node --env-file=.env.example index.js

3. Run with Docker/Podman Compose (includes DB and API)

cp .env.example .env

Edit .env with your settings:

POSTGRES_USER=uphold
POSTGRES_PASSWORD=uphold
POSTGRES_DB=uphold_db
PAIRS=BTC-USD,ETH-USD
INTERVAL=5000
THRESHOLD=0.01
# Start services
docker compose up -d --build 

or

podman compose up -d --build

View logs

docker compose logs -f uphold_bot_1

or

podman compose logs -f uphold_bot_1

Configuration

Parameter Flag Environment Default Description
Pairs -p, --pairs PAIRS BTC-USD Comma-separated currency pairs
Interval -i, --interval INTERVAL 5000 Uphold API retrieval interval in milliseconds
Threshold -t, --threshold THRESHOLD 0.01 Alert difference percentage

Running Tests

npm test

API

Endpoints

Health Check

curl http://localhost:3000/health

Statistics

curl http://localhost:3000/stats

Alerts

# Get last 50 alerts (default)
curl http://localhost:3000/alerts

# Get last 100 alerts
curl http://localhost:3000/alerts?limit=100

Example Output

[18:44:51.898] INFO: Bot starting...
[18:44:51.898] INFO: [WATCHING] BTC-USD | Every 5000ms | Threshold 0.01%
[18:44:51.898] WARN: [DB] specificiation missing. Running in memor
[18:44:52.167] INFO: [BTC-USD] Monitoring every 5000ms, +/-0.01%
[18:44:52.367] INFO: [BTC-USD] Initial price: 90977.65
[18:45:07.879] INFO: [ALERT] BTC-USD DOWN -0.0116%
    pair: "BTC-USD"
    direction: "DOWN"
    change: "-0.0116%"
    prev: "90977.648894"
    curr: "90967.085674"

Architecture

  • index.js - Entry point
  • src/bot.js - Bot logic
  • src/api.js - Uphold API client
  • src/db.js - DB logic
  • src/logger.js - Simple logging
  • src/server.js - API server for docker diagnosis
  • src/stats.js - Statistics tracking
  • tests/bot.test.js - Tests

Stopping the Bot

Press Ctrl+C or send SIGTERM for graceful shutdown.

With Docker:

docker compose down

or Podman

podman compose down
podman volume rm uphold_pgdata