semvec/pypi-packages huggingface dataset:
crypto-watcher-2 0.1.0
Lightweight real-time cryptocurrency market monitor via WebSocket
License: MIT
Requires Python: >=3.8
Keywords: crypto, binance, websocket, realtime, market-data, monitor


## Intro

- Watches the entire crypto market kline (candlestick) data, showing 20 symbols only below for illustration
- [Other tools](https://github.com/orgs/SerenaTradingResearch/repositories)

![](./test/data/CryptoWatcher.gif)

## Usage

```bash
pip install crypto-watcher
```

- You can either react to individual symbol updates by defining a callback `on_change` as shown below
- Or define a task like `plot_task` below that handles all symbols (`x.data`) repeatedly

```py
import asyncio
from typing import List

import numpy as np
from crypto_data_downloader.utils import format_date, plot_crypto_data, timestamp
from PIL import Image

from crypto_watcher.binance import CryptoWatcher
from crypto_watcher.utils import safe_exit, save_gif


async def main():
    async def on_change(sym: str, arr: np.ndarray, e_time: int):
        if sym == "BTCUSDT":
            f = format_date
            print(
                f"BTC. my time: {f(timestamp())}, event time: {f(e_time)}, price: {arr[-1, 1]}"
            )

    x = CryptoWatcher()
    x.kline_lim = 10  # Only show 10 time steps for clearer visualization
    x.market = ["SPOT", "MARGIN"][1]
    x.max_num = 20  # Only show 20 symbols for visualization
    x.on_change = on_change

    async def plot_task():
        frames: List[Image.Image] = []
        while True:
            await asyncio.sleep(2)
            safe_exit.check()
            if len(x.data):
                id = "data/CryptoWatcher"
                plot_crypto_data(x.data, id)
                frames.append(Image.open(f"{id}.png").copy())
                assert len(frames) < 150, save_gif(frames, id, fps=5)

    await asyncio.gather(x.watch(), plot_task())


asyncio.run(main())
```

- Output

```bash
weight lim: 5000/6000, USDT symbols: 599, spot: 559, margin: 403
BTC. my time: 2025-08-07 03:14:02, event time: 2025-08-07 03:14:02, price: 114453.57
BTC. my time: 2025-08-07 03:14:04, event time: 2025-08-07 03:14:04, price: 114453.56
BTC. my time: 2025-08-07 03:14:06, event time: 2025-08-07 03:14:06, price: 114452.0
...
```