Price Alert Bot
Goal: Create a Telegram bot that notifies users when a specific trading pair (e.g., TON-USDT) crosses a predefined price threshold.
Key xRocket API Features Used:
- Public REST API: For periodically fetching market data (the ticker).
- Telegram Bot API: For sending messages to users.
Workflow:
- User Interaction: A user interacts with your bot in Telegram and sends a command like
/alert TON-USDT 2.50. - Bot Logic: Your bot parses the command and stores the user's chat ID, trading pair, and target price in a database.
- Data Polling: A background process in your bot regularly polls the xRocket public REST API's ticker endpoint (
GET /api/v1/ticker/24h) for the latest price. - Threshold Check: The bot compares the current price to the stored threshold for each user.
- Notification: If the price crosses the threshold, the bot uses the Telegram Bot API to send a message back to the user's chat ID: "TON-USDT has reached 2.50!"
tip
For lower latency, consider subscribing to the WebSocket Ticker channel instead of polling the REST API. This delivers price updates in real time and reduces unnecessary API calls.