# Uphold Price Alert Bot ## Requirements - Node.js >= v20 - Docker & Docker Compose (optional) - PostgreSQL (optional, runs in-memory without it) ## Quick Start ### 1. Install Dependencies ```bash npm install ``` ### 2. Run the Bot **With default parameters:** ```bash node index.js ``` or ```bash npm start ``` **With custom parameters:** ```bash node index.js --pairs BTC-USD,ETH-USD --interval 5000 --threshold 0.01 ``` or ```bash npm start -- --pairs BTC-USD,ETH-USD --interval 5000 --threshold 0.01 ``` **With environment file:** ```bash node --env-file=.env.example index.js ``` ### 3. Run with Docker Compose (includes PostgreSQL) ```bash 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 # View logs docker compose logs -f bot ``` ## Configuration | Parameter | Flag | Environment | Default | Description | |-----------|------|-------------|---------|-------------| | Pairs | `-p, --pairs` | `PAIRS` | `BTC-USD` | Comma-separated currency pairs | | Interval | `-i, --interval` | `INTERVAL` | `5000` | Check interval in milliseconds | | Threshold | `-t, --threshold` | `THRESHOLD` | `0.01` | Alert threshold percentage | | Stats | `--stats` | `STATS` | `false` | Show performance statistics | ## Database Setup (Optional) The bot runs in-memory mode by default. To persist alerts: ```bash # Set DATABASE_URL export DATABASE_URL="postgres://user:password@localhost:5432/uphold_db" # Run the bot node index.js ``` The `alerts` table is created automatically on first run. ## Running Tests ```bash npm test ``` ## Example Output ``` [INFO] Uphold price alert bot starting... [INFO] [WATCHING] BTC-USD, ETH-USD | Every 5000ms | Threshold 0.01% [INFO] [BTC-USD] Initial price: 42350.50 [INFO] [ETH-USD] Initial price: 2245.75 [INFO] [ALERT] BTC-USD UP 0.0125% (42350.50 → 42355.79) [INFO] [DB] Event saved for BTC-USD ``` ## Architecture - `index.js` - Entry point - `src/bot.js` - Bot monitoring logic - `src/api.js` - Uphold API client with rate limiting - `src/db.js` - PostgreSQL DB layer - `src/logger.js` - logging - `tests/bot.test.js` - Test suite ## Stopping the Bot Press `Ctrl+C` or send `SIGTERM` for graceful shutdown. With Docker: ```bash docker compose down ``` ## License MIT