Skip to main content

Lightweight real-time cryptocurrency market monitor via WebSocket

Project description

Intro

  • Monitors the entire crypto market kline (candlestick) data, showing 20 symbols only below for illustration
  • Other tools

Usage

pip install crypto-monitor
  • 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
    x.data: Dict[str, np.ndarray]
    x.update_time: Dict[str, int]
    print(x.data["BTCUSDT"], x.update_time["BTCUSDT"])
    
import asyncio
from typing import List

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

from crypto_monitor.binance import CryptoMonitor
from crypto_monitor.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 = CryptoMonitor()
    x.quote = "USDT"  # Quote asset
    x.interval = "5m"  # Kline time interval
    x.columns = ["open_time", "close"]  # Data columns to include
    print(f"All data columns: {ALL_COLUMNS}")
    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/CryptoMonitor"
                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
All data columns: ['open_time', 'open', 'high', 'low', 'close', 'volume', 'close_time', 'quote_volume', 'n_trades', 'taker_buy_base_volume', 'taker_buy_quote_volume', 'unused']
weight lim: 5000/6000, USDT symbols: 599, spot: 559, margin: 403
BTC. my time: 2025-08-07 04:10:22, event time: 2025-08-07 04:10:22, price: 114639.92
BTC. my time: 2025-08-07 04:10:24, event time: 2025-08-07 04:10:24, price: 114639.91
BTC. my time: 2025-08-07 04:10:26, event time: 2025-08-07 04:10:26, price: 114639.92
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crypto_monitor-0.2.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crypto_monitor-0.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file crypto_monitor-0.2.0.tar.gz.

File metadata

  • Download URL: crypto_monitor-0.2.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for crypto_monitor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 954eba612574a925f84bfc8ae683e5e298a25e9b3e779a853724a0f52d4d39c2
MD5 f00b89b83a64628ab97be6672344008e
BLAKE2b-256 8e47f2b8109d9c0dd7ac9d86e956d2d48504149210c60beca0e86e1698983354

See more details on using hashes here.

File details

Details for the file crypto_monitor-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: crypto_monitor-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for crypto_monitor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6653f91c40ef2aa829f1aa51385aec73079fe4d8084b38cb1ef7680ea82a9efa
MD5 23a31b95fbccc8aa607d153811bd2058
BLAKE2b-256 2aa72c0f49c2d25b1cfca6f3666522c4c7e40885dd1f95e17157a36dc42994e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page