crypto-monitor


Namecrypto-monitor JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/SerenaTradingResearch/crypto-monitor
SummaryLightweight real-time cryptocurrency market monitor via WebSocket
upload_time2025-08-07 04:34:01
maintainerNone
docs_urlNone
authorRicky Ding
requires_python>=3.8
licenseMIT
keywords crypto binance websocket realtime market-data monitor
VCS
bugtrack_url
requirements crypto-data-downloader Pillow
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
## Intro

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

![](https://raw.githubusercontent.com/SerenaTradingResearch/crypto-monitor/main/test/data/CryptoMonitor.gif)

## Usage

```bash
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
    ```py
    x.data: Dict[str, np.ndarray]
    x.update_time: Dict[str, int]
    print(x.data["BTCUSDT"], x.update_time["BTCUSDT"])
    ```

```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_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.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

```bash
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
...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SerenaTradingResearch/crypto-monitor",
    "name": "crypto-monitor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "crypto, binance, websocket, realtime, market-data, monitor",
    "author": "Ricky Ding",
    "author_email": "e0134117@u.nus.edu",
    "download_url": "https://files.pythonhosted.org/packages/05/bf/42b731f22ee0a9b28795f92c5e48054a2302b11d1003f4968dbf82bc646d/crypto_monitor-0.1.2.tar.gz",
    "platform": null,
    "description": "\n## Intro\n\n- Monitors the entire crypto market kline (candlestick) data, showing 20 symbols only below for illustration\n- [Other tools](https://github.com/orgs/SerenaTradingResearch/repositories)\n\n![](https://raw.githubusercontent.com/SerenaTradingResearch/crypto-monitor/main/test/data/CryptoMonitor.gif)\n\n## Usage\n\n```bash\npip install crypto-monitor\n```\n\n- You can either react to individual symbol updates by defining a callback `on_change` as shown below\n- Or define a task like `plot_task` below that handles all symbols (`x.data`) repeatedly\n    ```py\n    x.data: Dict[str, np.ndarray]\n    x.update_time: Dict[str, int]\n    print(x.data[\"BTCUSDT\"], x.update_time[\"BTCUSDT\"])\n    ```\n\n```py\nimport asyncio\nfrom typing import List\n\nimport numpy as np\nfrom crypto_data_downloader.utils import format_date, plot_crypto_data, timestamp\nfrom PIL import Image\n\nfrom crypto_monitor.binance import CryptoMonitor\nfrom crypto_monitor.utils import safe_exit, save_gif\n\n\nasync def main():\n    async def on_change(sym: str, arr: np.ndarray, e_time: int):\n        if sym == \"BTCUSDT\":\n            f = format_date\n            print(\n                f\"BTC. my time: {f(timestamp())}, event time: {f(e_time)}, price: {arr[-1, 1]}\"\n            )\n\n    x = CryptoMonitor()\n    x.kline_lim = 10  # Only show 10 time steps for clearer visualization\n    x.market = [\"SPOT\", \"MARGIN\"][1]\n    x.max_num = 20  # Only show 20 symbols for visualization\n    x.on_change = on_change\n\n    async def plot_task():\n        frames: List[Image.Image] = []\n        while True:\n            await asyncio.sleep(2)\n            safe_exit.check()\n            if len(x.data):\n                id = \"data/CryptoMonitor\"\n                plot_crypto_data(x.data, id)\n                frames.append(Image.open(f\"{id}.png\").copy())\n                assert len(frames) < 150, save_gif(frames, id, fps=5)\n\n    await asyncio.gather(x.watch(), plot_task())\n\n\nasyncio.run(main())\n\n```\n\n- Output\n\n```bash\nweight lim: 5000/6000, USDT symbols: 599, spot: 559, margin: 403\nBTC. my time: 2025-08-07 04:10:22, event time: 2025-08-07 04:10:22, price: 114639.92\nBTC. my time: 2025-08-07 04:10:24, event time: 2025-08-07 04:10:24, price: 114639.91\nBTC. my time: 2025-08-07 04:10:26, event time: 2025-08-07 04:10:26, price: 114639.92\n...\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Lightweight real-time cryptocurrency market monitor via WebSocket",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/SerenaTradingResearch/crypto-monitor"
    },
    "split_keywords": [
        "crypto",
        " binance",
        " websocket",
        " realtime",
        " market-data",
        " monitor"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "346a4819ea2cd12b17a6766556c02fc924afe5d3993a735849abb684aeec30fa",
                "md5": "e95e45b1b48303460fdd5f23d5f10bac",
                "sha256": "9d528c564cbc38a9c6241299cc16bf1ebc4fd1f796a61e62d7fe8113c2311c03"
            },
            "downloads": -1,
            "filename": "crypto_monitor-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e95e45b1b48303460fdd5f23d5f10bac",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4488,
            "upload_time": "2025-08-07T04:33:59",
            "upload_time_iso_8601": "2025-08-07T04:33:59.804297Z",
            "url": "https://files.pythonhosted.org/packages/34/6a/4819ea2cd12b17a6766556c02fc924afe5d3993a735849abb684aeec30fa/crypto_monitor-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "05bf42b731f22ee0a9b28795f92c5e48054a2302b11d1003f4968dbf82bc646d",
                "md5": "7bea01c5550d23d8fad77c5a6c454405",
                "sha256": "e17d3b3198602c840819d5419067bd1189517f93ffe777a3a05ab0c1c643e8a4"
            },
            "downloads": -1,
            "filename": "crypto_monitor-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7bea01c5550d23d8fad77c5a6c454405",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4069,
            "upload_time": "2025-08-07T04:34:01",
            "upload_time_iso_8601": "2025-08-07T04:34:01.165133Z",
            "url": "https://files.pythonhosted.org/packages/05/bf/42b731f22ee0a9b28795f92c5e48054a2302b11d1003f4968dbf82bc646d/crypto_monitor-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-07 04:34:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SerenaTradingResearch",
    "github_project": "crypto-monitor",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "crypto-data-downloader",
            "specs": []
        },
        {
            "name": "Pillow",
            "specs": []
        }
    ],
    "lcname": "crypto-monitor"
}
        
Elapsed time: 2.21612s