Skip to main content

PyneCore Bybit Plugin

Bybit v5 integration for PyneCore: historical and live market data plus live order execution over the Bybit v5 Open API, covering the spot, linear (USDT/USDC perpetuals and futures) and inverse (coin-margined) categories.

Status

Both the data provider (LiveProviderPlugin) and live order execution (BrokerPlugin) are implemented and verified against the Bybit demo environment: historical plus live OHLCV for all three categories, and order execution with entries, exit brackets, cancels, in-place amends, crash recovery and fill reconciliation over the private WebSocket event stream.

Demo first

Bybit's demo environment (api-demo.*) runs on real mainnet prices with simulated balances — exactly the paper-trade path you should run before risking funds. The plugin defaults to demo = true; set it to false only once your strategy has proven itself on demo.

Demo API keys are generated from your mainnet account after switching the dashboard to Demo Trading. Demo covers spot, linear and inverse alike, and the private order/execution stream works the same as live. (Demo hosts serve no public market-data stream; public data always comes from the mainnet stream, which is fine — demo trades on mainnet prices.)

Configuration

Settings live in workdir/config/plugins/bybit.toml, auto-generated from BybitConfig on first run. Fill in your API key pair and pick the environment:

demo = true            # demo (api-demo.*) vs. live real funds
region = "global"      # global | eu | nl | tr | kz | ge | ae | id | testnet
api_key = ""
api_secret = ""
  • demo selects the paper-trade environment (see above).
  • region is your account's legal entity / host family, decided by your residency — it is not auto-detected. The (region, demo) pair resolves to a REST + WebSocket host triple (see hosts.py).
  • Optional rest_host / ws_public_host / ws_private_host overrides are an escape hatch for unlisted regional domains.

API key expiry and rotation

Bybit API keys without an IP whitelist expire after a limited period (currently three months) — a long-running bot will silently lose authentication when the key lapses. For unattended operation either bind the key to your server's IP address (whitelisted keys do not expire) or put a key-rotation reminder in your operations calendar.

The EU entity

Bybit EU (region = "eu", the MiCA-regulated entity for EEA residents) does not allow generating API keys directly: API access is only available through Bybit's third-party-application program, and that path is currently not usable in practice. Until this changes, EU-entity accounts cannot be used with this plugin — the host table and the eu region are wired and waiting, but there is no way to obtain a key. Development and verification run on the global entity's demo environment.

Symbols

The provider accepts TradingView-style notation:

  • BTCUSDT — plain name: spot first, then other categories are probed
  • BTCUSDT.P, BTCUSD.P — .P suffix: perpetual, linear probed first
  • BTCUSDT-26JUN26 — dated futures under their native Bybit name

Architecture

  • Transport: raw httpx (REST) + websockets (WS), no vendor SDK — the v5 API is plain JSON REST and JSON WebSocket, and the official pybit SDK is thread-based, which would fight the asyncio broker event loop.
  • Authentication: API key + secret, HMAC-SHA256 request signing; the private WebSocket authenticates with the same key pair.
  • One plugin, category-based model selection. The traded symbol's category (spot / linear / inverse) is resolved at connect time and selects both the execution model and the capability profile.
  • Push order events: order state and fills arrive over the private WebSocket order / execution / position topics — no polling. Crash recovery reconciles missed fills from REST history on restart.
  • Execution recovery without an operator: when the stream never delivered what an order executed, PyneCore asks the plugin (fetch_order_execution), which reads the order from /v5/order/realtime / /v5/order/history and its executions from /v5/execution/list, on every category. The executions keep their execId, so nothing is booked twice. An order neither order endpoint shows (and with no execution listed) counts as never executed. Bybit keeps an order with any execution in its history, and a fully cancelled one only for 24 hours. When an entry that executed while the bot was down had its position closed before the restart (a trading stop, a liquidation, a manual close), those closes reach PyneCore right after the entry, as the entry's close fills with their own execId and price (linear and inverse, one-way and hedge). A close whose process ended before PyneCore took it is delivered again after the restart, flagged journaled_before_restart, until PyneCore's fill receipt exists.

Category notes

Spot

  • Inventory model, not position model. Spot has no exchange-side position object; PyneCore's spot-inventory core folds the plugin's execution ledger into a synthetic position. Short selling is unsupported (the core rejects shorting scripts on spot).
  • Fee dust: Bybit charges the spot buy fee in the base coin, so round trips leave sub-precision dust behind. Balances below one quantity-grid step are treated as flat.
  • Close over an entry whose fill never arrived (held_execution_close): supported once the inventory ledger runs (persistence on). Spot has no reduce-only order, so the close sells at most the base the bot's own inventory ledger holds, never other coins in the wallet, and it never borrows (isLeverage=0). The ledger takes in the held order's execution as soon as the plugin reads it back from the venue (see below).

Linear (USDT/USDC perpetuals and futures)

  • Real venue position model with native short selling and reduceOnly.
  • One-way position mode is the native path; hedge-mode accounts run through PyneCore's one-way emulation layer, so Pine one-way semantics hold on both.
  • Close over an entry whose fill never arrived (held_execution_close): supported. When an entry's fill evidence never arrives and the strategy asks to close or reverse, PyneCore closes the real venue position. On a one-way account the plugin sizes that close from a fresh read of the venue position and sends it as a reduceOnly market order, so it cannot flip the position; on a hedge account the held order's unbooked execution is part of the bot's leg, so the one-way emulation closes it too. New entries stay blocked until PyneCore recovers the entry's execution from the venue.

Inverse (coin-margined)

  • Contracts are whole-USD denominated and settle in the base coin; the plugin maps Pine's base-quantity model onto USD contracts at dispatch, so strategies behave exactly as on linear (this matches TradingView, which also applies linear qty * Δprice accounting to inverse symbols).
  • One-way position mode only (a hedge-mode inverse account is refused at startup). The close over an entry whose fill never arrived is supported as on linear one-way: it closes the venue's own contract count.
  • Collateral switch gotcha: on a Unified Trading Account the settle coin's collateral switch must be ON, otherwise every inverse order is rejected with retCode 110101. Enable it under margin/collateral settings for the coin you trade (e.g. BTC for BTCUSD).

License

Apache-2.0. See LICENSE and NOTICE.

Metadata

Release files for pynesys-pynecore-bybit 0.9.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 pynesys-pynecore-bybit 0.9.7
File Size Uploaded Provenance Actions
pynesys_pynecore_bybit-0.9.7.tar.gz 409.4 kB With provenance Details for pynesys_pynecore_bybit-0.9.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynesys-pynecore-bybit 0.9.7
File Interpreter ABI Platform Actions
pynesys_pynecore_bybit-0.9.7-py3-none-any.whl Python 3 none any Details for pynesys_pynecore_bybit-0.9.7-py3-none-any.whl

Total release size: 665.6 kB

Release files / pynesys_pynecore_bybit-0.9.7.tar.gz

Download URL pynesys_pynecore_bybit-0.9.7.tar.gz
Size 409.4 kB
Tags Source
SHA-256 checksum
How to use checksums
55d7af9efa18e03c0eb383f39a192956ee4d276e15287b4433f42867a42e9dac
BLAKE2b-256 checksum
How to use checksums
ede29c3b442bedda31919cb26eb3fb0e1110aaa43a51b084280a94b4d3fd5a0e
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 27, 2026.

Transparency log

Release files / pynesys_pynecore_bybit-0.9.7-py3-none-any.whl

Download URL pynesys_pynecore_bybit-0.9.7-py3-none-any.whl
Size 256.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e1bf10d024577bdb5ef2e886049df3103dd8870de0fbfa5df44ccecc7a7d073
BLAKE2b-256 checksum
How to use checksums
e9c12ae5dd42a04cd56fa2405be195825bf01c9934a5d577f4bfc002bc337598
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 27, 2026.

Transparency log

Security for pynesys-pynecore-bybit 0.9.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 pynesys_pynecore_bybit-0.9.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 27, 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