Tradingbot
Python · FREE RESOURCE

Bybit Price Alert

A complete Python educational example with error handling and no order execution.

ICODERX Editorialv1.0.0Updated 11/20/20260 saves

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)
3 files · Read-only · MIT · Source is not executed here

Features and architecture

Public REST request → timeout → JSON parsing → validation → console output. No exchange API keys or order execution modules.

Installation

  1. Download ZIP and review every file before running locally.
  2. Install Python 3.11+. Standard library only; no third-party dependencies.
  3. 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.

Educational content, not investment advice. Trading can result in capital loss. No profit is guaranteed.

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.

Join the discussion