Corrected README
This commit is contained in:
parent
8929d4cd6e
commit
5d2710350e
3 changed files with 132 additions and 3 deletions
6
.env.example
Normal file
6
.env.example
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
PAIRS=BTC-USD,CNYUSD
|
||||
INTERVAL=5000
|
||||
THRESHOLD=0.05
|
||||
POSTGRES_USER=uphold
|
||||
POSTGRES_PASSWORD=uphold
|
||||
POSTGRES_DB=uphold_events
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
FROM docker.io/node:20-alpine
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
# RUN npm ci --omit=dev
|
||||
RUN npm ci
|
||||
COPY src/ ./src/
|
||||
COPY index.js ./
|
||||
|
||||
RUN addgroup -g 1001 nodejs && adduser -S -G nodejs -u 1001 nodejs
|
||||
USER nodejs
|
||||
RUN addgroup -g 1001 uphold && adduser -S -G uphold -u 1001 uphold
|
||||
USER uphold
|
||||
|
||||
ENTRYPOINT ["node", "index.js"]
|
||||
|
|
|
|||
124
README.md
124
README.md
|
|
@ -0,0 +1,124 @@
|
|||
# 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
|
||||
|
||||
**Basic:**
|
||||
```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
|
||||
|
||||
# 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
|
||||
Loading…
Reference in a new issue