DEV Community

Ama
Ama

Posted on

πŸ” Monitoring Bybit P2P USDT/RUB prices with Playwright network interception + Telegram alerts (Python)

If you have ever tried to β€œscrape” a modern website, you know the pain: the UI looks simple, but the data is loaded dynamically, and the DOM changes every two minutes πŸ˜…

⚑ What this tool does

You set a threshold like 71.50 RUB.
The script checks the current best USDT/RUB buy offer and notifies you in Telegram if the price is below that level.

Core flow:

🧭 open the Bybit P2P page
πŸ•΅οΈ listen to network responses
🧾 parse JSON from the P2P API response
πŸ“‰ compare the best price with your threshold
πŸ“© send Telegram message

No fragile selectors. No DOM gymnastics. Just data.

🧰 Setup

Install dependencies:

pip install -r requirements.txt
playwright install

Create .env:

BOT_TOKEN=your_telegram_bot_token
CHAT_ID=your_chat_id

Run:

python main.py

Then enter your threshold when the script asks for it.

🧠 The key idea: intercept the JSON response

Bybit P2P UI is basically a shell. The real data is coming from an internal endpoint.

So the strategy is:

open the page
subscribe to Playwright response events
filter responses by URL (the internal API endpoint)
call response.json()
extract offers and prices

This is usually more stable than DOM scraping because you rely on the same payload the app uses internally.

πŸ“¦ Why network interception beats DOM scraping

DOM scraping often breaks because:
class names change
elements are lazy loaded
content is rendered differently by region or language
the site adds random wrappers

Network interception is cleaner:

βœ… data structure is consistent
βœ… you get structured JSON
βœ… fewer moving parts
βœ… easier debugging

If the endpoint changes, you update one filter. Not 20 selectors.

πŸ“© Telegram alerts in 10 seconds

Telegram sending is just a POST request to:

https://api.telegram.org/bot/sendMessage

Payload:

chat_id
text

Add a timeout so your monitor loop never hangs.

Result: when the best price crosses your threshold, you get a nice message instantly πŸš€

If you want to evolve this tool, here are easy upgrades:

🧽 deduplicate notifications so you do not spam yourself
🧷 move threshold into .env or CLI args
πŸ§ͺ add a --once mode to run a single check
πŸ“Š store history to a simple CSV for analysis

βœ… Wrap up

If you are scraping a dynamic website and the data comes from JSON calls, intercepting the network layer is often the most robust solution.

This project is a tiny example of that approach:

Playwright for browser and network events
JSON parsing for structured data
Telegram for instant notifications

Repo again: https://github.com/AmaLS367/bybit-p2p-price-monitor

If you have ideas for improvements or want to contribute, PRs are welcome πŸ’ͺπŸ”₯

Top comments (0)