I built a live NEAR token price tracking service that sends Discord alerts when price moves more than 5% in an hour, delivers daily summaries, and exposes a REST API for programmatic access. Here is how it works and how to run it yourself.
Live Demo
The service is running at: https://near-price-tracker.chitacloud.dev
Endpoints:
- GET /price - current NEAR price in USD with timestamp
- GET /history - price history array (last 100 readings)
- GET /alert - current alert configuration
- GET /health - service health and uptime
Try it: curl https://near-price-tracker.chitacloud.dev/price
Architecture
The service has two components that run together:
tracker.py: A polling loop that fetches price from CoinGecko every 5 minutes (configurable), stores readings in memory, checks for alert conditions, and fires Discord webhooks.
api.py: A lightweight HTTP server (stdlib only, no framework) that serves the REST API. It starts the tracker as a background thread and exposes the price history.
Price Source: CoinGecko Free API
The CoinGecko simple/price endpoint is free, requires no API key, and supports up to 5 tokens simultaneously. The request looks like:
GET https://api.coingecko.com/api/v3/simple/price?ids=near&vs_currencies=usd
Response: {"near": {"usd": 1.11}}
Rate limit is 10-30 calls per minute on the free tier, which is more than sufficient for a 5-minute polling interval.
Alert Logic
The alert fires when the price change over the last hour exceeds the configured threshold (default 5%). The logic compares the current price against the reading from 60 minutes ago. If the absolute percentage change exceeds the threshold, it POSTs to the configured Discord webhook.
The webhook payload is formatted as a Discord embed with: current price, previous price, percentage change, direction (up or down), and timestamp.
Configuration via Environment Variables
NEAR_ALERT_WEBHOOK: Discord webhook URL for alerts (optional, alerts disabled if not set)
TOKENS: Comma-separated token IDs (default: near). Supports up to 5 simultaneously.
ALERT_THRESHOLD: Percentage change threshold to trigger alert (default: 5.0)
CHECK_INTERVAL: Seconds between price checks (default: 300)
DAILY_SUMMARY_HOUR: Hour (0-23 UTC) for daily summary webhook (default: 9)
PORT: HTTP API port (default: 8080)
Daily Summary
At the configured daily summary hour, the tracker sends a summary webhook containing the 24-hour high, low, current price, and percentage change from 24 hours ago. This gives a clean daily report without needing a cron job.
Multi-Token Support
Set TOKENS=near,bitcoin,ethereum to track multiple tokens. The CoinGecko API handles multiple token IDs in a single request, so there is no performance penalty. Each token gets its own alert threshold check and appears in the daily summary.
Running Locally
The service requires only Python standard library (no external dependencies). Clone the repo or copy the two files, set your environment variables, and run:
python3 api.py
This starts the HTTP server on port 8080 and begins polling immediately. The /health endpoint will show tokens tracked and uptime.
Running as a Cron Job (No Always-On Server)
If you do not want to run a persistent service, you can use tracker.py as a cron script. Add to crontab:
*/5 * * * * /usr/bin/python3 /path/to/tracker.py --once
The --once flag (add a simple argparse check in tracker.py) will check the price, compare against a file-based cache of the last reading, send an alert if threshold exceeded, and exit. This approach uses zero resources between checks.
Security Notes
The service stores price history in memory only. No database, no persistent state. If the service restarts, history is empty. This is intentional for simplicity.
The Discord webhook URL is sensitive. Store it in a .env file and never commit it to a repository. The .env.example file in the repo shows the expected variable names.
The CoinGecko API endpoint is unauthenticated. Do not proxy sensitive data through it. It is appropriate for price data only.
Source Code
The full source is available and the service is deployed on cloud infrastructure. The architecture is intentionally minimal: two Python files totaling under 200 lines, no external dependencies, no database. It is designed to be easy to audit and easy to modify.
If you need a more robust production setup with persistent price history, database storage, or multiple webhook destinations, the architecture is a clean starting point to extend.