Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

OKX P2P Telegram Monitor

Cloudflare Worker Telegram bot that monitors OKX P2P fiat-to-crypto buy prices. The default report is CNY -> USDT with a 1000 CNY spend amount, and admins can add custom monitors from Telegram.

Features

  • Hourly reports via Cloudflare Cron Triggers.
  • Telegram webhook endpoint at /telegram/webhook.
  • OKX P2P web data source matching the public market page behavior.
  • Admin-only monitor mutations.
  • KV-backed monitor registry.
  • One-shot quotes, pair lookup, payment lookup, manual test, and manual cron trigger.

Commands

/help
/quote CNY USDT amount=3000 pay=aliPay,wxPay
/add CNY USDT amount=3000 pay=aliPay chat=admin,-100123 label=cny-usdt
/list
/remove <id>
/test <id>
/pairs CNY
/payments CNY USDT

chat=admin expands to ADMIN_CHAT_IDS. chat=here sends reports to the chat where the command was issued.

Setup

  1. Install dependencies:
npm install
  1. Create a KV namespace:
npx wrangler kv namespace create MONITORS
npx wrangler kv namespace create MONITORS --preview
  1. Put the returned namespace IDs into wrangler.toml.

  2. Set Worker secrets:

npx wrangler secret put TELEGRAM_BOT_TOKEN
npx wrangler secret put TELEGRAM_WEBHOOK_SECRET
npx wrangler secret put ADMIN_USER_IDS
npx wrangler secret put ADMIN_CHAT_IDS
npx wrangler secret put DEFAULT_TARGET_CHAT_IDS
npx wrangler secret put CRON_DEBUG_SECRET

For local development, copy .dev.vars.example to .dev.vars and fill in real values.

  1. Deploy:
npm run deploy
  1. Register the Telegram webhook:
curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/setWebhook" \
  -d "url=https://<your-worker>.<your-subdomain>.workers.dev/telegram/webhook" \
  -d "secret_token=$TELEGRAM_WEBHOOK_SECRET"

Local Development

npm run dev

Manual report trigger:

curl -X POST "http://127.0.0.1:8787/debug/run?secret=<CRON_DEBUG_SECRET>"

Health check:

curl "http://127.0.0.1:8787/health"

Verification

npm test
npm run typecheck

Notes

  • This uses OKX's current public web P2P endpoints, not a formally stable OKX public API.
  • For user-facing buy behavior, the OKX request uses side=sell because it fetches ads from merchants selling crypto to you.
  • If OKX returns unsupported market code 17007 or no eligible ads, the bot reports that condition instead of failing the whole hourly run.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages