⚠️ Registration Threshold: Pionex doesn’t support KYC for mainland China ID cards. You’ll need a valid ID from Taiwan / Singapore / Malaysia / United States, etc. See Pionex Restricted Regions Official Notice.

After running the Pionex grid bot for 4 months, the biggest pain point was no alert when price hits the range boundaries. When price breaks above or below your configured range, the bot stops automatically—but you won’t know when you need to step in (to reconfigure or pause).
Solution: write a small script to monitor price and alert you before hitting boundaries. I used Claude Code to go from zero to running in 25 minutes, and I’m sharing the process and final code.
Why Claude Code for This
Instead of rolling your own:
- I’m not familiar with the Pionex API (Claude finds docs faster)
- Telegram Bot API details escape me (Claude outputs correct code directly)
- I tend to over-engineer; Claude gives you “minimum viable” instead
- During debugging Claude sees the error and fixes it right away
The whole process is just talking to Claude in plain English and getting back code + explanation.
Defining Requirements (What I Told Claude)
Write a Python script that:
1. Checks BTC/USDT and XAU/USDT price every 5 minutes
2. If price gets within 10% of the upper or lower bound, send a Telegram alert
3. Alert includes: current price, range, distance to boundary in percentage
4. Config via environment variables: TG_TOKEN, TG_CHAT_ID, BOT_CONFIGS
5. BOT_CONFIGS is JSON in this format:
[
{"symbol": "BTC/USDT", "low": 60000, "high": 70000, "name": "BTC Grid"},
{"symbol": "XAU/USDT", "low": 3400, "high": 3600, "name": "Gold Grid"}
]
6. Use Binance public API for price (Pionex uses the same price source)
7. Deploy to Mac with launchd to run every 5 minutes
Code Claude Generated (Nearly First-Draft Ready)
File 1: pionex_monitor.py
import os, json, urllib.request, time
from datetime import datetime
TG_TOKEN = os.environ["TG_TOKEN"]
TG_CHAT_ID = os.environ["TG_CHAT_ID"]
BOT_CONFIGS = json.loads(os.environ.get("BOT_CONFIGS", "[]"))
# Threshold: trigger alert when 10% away from boundary
ALERT_THRESHOLD = 0.10
def get_price(symbol):
"""symbol format 'BTC/USDT' → Binance API 'BTCUSDT'"""
s = symbol.replace("/", "")
url = f"https://api.binance.com/api/v3/ticker/price?symbol={s}"
with urllib.request.urlopen(url, timeout=10) as r:
return float(json.loads(r.read())["price"])
def send_tg(text):
"""Send Telegram alert"""
url = f"https://api.telegram.org/bot{TG_TOKEN}/sendMessage"
data = json.dumps({"chat_id": TG_CHAT_ID, "text": text}).encode()
req = urllib.request.Request(url, data=data,
headers={"Content-Type": "application/json"})
try: urllib.request.urlopen(req, timeout=5)
except Exception as e: print(f"TG send failed: {e}")
def check_bot(bot):
symbol = bot["symbol"]
low, high = bot["low"], bot["high"]
name = bot["name"]
try: price = get_price(symbol)
except Exception as e:
print(f"{symbol}: get price fail: {e}")
return
# Distance to upper bound in percentage
dist_to_high = (high - price) / price
dist_to_low = (price - low) / price
# Check if approaching boundary
if dist_to_high < ALERT_THRESHOLD and dist_to_high > 0:
pct = dist_to_high * 100
send_tg(f"🟡 {name} approaching upper bound\nCurrent: ${price:,.2f}\nUpper: ${high:,.2f}\nDistance: {pct:.2f}%")
elif dist_to_low < ALERT_THRESHOLD and dist_to_low > 0:
pct = dist_to_low * 100
send_tg(f"🟡 {name} approaching lower bound\nCurrent: ${price:,.2f}\nLower: ${low:,.2f}\nDistance: {pct:.2f}%")
elif price >= high:
send_tg(f"🔴 {name} has broken above upper bound!\nCurrent: ${price:,.2f}\nUpper: ${high:,.2f}\nBot may have stopped, check it")
elif price <= low:
send_tg(f"🔴 {name} has dropped below lower bound!\nCurrent: ${price:,.2f}\nLower: ${low:,.2f}\nConsider manual close or expand range")
if __name__ == "__main__":
for bot in BOT_CONFIGS:
check_bot(bot)
Just 40 lines.
How to Deploy (Local Mac)
1. Save as ~/scripts/pionex_monitor.py
2. Create a Telegram Bot: find @BotFather, send /newbot → get Token
3. Get Chat ID: send a message to your bot, then visit
https://api.telegram.org/bot<TOKEN>/getUpdates
Grab chat.id from the JSON.
4. LaunchAgent: ~/Library/LaunchAgents/com.as.pionex-monitor.plist
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>Label</key><string>com.as.pionex-monitor</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>/Users/YOU/scripts/pionex_monitor.py</string>
</array>
<key>StartInterval</key><integer>300</integer>
<key>EnvironmentVariables</key>
<dict>
<key>TG_TOKEN</key><string>YOUR_TOKEN</string>
<key>TG_CHAT_ID</key><string>YOUR_CHAT_ID</string>
<key>BOT_CONFIGS</key><string>[{"symbol":"BTC/USDT","low":60000,"high":70000,"name":"BTC Grid"}]</string>
</dict>
<key>StandardOutPath</key><string>/tmp/pionex_monitor.log</string>
<key>StandardErrorPath</key><string>/tmp/pionex_monitor.log</string>
</dict>
</plist>
5. Load it:
launchctl load ~/Library/LaunchAgents/com.as.pionex-monitor.plist
Runs automatically every 5 minutes.
Enhanced Version (Claude’s Second Round)
After getting v1 running, I asked Claude to add:
Deduplication: same alert won’t repeat within 2 hours
def should_alert(key, window_sec=7200):
"""use marker files in /tmp for deduplication"""
import os
marker = f"/tmp/.pionex_alert_{key}"
if os.path.isfile(marker) and time.time() - os.path.getmtime(marker) < window_sec:
return False
open(marker, "w").close()
return True
Daily summary: unconditionally send a current price report every morning at 8am
Extended monitoring: beyond price, also monitor Pionex account balance changes (requires Pionex API key)
Claude Code’s Workflow for This
Actual back-and-forth from requirement to deployment:
- Me: describe requirements (above)
- Claude: outputs first version code + explanation
- Me: run it → error “KeyError: ‘price’”
- Claude: analyze API response + fix
- Me: run again → TG alerts keep repeating
- Claude: add deduplication logic
- Me: switch to launchd deployment, ask about plist format
- Claude: output complete plist + verification commands
- Me: launchctl load error
- Claude: spot the PATH issue immediately, add PATH to
EnvironmentVariables
Typical timeline: 20–40 minutes from requirement to running. The main work is describing things to Claude, test runs, and reporting errors—you’re not writing code from scratch.
Similar Quant Utilities with This Approach
Scripts you can write with Claude Code:
| Script Purpose | Typical LOC |
|---|---|
| Alert when funding rate > threshold (arbitrage opportunity) | 50 lines |
| Compare Pionex account P&L vs Grafana record | 80 lines |
| Check all positions have stop-loss, alert if not | 35 lines |
| Daily summary of AFF clicks (integrate CF Worker API) | 40 lines |
Usually under 50 lines, Claude Code gets it done in half an hour.
Why Choose Claude Code
Alternatives:
- ChatGPT web: copying-pasting code each time gets tedious
- Cursor: solid, but requires subscription and occasional precision issues
- Copilot: good at completions, not at building from scratch
- Claude Code: lets it edit your local files directly in the terminal, run tests, you give feedback
If you’re doing quant or ops work on Mac, highly recommend it.
→ Claude Code Money-Saving Guide · Claude Dual Channel Switching
The Combined Value
Now my Pionex monitoring + live data + spot-futures arbitrage run as separate strategies; when hitting boundaries, you get a Telegram alert in 2 seconds.
Real-world results:
- Usually 2–3 alerts per week, 1–2 worth acting on (timely adjustment before a breakout or breakdown)
- A single correct “manual close before breaking the upper bound” nets you extra floating profit (a few to tens of dollars depending on position size)
- Compared to no monitoring, net APY typically 3–5% higher (depends on volatility and your response time)
The tool doesn’t make you rich; reducing emotional interference = stronger discipline = long-term compounding.
→ Pionex New User Registration
Summary
- Use Claude Code to write quant monitoring, live in 30 minutes
- 40 lines of code
- The key is clear requirement definition, not coding tricks
- 3–5% long-term APY boost sounds small but compounds dramatically
Further Reading: