Skip to main content

Bybit-Predict

License: GPL-2.0-or-later CI

Rule-based cryptocurrency market analysis and signals from public Bybit V5 market data, with optional Discord integration.

Current release: v4.1.7. This documentation release corrects several documentation errors and fixes README links on the PyPI page. The code is the same as v4.1.6, which fixed linear-contract short returns, included starting equity in maximum drawdown, and made live CLI/Discord analysis use only completed candles. The last legacy release was v3.1.

正體中文

If you made backtests with a version before v4.1.6, rerun them with the same saved CSV/manifest, analysis window, fees, and slippage, and keep the original reports to compare. See the v4.1.6 upgrade notes in CHANGELOG.md.

How it works

Bybit-Predict reads OHLCV candles from Bybit's public API and uses fixed rules to produce market signals and reference levels. The current legacy-rule-based-v4 strategy looks at candle shapes, volume, percentiles, and IQR, and uses Fibonacci ratios for the reference levels. It only reads public market data and never places orders.

Crypto prices move fast. Treat these signals as reference only, not investment advice.

Highlights

  • Live analysis uses completed candles: the default 180-candle window normally needs one K-line page, while 1,000 completed candles may need one additional older page.
  • Typed, UTC-normalized Candle and immutable PredictionResult models.
  • Each legacy-strategy analysis runs independently, so you can run several at once.
  • CLI for local use and an optional non-blocking Discord slash command.
  • Symbols are checked against Bybit's instrument metadata.
  • Tests, Ruff, Pyright, GitHub Actions CI, and Dependabot.
  • Reproducible historical backtesting with saved CSV inputs, validated dataset manifests, stated assumptions, performance metrics, and two simple baselines.

Requirements

  • Python 3.11 or later
  • Internet access to Bybit public market endpoints
  • A Discord bot token, only for the Discord interface

You do not need a Bybit account or API key.

Install

From PyPI

Install the CLI and its standard Bybit V5 dependency with:

python -m pip install bybit-predict

Install the optional Discord interface when you need it:

python -m pip install "bybit-predict[discord]"

For an isolated command-line installation, use pipx:

pipx install bybit-predict

From source

git clone https://github.com/KageRyo/Bybit-Predict.git
cd Bybit-Predict
uv venv --python 3.11 .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
uv pip install .

For contributors, install development and optional Discord dependencies:

uv pip install -e ".[dev]"

CLI

Analyze the default 180 four-hour candles:

bybit-predict analyze BTCUSDT

Choose another supported Bybit interval and candle count:

bybit-predict analyze ETHUSDT --interval 60 --limit 240

CLI --limit and Discord candles count completed candles, from 42 to 1,000 (default 180). The candle that is still open is left out until its UTC close time. For minute, daily, and weekly intervals, the close time is the candle start plus the interval; monthly candles close at the start of the next UTC calendar month. All requests and retries in one analysis use the same UTC time. If two K-line pages still do not give enough completed candles, analysis fails and shows how many were requested and how many were available. The reported data period still shows the start times of the first and last analyzed candles.

Example output:

Symbol: BTCUSDT
Strategy: legacy-rule-based-v4 (rule-based, not ML)
Timeframe: 240
Candles: 180
Trend: Bullish
Signal strength: 68.00%

Reference levels:
     0%  ...
  23.6%  ...

The CLI returns a non-zero status for invalid symbols, invalid parameters, or market-data failures. You can also run python -m bybit_predict analyze BTCUSDT.

Backtest a historical range

backtest replays a strategy over a past date range. The strategy sees only a fixed window of earlier closed candles. Bullish or bearish signals enter at the next candle open and exit at that candle's close. The output lists the assumptions, metrics, and two baselines.

bybit-predict backtest BTCUSDT \
  --interval 240 \
  --start 2024-01-01 \
  --end 2025-01-01 \
  --strategy legacy \
  --window 180 \
  --save-data data/btcusdt-2024-4h.csv

Re-run against the saved, normalized CSV without downloading data again:

bybit-predict backtest BTCUSDT \
  --interval 240 \
  --start 2024-01-01 \
  --end 2025-01-01 \
  --strategy legacy \
  --window 180 \
  --data data/btcusdt-2024-4h.csv

--start is inclusive, --end is exclusive, and times are in UTC. Saving with --save-data also writes <csv-name>.manifest.json; keep it next to the CSV, because --data checks it before replaying. Dataset paths must be inside the current working directory.

See backtesting and evaluation for the return model, metric definitions, manifest format, path rules, and limitations.

Discord slash commands

Install the Discord optional dependency, create a Discord application/bot, and invite it with the bot and applications.commands scopes.

python -m pip install ".[discord]"
cp .env.example .env

Set the environment variables. Locally you can source .env; in deployment, use your platform's secret manager:

export DISCORD_BOT_TOKEN="your-token"
# Optional: immediately sync commands to one development guild.
export DISCORD_GUILD_ID="your-development-guild-id"

Then start the interface:

bybit-predict discord

Use the slash command in Discord:

/predict symbol:BTCUSDT interval:240 candles:180

The command runs Bybit requests in a separate thread, so a slow request does not block Discord's event loop. Responses include the strategy, trend, signal strength, candle period, and reference levels.

.env and data/ are in .gitignore, so tokens kept in .env and market data saved under data/ stay out of commits.

Configuration

Variable Required Purpose
DISCORD_BOT_TOKEN Discord only Discord bot authentication token.
DISCORD_GUILD_ID No Development guild for immediate command syncing.
BYBIT_TESTNET No true opts into Bybit testnet public data; default is false.

Architecture

Bybit V5 public API
        │
BybitV5MarketClient ──→ normalized UTC Candles
        │
        ├── PredictionService ──→ LegacyRuleBasedStrategy ──→ PredictionResult
        │         │                         │
        │         ├──────── CLI             └── future strategies
        │         └──────── Discord slash command
        │
        └── BacktestEngine ─────→ LegacyRuleBasedStrategy ──→ BacktestResult
                  │
                  ├──────── historical CLI
                  └──────── saved CSV input/output
  • market/ owns Bybit V5 requests, retry boundaries, pagination, and response normalization.
  • strategies/ contains pure, deterministic signal calculations and has no dependency on Bybit or Discord.
  • services/ composes market data with a strategy.
  • interfaces/ converts user input/output only.

Strategy and evaluation

LegacyRuleBasedStrategy keeps the project's original core logic. It classifies candle bodies and wicks, compares significant bullish and bearish volume, and derives optional reference prices from IQR and percentile calculations. It has its own name so later strategies can be compared with it fairly. v4 fixes three v3 problems: the zero/six-candle volume window, timezone handling, and bearish Fibonacci label order. The compatibility baseline and the behavior kept from v3 are documented in legacy strategy migration notes.

The v4.1.0 backtesting work (#25) defines a fixed trailing analysis window, next-open entry, same-candle-close exit, and neutral-as-cash behavior before calculating close-to-close directional accuracy, win rate, average return, maximum drawdown, and a Sharpe ratio with a zero risk-free rate. It compares the result with buy-and-hold and a 10/20 SMA directional baseline. See backtesting and evaluation for the exact rules and limitations.

Development and quality checks

ruff check .
ruff format --check .
pyright
pytest

pytest fails when total coverage falls below 80%. Pyright runs in basic mode but treats missing imports as errors; the development extra installs the dependencies these checks need.

Pull requests run these checks on Python 3.11, 3.12, and 3.13. See CONTRIBUTING.md for local setup and the required feature/<issue>-<description> branch convention.

Publishing

Pushing a final release tag builds an sdist and universal wheel, validates them, publishes through PyPI Trusted Publishing, then creates a GitHub Release with the same artifacts. See PyPI publishing for the maintainer-only setup and release procedure.

Release history and roadmap

  • v4.0.0: package architecture, public Bybit V5 client, stateless legacy strategy, CLI, Discord slash command, configuration, quality gates, and documentation.
  • v4.1.0: reproducible backtesting and evaluation (#25).
  • v4.1.1: PyPI distribution, Trusted Publishing, and package-release automation (#37).
  • v4.1.2: documentation and PyPI metadata corrections (#40).
  • v4.1.3: CI dependency maintenance and restoration of the complete GPL v2 license text.
  • v4.1.4: standard GPL v2 distribution license, recognized by GitHub as GPL-2.0.
  • v4.1.5: candle and API robustness, interval and dataset replay validation, linear-time SMA baseline computation, explicit metric semantics, enforced quality gates, and main-branch protection.
  • v4.1.6: corrected linear short returns and initial-equity drawdown, plus completed-candle live analysis with bounded pagination (#64–#66).
  • v4.1.7: documentation corrections, plainer wording, and README links that work on PyPI (#73).
  • Later: more strategies can implement the same strategy contract; ML is one possible future direction.

Contributing and history

Thanks to prior contributors, including RRAaru. New contributors are welcome—start with good first issues or read CONTRIBUTING.md.

Bybit-Predict is licensed under the GNU General Public License v2.0 or later.

Copyright © 2022–2026 CodeRyo Studio, Chien-Hsun Chang, and contributors. CodeRyo Studio is the project maintainer. See NOTICE for the complete attribution notice.

Metadata

Release files for bybit-predict 4.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bybit-predict 4.1.7
File Size Uploaded Provenance Actions
bybit_predict-4.1.7.tar.gz 68.7 kB With provenance Details for bybit_predict-4.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bybit-predict 4.1.7
File Interpreter ABI Platform Actions
bybit_predict-4.1.7-py3-none-any.whl Python 3 none any Details for bybit_predict-4.1.7-py3-none-any.whl

Total release size: 119.1 kB

Release files / bybit_predict-4.1.7.tar.gz

Download URL bybit_predict-4.1.7.tar.gz
Size 68.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6ec17e226a7c21bc7000327a743de13c649df50012cc91ba3e57906549021cf5
BLAKE2b-256 checksum
How to use checksums
10e19eff1cd3b7469a0ce227b4b00fe2461c81c93e4c5485a3c034512ffaa416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / bybit_predict-4.1.7-py3-none-any.whl

Download URL bybit_predict-4.1.7-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed11f97513b43750d2ca545062ff5094dd5285819aa7e7ce8e757a8bb3541dcf
BLAKE2b-256 checksum
How to use checksums
213a1d9ad4adb11395e93c6110a0068b200966ef1a3a5b3cd2771cc8b5e14f53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for bybit-predict 4.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bybit_predict-4.1.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page