Source code
v1.0.0"""ICODERX — MIT. Bounded public-price alert example."""
import json
import os
import time
import urllib.request
from urllib.error import URLError
threshold = float(os.environ.get("ALERT_PRICE", "0"))
if threshold <= 0:
raise SystemExit("Set ALERT_PRICE to a positive threshold")
for attempt in range(12):
try:
url = "https://api.bybit.com/v5/market/tickers?category=spot&symbol=BTCUSDT"
with urllib.request.urlopen(url, timeout=10) as response:
payload = json.load(response)
if payload["retCode"] != 0:
raise ValueError("Exchange rejected request")
price = float(payload["result"]["list"][0]["lastPrice"])
print(json.dumps({"symbol": "BTCUSDT", "price": price}))
if price >= threshold:
print("ALERT: threshold reached. No order submitted.")
break
except (URLError, KeyError, ValueError, IndexError) as error:
print(type(error).__name__)
time.sleep(15)
Features and architecture
Public REST request → timeout → JSON parsing → validation → console output. No exchange API keys or order execution modules.
Installation
- Download ZIP and review every file before running locally.
- Install Python 3.11+. Standard library only; no third-party dependencies.
- Follow README.md and set the required environment variables. Keep secrets out of source.
Configuration and security
Uses public endpoints only. Bounded loops and 10-second timeouts. Set ALERT_PRICE for the Bybit alert example.
Known limitations
No durable state, retry queue or production monitoring. APIs can disconnect or impose regional limits. Do not use this sample as a real-order execution system. This website never executes uploaded source.
Changelog
1.0.0 — first educational release, MIT license.
FAQ
Is the source code free?
Yes. Examples use the MIT license and can be modified and shared with attribution.
Does this guarantee profit?
No. This is educational material. Independently validate assumptions, costs and risks.