Skip to content
All library documents

Streaming Bybit Market Data with a Data Tester

Code NautilusTrader

Summary

This example configures a live data node to connect to Bybit’s mainnet for linear products and stream data for a BTCUSDT instrument. A built-in data-testing actor subscribes to quotes, trades, mark prices, index prices, and funding rates, while managing the order book and logging incoming data. The example is for observing feed delivery and does not submit orders.

It demonstrates how a test actor can exercise several market-data subscriptions through a live exchange connection. It does not describe a trading strategy, analyze signal quality, or provide measured results. Its scope is limited to a data-streaming setup for a single configured instrument and product type; users should not infer broader coverage or trading performance from it.

Key ideas

  • The example connects a live data node to Bybit mainnet for linear products.
  • It streams quote, trade, mark price, index price, and funding-rate data for one instrument.
  • The built-in actor manages the order book and logs the received data.
  • The example places no orders and provides no strategy or performance analysis.

Tags

Full text
# data_tester.py


```py
#!/usr/bin/env python3
# -------------------------------------------------------------------------------------------------
#  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
#  https://nautechsystems.io
#
#  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
#  You may not use this file except in compliance with the License.
#  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
# -------------------------------------------------------------------------------------------------
"""
Stream Bybit market data with the built-in DataTester actor.

Running this example connects to Bybit mainnet and starts subscriptions for the
configured instrument immediately, logging all received data. No orders are placed.

"""

from __future__ import annotations

from nautilus_trader.adapters.bybit import BybitDataClientConfig
from nautilus_trader.adapters.bybit import BybitDataClientFactory
from nautilus_trader.adapters.bybit import BybitEnvironment
from nautilus_trader.adapters.bybit import BybitProductType
from nautilus_trader.common import Environment
from nautilus_trader.live import LiveNode
from nautilus_trader.model import ClientId
from nautilus_trader.model import InstrumentId
from nautilus_trader.model import TraderId
from nautilus_trader.testkit import DataTesterConfig


BYBIT = "BYBIT"
TRADER_ID = TraderId.from_str("TESTER-001")
INSTRUMENT_ID = InstrumentId.from_str(f"BTCUSDT-LINEAR.{BYBIT}")


def main() -> None:
    """
    Run the example.
    """
    node = (
        LiveNode.builder("BYBIT-DATA-TESTER-001", TRADER_ID, Environment.LIVE)
        .add_data_client(
            None,
            BybitDataClientFactory(),
            BybitDataClientConfig(
                product_types=[BybitProductType.LINEAR],
                environment=BybitEnvironment.MAINNET,
            ),
        )
        .build()
    )
    node.add_builtin_actor(
        "DataTester",
        DataTesterConfig(
            client_id=ClientId.from_str(BYBIT),
            instrument_ids=[INSTRUMENT_ID],
            subscribe_quotes=True,
            subscribe_trades=True,
            subscribe_mark_prices=True,
            subscribe_index_prices=True,
            subscribe_funding_rates=True,
            manage_book=True,
            log_data=True,
        ),
    )

    node.run()


if __name__ == "__main__":
    main()

```

Shown in full with attribution under the source's licence. Licence: LGPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.