2.9 KiB
2.9 KiB
Uphold currency rate bot for interview
This project includes a simple API to checkout statistics and health monitoring (requires running DB)
Requirements
- Node.js >= v20
- Docker and Docker Compose (optionally, Podman and Podman compose )
- PostgreSQL (optional, runs in-memory without it)
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 pointsrc/bot.js- Bot logicsrc/api.js- Uphold API clientsrc/db.js- PostgreSQL persistence layersrc/logger.js- Simple loggingsrc/server.js- API server for docker diagnosissrc/stats.js- Runtime statistics trackingtests/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