Qubx 3.17.1__tar.gz → 3.17.2.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {qubx-3.17.1 → qubx-3.17.2.dev1}/PKG-INFO +1 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/_version.py +2 -2
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/connector.py +7 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/__init__.py +9 -2
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/_two_stream.py +12 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/binance/exchange.py +3 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/bitfinex/bitfinex.py +0 -10
- qubx-3.17.2.dev1/src/qubx/connectors/ccxt/exchanges/bybit/bybit.py +311 -0
- qubx-3.17.2.dev1/src/qubx/connectors/ccxt/exchanges/bybit/connector.py +132 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/utils.py +74 -33
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/manager.py +7 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/reconciler.py +7 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/state.py +18 -10
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/basics.py +24 -17
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/lookups.py +3 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/trading.py +2 -1
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/utils.pyi +4 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/utils.pyx +72 -0
- qubx-3.17.2.dev1/src/qubx/utils/runner/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/.gitignore +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/LICENSE +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/README.md +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/pyproject.toml +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/scripts/build.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/_nb_magic.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/connector.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/data.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/iteratedstream.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/management.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/ome.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/optimization.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/runner.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/sentinels.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/simulated_data.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/simulated_exchange.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/simulator.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/transfers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/backtester/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/commands.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/deploy.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/misc.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/release.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/resolver.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/s3.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/theme.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/tui.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/cli/user_config.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/config.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/adapters/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/adapters/polling_adapter.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/connection_manager.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/data.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exceptions.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchange_manager.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/binance/connector.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/bitfinex/connector.py +0 -0
- {qubx-3.17.1/src/qubx/connectors/ccxt/exchanges/okx → qubx-3.17.2.dev1/src/qubx/connectors/ccxt/exchanges/bybit}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/gateio/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/gateio/gateio.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/hyperliquid/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/hyperliquid/hyperliquid.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/kraken/kraken.py +0 -0
- {qubx-3.17.1/src/qubx/core → qubx-3.17.2.dev1/src/qubx/connectors/ccxt/exchanges/okx}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/okx/connector.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/exchanges/okx/okx.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/factory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/factory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/funding_rate.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/liquidation.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/ohlc.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/open_interest.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/orderbook.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/quote.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/handlers/trade.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/plugin.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/rate_limits.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/subscription_config.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/subscription_manager.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/subscription_orchestrator.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/ccxt/warmup_service.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/plugin.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/registry.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/tardis/data.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/tardis/plugin.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/connectors/tardis/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/builtin.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/decorator.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/executor.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/interfaces.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/server.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/control/types.py +0 -0
- {qubx-3.17.1/src/qubx/restarts → qubx-3.17.2.dev1/src/qubx/core}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/config.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/diffs.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/reducer.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/account_manager/state_machine.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/boot.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/connector.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/context.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/detectors/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/detectors/delisting.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/detectors/stale.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/errors.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/events.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/exceptions.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/fit_context.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/fit_executor.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/helpers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/initializer.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/instrument_service.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/interfaces.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/loggers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/metrics.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/instrument_service.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/market.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/processing.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/subscription.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/universe.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/mixins/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/series.pxd +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/series.pyi +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/series.pyx +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/state_snapshot.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/status.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/core/subscription_watchdog.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/cache.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/containers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/guards.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/registry.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storage.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/ccxt.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/csv.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/handy.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/multi.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/questdb.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/stub.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/storages/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/data/transformers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/composite.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/csv.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/indicator.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/inmemory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/prometheus.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/emitters/questdb.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/composite.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/formatters/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/formatters/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/formatters/incremental.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/formatters/slack.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/formatters/target_position.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/redis_streams.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/exporters/slack.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/gathering/simplest.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/health/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/health/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/health/dummy.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/health/status.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/csv.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/factory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/inmemory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/mongo.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/loggers/postgres.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/notifications/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/notifications/composite.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/notifications/slack.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/notifications/throttler.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/pandaz/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/pandaz/stats.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/pandaz/ta.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/pandaz/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/plugins/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/plugins/loader.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/backend.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/config.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/engine.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/ip_resolver.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/manager.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/pools.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/redis_backend.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/rate_limiting/resilient.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/_build.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/crypto-fees.ini +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/hyperliquid-spot.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/hyperliquid.f-perpetual.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-binance-spot.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-binance.cm-future.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-binance.cm-perpetual.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-binance.um-future.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-binance.um-perpetual.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-bitfinex.f-perpetual.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-kraken-spot.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-kraken.f-future.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/resources/instruments/symbols-kraken.f-perpetual.json +0 -0
- {qubx-3.17.1/src/qubx/ta → qubx-3.17.2.dev1/src/qubx/restarts}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restarts/state_resolvers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restarts/time_finders.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/balance.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/factory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/interfaces.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/position.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/signal.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/state.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/restorers/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/state/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/state/dummy.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/state/redis.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/state/runtime_info.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/state/safe.py +0 -0
- {qubx-3.17.1/src/qubx/utils/plotting → qubx-3.17.2.dev1/src/qubx/ta}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/ta/indicators.pxd +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/ta/indicators.pyi +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/ta/indicators.pyx +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/base.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/accounts.toml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/config.yml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/jlive.sh.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/jpaper.sh.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/pyproject.toml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/src/{{ strategy_name }}/__init__.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/src/{{ strategy_name }}/strategy.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/project/template.yml +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.claude/skills/qubx-cli/SKILL.md +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.claude/skills/qubx-indicators/SKILL.md +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.claude/skills/simulation-explorer/SKILL.md +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.claude/skills/strategy-release/SKILL.md +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.github/workflows/ci.yml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.gitignore.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.python-version +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.vscode/launch.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.vscode/settings.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/.vscode/tasks.json +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/CLAUDE.md.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/README.md.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/configs/.gitkeep +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/justfile.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/pyproject.toml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/research/.gitkeep +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/src/{{ strategy_name }}/__init__.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/src/{{ strategy_name }}/cli.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/src/{{ strategy_name }}/strategy.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/template.yml +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/repo/tests/test_strategy.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/__init__.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/accounts.toml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/config.yml.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/jlive.sh.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/jpaper.sh.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/strategy.py.j2 +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/templates/simple/template.yml +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/advanced.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/composite.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/rebalancers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/riskctrl.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/trackers/sizers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/_pyxreloader.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/charting/lookinglass.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/charting/mpl_helpers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/charting/orderbook.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/clock.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/collections.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/hft/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/hft/numba_utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/hft/orderbook.pyi +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/hft/orderbook.pyx +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/marketdata/binance.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/marketdata/ccxt.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/marketdata/dukas.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/misc.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/nonce.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/numbers_utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/orderbook.py +0 -0
- {qubx-3.17.1/src/qubx/utils/plotting/renderers → qubx-3.17.2.dev1/src/qubx/utils/plotting}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/plotting/dashboard.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/plotting/data.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/plotting/interfaces.py +0 -0
- {qubx-3.17.1/src/qubx/utils/runner → qubx-3.17.2.dev1/src/qubx/utils/plotting/renderers}/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/plotting/renderers/plotly.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/questdb.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/rate_limiter.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/results.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/ringbuffer.pxd +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/ringbuffer.pyi +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/ringbuffer.pyx +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/_jupyter_runner.pyt +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/accounts.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/configs.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/factory.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/kernel_service.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/runner.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/app.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/handlers.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/init_code.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/kernel.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/styles.tcss +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/__init__.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/account_summary.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/command_input.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/debug_log.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/log_filter.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/orders_table.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/positions_table.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/quotes_table.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/runner/textual/widgets/repl_output.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/s3.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/slack.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/threading.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/throttler.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/time.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/src/qubx/utils/websocket_manager.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/tests/strategies/macd_crossover/src/macd_crossover/indicators/macd.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/tests/strategies/macd_crossover/src/macd_crossover/models/macd_crossover.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/tests/strategies/macd_crossover/src/macd_crossover/models/utils.py +0 -0
- {qubx-3.17.1 → qubx-3.17.2.dev1}/tests/strategies/obi_trader/src/obi_trader/models/obi_trader.py +0 -0
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '3.17.
|
|
22
|
-
__version_tuple__ = version_tuple = (3, 17,
|
|
21
|
+
__version__ = version = '3.17.2.dev1'
|
|
22
|
+
__version_tuple__ = version_tuple = (3, 17, 2, 'dev1')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -44,6 +44,7 @@ from ccxt import AuthenticationError, ExchangeClosedByUser, ExchangeError, Excha
|
|
|
44
44
|
from qubx import connector_logger, logger
|
|
45
45
|
from qubx.core.basics import (
|
|
46
46
|
FRAMEWORK_CID_PREFIX,
|
|
47
|
+
OPTION_REPRICE_IF_CROSSING,
|
|
47
48
|
Balance,
|
|
48
49
|
CtrlChannel,
|
|
49
50
|
CurrencyConversion,
|
|
@@ -89,6 +90,7 @@ from qubx.utils.time import to_timedelta
|
|
|
89
90
|
from .exceptions import CcxtSymbolNotRecognized
|
|
90
91
|
from .exchange_manager import ExchangeManager
|
|
91
92
|
from .utils import (
|
|
93
|
+
FRAMEWORK_ONLY_OPTIONS,
|
|
92
94
|
ccxt_convert_balance,
|
|
93
95
|
ccxt_convert_deal_info,
|
|
94
96
|
ccxt_convert_order_info,
|
|
@@ -315,6 +317,8 @@ class CcxtConnector(ChannelEmitter):
|
|
|
315
317
|
|
|
316
318
|
options = request.options or {}
|
|
317
319
|
reduce_only = bool(resolve_reduce_only(options))
|
|
320
|
+
post_only = bool(options.get("post_only", False))
|
|
321
|
+
reprice_if_crossing = bool(options.get(OPTION_REPRICE_IF_CROSSING, False))
|
|
318
322
|
|
|
319
323
|
# Quote lookup is the connector's only READ dependency; payload build raises
|
|
320
324
|
# framework-side rejections (no quote, below min-notional, missing price).
|
|
@@ -329,11 +333,13 @@ class CcxtConnector(ChannelEmitter):
|
|
|
329
333
|
time_in_force=request.time_in_force,
|
|
330
334
|
quote=quote,
|
|
331
335
|
reduce_only=reduce_only,
|
|
336
|
+
post_only=post_only,
|
|
337
|
+
reprice_if_crossing=reprice_if_crossing,
|
|
332
338
|
)
|
|
333
339
|
# Forward any remaining venue-specific options ccxt understands (e.g.
|
|
334
340
|
# lighter_* indices) without clobbering what the payload builder set.
|
|
335
341
|
for k, v in options.items():
|
|
336
|
-
if k in
|
|
342
|
+
if k in FRAMEWORK_ONLY_OPTIONS:
|
|
337
343
|
continue
|
|
338
344
|
payload["params"].setdefault(k, v)
|
|
339
345
|
|
|
@@ -10,6 +10,8 @@ from ..connector import CcxtConnector
|
|
|
10
10
|
from .binance.connector import BinancePmCcxtConnector
|
|
11
11
|
from .binance.exchange import BINANCE_UM_MM, BinancePortfolioMargin, BinanceQV, BinanceQVUSDM
|
|
12
12
|
from .bitfinex.connector import BitfinexCcxtConnector
|
|
13
|
+
from .bybit.bybit import BybitF
|
|
14
|
+
from .bybit.connector import BybitCcxtConnector
|
|
13
15
|
from .gateio.gateio import GateioFutures
|
|
14
16
|
from .hyperliquid.hyperliquid import Hyperliquid, HyperliquidF
|
|
15
17
|
from .kraken.kraken import CustomKrakenFutures
|
|
@@ -45,14 +47,15 @@ EXCHANGE_ALIASES = {
|
|
|
45
47
|
"bitfinex.f": "bitfinex_f",
|
|
46
48
|
"hyperliquid": "hyperliquid",
|
|
47
49
|
"hyperliquid.f": "hyperliquid_f",
|
|
48
|
-
"bybit.f": "
|
|
50
|
+
"bybit.f": "bybit_f",
|
|
49
51
|
"gateio.f": "gateio_futures",
|
|
50
52
|
"okx.f": "okx_futures",
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
# CcxtConnector subclasses per exchange. Unlisted exchanges (Binance,
|
|
54
56
|
# Hyperliquid, ...) use the base CcxtConnector via the factory fallback. OKX/Bitfinex
|
|
55
|
-
# need the split orders/fills streams; OKX additionally overrides balance/clOrdId.
|
|
57
|
+
# need the split orders/fills streams; OKX additionally overrides balance/clOrdId. Bybit needs
|
|
58
|
+
# them too: ccxt's parse_order hardcodes ``trades: None``, so fills arrive only on executions.
|
|
56
59
|
# Keyed by the normalized framework exchange names, plus
|
|
57
60
|
# the bare ``okx``/``bitfinex`` aliases the factory may receive. Bitfinex's connector
|
|
58
61
|
# subclass has NO dependency on the optional qubx-bitfinex-api package (it only needs
|
|
@@ -65,6 +68,8 @@ CUSTOM_CONNECTORS: dict[str, type[CcxtConnector]] = {
|
|
|
65
68
|
"bitfinex": BitfinexCcxtConnector,
|
|
66
69
|
"bitfinex.f": BitfinexCcxtConnector,
|
|
67
70
|
"binance.pm": BinancePmCcxtConnector,
|
|
71
|
+
"bybit": BybitCcxtConnector,
|
|
72
|
+
"bybit.f": BybitCcxtConnector,
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
READER_CAPABILITIES = {
|
|
@@ -93,6 +98,7 @@ cxp.hyperliquid = Hyperliquid # type: ignore
|
|
|
93
98
|
cxp.hyperliquid_f = HyperliquidF # type: ignore
|
|
94
99
|
cxp.gateio_futures = GateioFutures # type: ignore
|
|
95
100
|
cxp.okx_futures = OkxFutures # type: ignore
|
|
101
|
+
cxp.bybit_f = BybitF # type: ignore
|
|
96
102
|
|
|
97
103
|
cxp.exchanges.append("binanceqv")
|
|
98
104
|
cxp.exchanges.append("binanceqv_usdm")
|
|
@@ -105,3 +111,4 @@ cxp.exchanges.append("hyperliquid")
|
|
|
105
111
|
cxp.exchanges.append("hyperliquid_f")
|
|
106
112
|
cxp.exchanges.append("gateio_futures")
|
|
107
113
|
cxp.exchanges.append("okx_futures")
|
|
114
|
+
cxp.exchanges.append("bybit_f")
|
|
@@ -88,12 +88,23 @@ class _TwoStreamCcxtConnector(CcxtConnector):
|
|
|
88
88
|
self.send(
|
|
89
89
|
DealEvent(
|
|
90
90
|
instrument=instrument,
|
|
91
|
-
client_order_id=
|
|
91
|
+
client_order_id=self._trade_client_id(raw),
|
|
92
92
|
venue_order_id=raw.get("order"),
|
|
93
93
|
deal=deal,
|
|
94
94
|
)
|
|
95
95
|
)
|
|
96
96
|
|
|
97
|
+
def _trade_client_id(self, raw: dict[str, Any]) -> str | None:
|
|
98
|
+
"""The cid this trade carries, when the venue puts one on its execution frame.
|
|
99
|
+
|
|
100
|
+
Resolving by venue id alone loses the race a market order can create: the trade can
|
|
101
|
+
arrive before the submit ack has mapped that id, and AM then materializes a phantom
|
|
102
|
+
EXTERNAL order which absorbs the fill — leaving the real order at filled=0 with its
|
|
103
|
+
seen-trade-ids on the phantom. The order itself is already in state (registered before
|
|
104
|
+
submit), so a cid resolves it immediately. None keeps the venue-id-only behaviour.
|
|
105
|
+
"""
|
|
106
|
+
return None
|
|
107
|
+
|
|
97
108
|
# ------------------------------------------------------------------ #
|
|
98
109
|
# Order-status stream — fill branches (override the base's inline-trade reads)
|
|
99
110
|
# ------------------------------------------------------------------ #
|
|
@@ -840,6 +840,9 @@ class BinancePortfolioMargin(BinanceQVUSDM):
|
|
|
840
840
|
raise BadRequest(f"{self.id} algo {algo_order_type} requires a price")
|
|
841
841
|
request["price"] = self.price_to_precision(symbol, price)
|
|
842
842
|
request["timeInForce"] = self.safe_string_upper(params, "timeInForce", "GTC")
|
|
843
|
+
# The algo endpoint has no postOnly flag — it must be expressed as GTX TIF.
|
|
844
|
+
if self.safe_bool(params, "postOnly", False):
|
|
845
|
+
request["timeInForce"] = "GTX"
|
|
843
846
|
cid = self.safe_string_2(params, "clientOrderId", "newClientOrderId")
|
|
844
847
|
if cid is not None:
|
|
845
848
|
request["clientAlgoId"] = cid
|
|
@@ -76,11 +76,6 @@ class BitfinexF(CcxtFuturePatchMixin, cxp.bitfinex):
|
|
|
76
76
|
self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}
|
|
77
77
|
):
|
|
78
78
|
params.pop("type", None)
|
|
79
|
-
if "timeInForce" in params and params["timeInForce"] == "GTX":
|
|
80
|
-
# GTX is not supported by bitfinex, so we need to convert it to PO
|
|
81
|
-
params["timeInForce"] = "PO"
|
|
82
|
-
params["postOnly"] = True
|
|
83
|
-
|
|
84
79
|
if "lev" not in params:
|
|
85
80
|
params["lev"] = 2
|
|
86
81
|
|
|
@@ -91,11 +86,6 @@ class BitfinexF(CcxtFuturePatchMixin, cxp.bitfinex):
|
|
|
91
86
|
self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}
|
|
92
87
|
) -> Order:
|
|
93
88
|
params.pop("type", None)
|
|
94
|
-
if "timeInForce" in params and params["timeInForce"] == "GTX":
|
|
95
|
-
# GTX is not supported by bitfinex, so we need to convert it to PO
|
|
96
|
-
params["timeInForce"] = "PO"
|
|
97
|
-
params["postOnly"] = True
|
|
98
|
-
|
|
99
89
|
if "lev" not in params:
|
|
100
90
|
params["lev"] = 2
|
|
101
91
|
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from collections.abc import Awaitable, Callable
|
|
3
|
+
from functools import partial
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import ccxt.pro as cxp
|
|
7
|
+
from ccxt.base.errors import ArgumentsRequired, BadRequest, OrderNotFound
|
|
8
|
+
from ccxt.base.types import Liquidation, Num, Order, OrderSide, OrderType, Position, Str, Strings
|
|
9
|
+
|
|
10
|
+
from ...adapters.polling_adapter import PollingConfig, PollingToWebSocketAdapter
|
|
11
|
+
from ...utils import info_float
|
|
12
|
+
from ..base import CcxtFuturePatchMixin
|
|
13
|
+
|
|
14
|
+
# Bybit answers a redundant set_leverage with this code rather than no-opping.
|
|
15
|
+
_LEVERAGE_NOT_MODIFIED = "110043"
|
|
16
|
+
|
|
17
|
+
# a stop rests on the far side of the market from its own side: BUY above, SELL below
|
|
18
|
+
_TRIGGER_DIRECTION = {"buy": "ascending", "sell": "descending"}
|
|
19
|
+
|
|
20
|
+
# a symbol-less positions/orders read defaults to settleCoin=USDT, so anything settled in
|
|
21
|
+
# another coin reads as absent; the endpoints take one settle coin per call
|
|
22
|
+
_SETTLE_COINS = ("USDT", "USDC")
|
|
23
|
+
|
|
24
|
+
# Bybit ranks the ADL queue 1..5, 0 = not ranked; the framework scale is Binance's 0..4,
|
|
25
|
+
# higher = closer to the front of the queue.
|
|
26
|
+
_ADL_MIN_RANK = 1
|
|
27
|
+
_ADL_MAX_RANK = 5
|
|
28
|
+
|
|
29
|
+
# a crossing post-only order comes back cancelled with this reject-reason family
|
|
30
|
+
_POST_ONLY_REFUSAL = "EC_PostOnly"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _adl_level(position: Any) -> int | None:
|
|
34
|
+
"""Bybit's ``adlRankIndicator`` on the framework scale.
|
|
35
|
+
|
|
36
|
+
A rank outside 1..5 is dropped, not clamped: 0 means "not ranked", not "safest".
|
|
37
|
+
"""
|
|
38
|
+
rank = info_float(position, "adlRankIndicator")
|
|
39
|
+
if rank is None or not (_ADL_MIN_RANK <= rank <= _ADL_MAX_RANK):
|
|
40
|
+
return None
|
|
41
|
+
return int(rank) - _ADL_MIN_RANK
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
FUNDING_RATE_DEFAULT_POLL_MINUTES = 5
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BybitF(CcxtFuturePatchMixin, cxp.bybit):
|
|
48
|
+
"""Bybit perpetual futures: ccxt patches for the calls Bybit does not accept as written."""
|
|
49
|
+
|
|
50
|
+
# the only depths Bybit's WS book serves; anything else is a BadRequest at subscribe
|
|
51
|
+
_WS_DEPTHS = (1, 50, 200, 1000)
|
|
52
|
+
|
|
53
|
+
def __init__(self, config=None):
|
|
54
|
+
super().__init__(config or {})
|
|
55
|
+
self._funding_rate_adapter: PollingToWebSocketAdapter | None = None
|
|
56
|
+
|
|
57
|
+
def describe(self):
|
|
58
|
+
return self.deep_extend(
|
|
59
|
+
super().describe(),
|
|
60
|
+
{
|
|
61
|
+
"has": {
|
|
62
|
+
"unWatchBidsAsks": True,
|
|
63
|
+
"watchFundingRates": True,
|
|
64
|
+
"watchLiquidationsForSymbols": True,
|
|
65
|
+
},
|
|
66
|
+
"options": {
|
|
67
|
+
"fetchOrder": {"acknowledged": True},
|
|
68
|
+
# caps the cursor walk armed by params={"paginate": True}; read by the
|
|
69
|
+
# pagination driver only, so it cannot re-arm on the recursive call
|
|
70
|
+
"fetchOpenOrders": {"paginationCalls": 20},
|
|
71
|
+
"fetchPositions": {"paginationCalls": 20},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def _settle_filtered(self, params: dict) -> bool:
|
|
77
|
+
return any(params.get(k) is not None for k in ("settleCoin", "baseCoin", "symbol"))
|
|
78
|
+
|
|
79
|
+
async def _per_settle_coin(self, fetch: Callable[[dict], Awaitable[list]], params: dict) -> list:
|
|
80
|
+
"""One paginated call per settle coin, concatenated.
|
|
81
|
+
|
|
82
|
+
The row caps — /v5/order/realtime serves 20, ccxt pins /v5/position/list at 200 — need
|
|
83
|
+
the cursor walk, and ``paginate`` must ride params, not options: the recursive call
|
|
84
|
+
carries ``settleCoin``, so it lands back on the filtered branch and ends at ``super()``.
|
|
85
|
+
"""
|
|
86
|
+
legs = await asyncio.gather(
|
|
87
|
+
*(fetch(self.extend(params, {"settleCoin": coin, "paginate": True})) for coin in _SETTLE_COINS)
|
|
88
|
+
)
|
|
89
|
+
return [row for leg in legs for row in leg]
|
|
90
|
+
|
|
91
|
+
async def fetch_positions(self, symbols: Strings = None, params={}) -> list[Any]:
|
|
92
|
+
if symbols or self._settle_filtered(params):
|
|
93
|
+
return await super().fetch_positions(symbols, params)
|
|
94
|
+
return await self._per_settle_coin(partial(super(BybitF, self).fetch_positions, symbols), params)
|
|
95
|
+
|
|
96
|
+
def parse_position(self, position, market=None) -> Position:
|
|
97
|
+
"""Keep the venue's own maintenance margin and put the ADL rank on the unified key.
|
|
98
|
+
|
|
99
|
+
ccxt reads ``positionMM`` and then replaces it with ``|liqPrice - bustPrice| * size``
|
|
100
|
+
whenever a liquidation price is set; a UTA account reports ``bustPrice=""``, so the
|
|
101
|
+
product is None and the framework falls back to a flat 5% of notional.
|
|
102
|
+
|
|
103
|
+
``info`` is ccxt's passthrough of the raw row, which is where ``ccxt_convert_position``
|
|
104
|
+
reads ``adl`` — Bybit spells the same figure ``adlRankIndicator`` on a 1-based scale.
|
|
105
|
+
"""
|
|
106
|
+
parsed = super().parse_position(position, market)
|
|
107
|
+
if parsed.get("maintenanceMargin") is None:
|
|
108
|
+
venue_mm = info_float(position, "positionMM")
|
|
109
|
+
if venue_mm is not None:
|
|
110
|
+
parsed["maintenanceMargin"] = venue_mm
|
|
111
|
+
adl = _adl_level(position)
|
|
112
|
+
if adl is not None:
|
|
113
|
+
parsed["info"] = {**position, "adl": adl}
|
|
114
|
+
return parsed
|
|
115
|
+
|
|
116
|
+
async def fetch_open_orders(
|
|
117
|
+
self, symbol: Str = None, since: Num = None, limit: Num = None, params={}
|
|
118
|
+
) -> list[Order]:
|
|
119
|
+
if symbol is not None or self._settle_filtered(params):
|
|
120
|
+
return await super().fetch_open_orders(symbol, since, limit, params)
|
|
121
|
+
return await self._per_settle_coin(partial(super(BybitF, self).fetch_open_orders, symbol, since, limit), params)
|
|
122
|
+
|
|
123
|
+
def create_order_request(
|
|
124
|
+
self,
|
|
125
|
+
symbol: str,
|
|
126
|
+
type: OrderType,
|
|
127
|
+
side: OrderSide,
|
|
128
|
+
amount: float,
|
|
129
|
+
price: Num = None,
|
|
130
|
+
params={},
|
|
131
|
+
isUTA=True,
|
|
132
|
+
):
|
|
133
|
+
return super().create_order_request(
|
|
134
|
+
symbol, type, side, amount, price, self._with_trigger_direction(side, params), isUTA
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
@staticmethod
|
|
138
|
+
def _with_trigger_direction(side: str, params: dict) -> dict:
|
|
139
|
+
"""ccxt refuses every non-spot trigger order that does not carry ``triggerDirection``."""
|
|
140
|
+
if params.get("triggerDirection") is not None:
|
|
141
|
+
return params
|
|
142
|
+
if params.get("triggerPrice") is None and params.get("stopPrice") is None:
|
|
143
|
+
return params
|
|
144
|
+
return {**params, "triggerDirection": _TRIGGER_DIRECTION[side.lower()]}
|
|
145
|
+
|
|
146
|
+
def parse_order(self, order, market=None):
|
|
147
|
+
"""Report a post-only refusal as rejected, not cancelled.
|
|
148
|
+
|
|
149
|
+
Bybit accepts a crossing post-only order and then cancels it with
|
|
150
|
+
``rejectReason=EC_PostOnlyWillTakeLiquidity`` instead of refusing it synchronously.
|
|
151
|
+
"""
|
|
152
|
+
parsed = super().parse_order(order, market)
|
|
153
|
+
if parsed.get("status") == "canceled":
|
|
154
|
+
reason = self.safe_string(parsed.get("info") or {}, "rejectReason", "")
|
|
155
|
+
if reason.startswith(_POST_ONLY_REFUSAL):
|
|
156
|
+
parsed["status"] = "rejected"
|
|
157
|
+
return parsed
|
|
158
|
+
|
|
159
|
+
async def set_leverage(self, leverage: int, symbol: Str = None, params={}):
|
|
160
|
+
"""Treat a redundant set as the silent no-op every other venue answers with."""
|
|
161
|
+
try:
|
|
162
|
+
return await super().set_leverage(leverage, symbol, params)
|
|
163
|
+
except BadRequest as e:
|
|
164
|
+
if _LEVERAGE_NOT_MODIFIED not in str(e):
|
|
165
|
+
raise
|
|
166
|
+
return {}
|
|
167
|
+
|
|
168
|
+
def cancel_order_request(self, id: str, symbol: Str = None, params={}):
|
|
169
|
+
link_id = self.safe_string_2(params, "orderLinkId", "clientOrderId")
|
|
170
|
+
if link_id is None:
|
|
171
|
+
return super().cancel_order_request(id, symbol, params)
|
|
172
|
+
request = super().cancel_order_request(id, symbol, self.omit(params, ["clientOrderId", "orderLinkId"]))
|
|
173
|
+
request.pop("orderId", None)
|
|
174
|
+
request["orderLinkId"] = link_id
|
|
175
|
+
return request
|
|
176
|
+
|
|
177
|
+
async def fetch_order(self, id: str, symbol: Str = None, params={}) -> Order:
|
|
178
|
+
"""Look up an order, retrying without the trigger filter before believing it is gone.
|
|
179
|
+
|
|
180
|
+
``trigger``/``stop`` becomes ``orderFilter=StopOrder``, which holds only UNTRIGGERED
|
|
181
|
+
conditionals — a fired stop moves to the regular book but still reads back STOP_MARKET.
|
|
182
|
+
"""
|
|
183
|
+
try:
|
|
184
|
+
return await self._fetch_order(id, symbol, params)
|
|
185
|
+
except OrderNotFound:
|
|
186
|
+
if not self.safe_bool_2(params, "trigger", "stop", False):
|
|
187
|
+
raise
|
|
188
|
+
return await self._fetch_order(id, symbol, self.omit(params, ["trigger", "stop"]))
|
|
189
|
+
|
|
190
|
+
async def _fetch_order(self, id: str, symbol: Str, params: dict) -> Order:
|
|
191
|
+
"""Route a client-id lookup through the order-list endpoints, the only ones that accept
|
|
192
|
+
``orderLinkId``."""
|
|
193
|
+
link_id = self.safe_string_2(params, "orderLinkId", "clientOrderId")
|
|
194
|
+
if link_id is None:
|
|
195
|
+
return await super().fetch_order(id, symbol, params)
|
|
196
|
+
rest = self.omit(params, ["clientOrderId", "orderLinkId"])
|
|
197
|
+
for fetch in (self.fetch_open_orders, self.fetch_canceled_and_closed_orders):
|
|
198
|
+
rows = await fetch(symbol, None, None, self.extend(rest, {"orderLinkId": link_id}))
|
|
199
|
+
# match explicitly rather than trusting the venue-side filter
|
|
200
|
+
for row in rows:
|
|
201
|
+
if row.get("clientOrderId") == link_id:
|
|
202
|
+
return row
|
|
203
|
+
raise OrderNotFound(f"{self.id} order with orderLinkId {link_id} was not found")
|
|
204
|
+
|
|
205
|
+
async def watch_bids_asks(self, symbols: Strings = None, params={}) -> dict:
|
|
206
|
+
"""Take quotes off ``tickers``, not ``orderbook.1``.
|
|
207
|
+
|
|
208
|
+
ccxt's ``watchBidsAsks`` writes its one-level book into the same
|
|
209
|
+
``self.orderbooks[symbol]`` the depth subscription fills, collapsing the L2 book.
|
|
210
|
+
"""
|
|
211
|
+
tickers = await self.watch_tickers(symbols, params)
|
|
212
|
+
return {s: t for s, t in tickers.items() if t.get("bid") is not None and t.get("ask") is not None}
|
|
213
|
+
|
|
214
|
+
async def un_watch_bids_asks(self, symbols: Strings = None, params={}) -> Any:
|
|
215
|
+
"""Release the tickers topic ``watch_bids_asks`` subscribed; upstream has no unwatch."""
|
|
216
|
+
return await self.un_watch_tickers(symbols, params)
|
|
217
|
+
|
|
218
|
+
async def watch_funding_rates(
|
|
219
|
+
self, symbols: list[str] | None = None, params: dict[str, Any] | None = None
|
|
220
|
+
) -> dict[str, Any]:
|
|
221
|
+
"""Present ``fetch_funding_rates`` as a watch, on a poll.
|
|
222
|
+
|
|
223
|
+
Bybit has no funding WS channel, and ``tickers`` carries the rate on its snapshot frame
|
|
224
|
+
only — a topic ``watch_bids_asks`` already owns.
|
|
225
|
+
"""
|
|
226
|
+
params = params or {}
|
|
227
|
+
await self.load_markets()
|
|
228
|
+
poll_minutes = params.get("poll_interval_minutes", FUNDING_RATE_DEFAULT_POLL_MINUTES)
|
|
229
|
+
|
|
230
|
+
if self._funding_rate_adapter is None:
|
|
231
|
+
self._funding_rate_adapter = PollingToWebSocketAdapter(
|
|
232
|
+
fetch_method=self._fetch_funding_rates_for,
|
|
233
|
+
symbols=symbols or [],
|
|
234
|
+
params=params,
|
|
235
|
+
config=PollingConfig(poll_interval_seconds=poll_minutes * 60),
|
|
236
|
+
)
|
|
237
|
+
elif symbols is not None:
|
|
238
|
+
await self._funding_rate_adapter.update_symbols(symbols)
|
|
239
|
+
|
|
240
|
+
rates = await self._funding_rate_adapter.get_next_data()
|
|
241
|
+
# ccxt's bybit parser writes the next funding time as `fundingTimestamp`;
|
|
242
|
+
# ccxt_convert_funding_rate reads `nextFundingTime`
|
|
243
|
+
return {
|
|
244
|
+
symbol: {**info, "nextFundingTime": info.get("fundingTimestamp")}
|
|
245
|
+
for symbol, info in (rates or {}).items()
|
|
246
|
+
if isinstance(info, dict)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async def _fetch_funding_rates_for(self, symbols: list[str], **params) -> dict[str, Any]:
|
|
250
|
+
# bybit's fetch does market(symbols[0]) on an empty list -> IndexError
|
|
251
|
+
return await self.fetch_funding_rates(symbols or None, params)
|
|
252
|
+
|
|
253
|
+
async def un_watch_funding_rates(self, symbols: list[str] | None = None) -> None:
|
|
254
|
+
"""The handler's cleanup calls this with no arguments, meaning "stop everything"."""
|
|
255
|
+
adapter = self._funding_rate_adapter
|
|
256
|
+
if adapter is None:
|
|
257
|
+
return
|
|
258
|
+
if symbols:
|
|
259
|
+
await adapter.remove_symbols(symbols)
|
|
260
|
+
if adapter.is_watching():
|
|
261
|
+
return
|
|
262
|
+
await adapter.stop()
|
|
263
|
+
self._funding_rate_adapter = None
|
|
264
|
+
|
|
265
|
+
def _ws_depth(self, limit: int | None) -> int:
|
|
266
|
+
"""Round a requested depth up to one Bybit serves; 50 is ccxt's linear default, pinned
|
|
267
|
+
here so the unwatch topic matches the subscribed one."""
|
|
268
|
+
return next((d for d in self._WS_DEPTHS if d >= (limit or 50)), self._WS_DEPTHS[-1])
|
|
269
|
+
|
|
270
|
+
async def watch_order_book_for_symbols(self, symbols: list[str], limit: int | None = None, params={}):
|
|
271
|
+
return await super().watch_order_book_for_symbols(symbols, self._ws_depth(limit), params)
|
|
272
|
+
|
|
273
|
+
async def un_watch_order_book_for_symbols(self, symbols: list[str], limit: int | None = None, params={}) -> Any:
|
|
274
|
+
"""Upstream takes the depth via params and otherwise defaults to 500, an illegal topic."""
|
|
275
|
+
return await super().un_watch_order_book_for_symbols(
|
|
276
|
+
symbols, self.extend(params, {"limit": self._ws_depth(limit)})
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
async def un_watch_order_book(self, symbol: str, limit: int | None = None, params={}) -> Any:
|
|
280
|
+
# upstream passes params as the second positional, which is our limit
|
|
281
|
+
return await self.un_watch_order_book_for_symbols([symbol], limit, params)
|
|
282
|
+
|
|
283
|
+
async def watch_liquidations_for_symbols(
|
|
284
|
+
self, symbols: list[str], since: int | None = None, limit: int | None = None, params={}
|
|
285
|
+
) -> list[Liquidation]:
|
|
286
|
+
"""Subscribe ``allLiquidation`` for many symbols at once: ccxt ships only the
|
|
287
|
+
single-symbol watch, and no unwatch for liquidations on any venue."""
|
|
288
|
+
if not symbols:
|
|
289
|
+
raise ArgumentsRequired(f"{self.id} watchLiquidationsForSymbols() requires a non-empty array of symbols")
|
|
290
|
+
await self.load_markets()
|
|
291
|
+
symbols = self.market_symbols(symbols)
|
|
292
|
+
url = await self.get_url_by_market_type(symbols[0], False, "watchLiquidations", params)
|
|
293
|
+
params = self.clean_params(params)
|
|
294
|
+
method, params = self.handle_option_and_params(params, "watchLiquidations", "method", "allLiquidation")
|
|
295
|
+
topics = [method + "." + self.market(symbol)["id"] for symbol in symbols]
|
|
296
|
+
hashes = ["liquidations::" + symbol for symbol in symbols]
|
|
297
|
+
liquidations = await self.watch_topics(url, hashes, topics, params)
|
|
298
|
+
if self.newUpdates:
|
|
299
|
+
return liquidations
|
|
300
|
+
return self.filter_by_symbols_since_limit(self.liquidations, symbols, since, limit, True)
|
|
301
|
+
|
|
302
|
+
def parse_ws_liquidation(self, liquidation, market=None) -> Liquidation:
|
|
303
|
+
"""Report the side of the liquidating ORDER, as other venues do.
|
|
304
|
+
|
|
305
|
+
ccxt passes ``'S'`` as ``safe_string_lower``'s default value instead of as a second key,
|
|
306
|
+
and Bybit's ``S`` is the POSITION side — the inverse of Binance's ``forceOrder``.
|
|
307
|
+
"""
|
|
308
|
+
parsed = super().parse_ws_liquidation(liquidation, market)
|
|
309
|
+
position_side = self.safe_string_lower_2(liquidation, "side", "S")
|
|
310
|
+
parsed["side"] = "sell" if position_side == "buy" else "buy"
|
|
311
|
+
return parsed
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Bybit CcxtConnector subclass.
|
|
2
|
+
|
|
3
|
+
Bybit, like OKX and Bitfinex, splits the account feed: ``bybit.parse_order`` sets
|
|
4
|
+
``trades: None``, so fills arrive only on the ``execution`` topic ``watch_my_trades`` reads
|
|
5
|
+
(same /v5/private socket). On top of that split, it fills margin mode and the venue account
|
|
6
|
+
figures from Bybit surfaces ccxt's unified shapes do not reach.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Any, Literal
|
|
10
|
+
|
|
11
|
+
from qubx import logger
|
|
12
|
+
from qubx.core.basics import Instrument, Position, RejectCause
|
|
13
|
+
|
|
14
|
+
from ...utils import info_float, instrument_to_ccxt_symbol, normalize_margin_mode
|
|
15
|
+
from .._two_stream import _TwoStreamCcxtConnector
|
|
16
|
+
from .bybit import _POST_ONLY_REFUSAL
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _account_block(raw_balance: dict[str, Any]) -> dict[str, Any]:
|
|
20
|
+
"""``info.result.list[0]`` of a Bybit wallet-balance payload, ``{}`` when absent/malformed.
|
|
21
|
+
|
|
22
|
+
Runs outside ``_snapshot_async``'s per-leg isolation, so raising would sink the snapshot.
|
|
23
|
+
"""
|
|
24
|
+
info = raw_balance.get("info")
|
|
25
|
+
if not isinstance(info, dict):
|
|
26
|
+
return {}
|
|
27
|
+
result = info.get("result")
|
|
28
|
+
if not isinstance(result, dict):
|
|
29
|
+
return {}
|
|
30
|
+
rows = result.get("list")
|
|
31
|
+
if not isinstance(rows, list) or not rows or not isinstance(rows[0], dict):
|
|
32
|
+
return {}
|
|
33
|
+
return rows[0]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class BybitCcxtConnector(_TwoStreamCcxtConnector):
|
|
37
|
+
"""Bybit connector: split orders/fills streams, Bybit account surface, base behavior otherwise."""
|
|
38
|
+
|
|
39
|
+
# account-wide on a UTA, so one value serves every instrument
|
|
40
|
+
_margin_mode: Literal["cross", "isolated"] | None = None
|
|
41
|
+
|
|
42
|
+
def _trade_client_id(self, raw: dict[str, Any]) -> str | None:
|
|
43
|
+
"""Bybit's execution frame carries ``orderLinkId``; ccxt keeps it on ``info``.
|
|
44
|
+
|
|
45
|
+
Empty for an order placed outside the framework, which then materializes as EXTERNAL.
|
|
46
|
+
"""
|
|
47
|
+
return (raw.get("info") or {}).get("orderLinkId") or None
|
|
48
|
+
|
|
49
|
+
async def _fill_leverage_settings(self, positions: list[Position]) -> None:
|
|
50
|
+
await super()._fill_leverage_settings(positions)
|
|
51
|
+
await self._fill_margin_mode(positions)
|
|
52
|
+
|
|
53
|
+
async def _fill_margin_mode(self, positions: list[Position]) -> None:
|
|
54
|
+
"""Stamp ``Position.margin_mode`` from ONE account-wide ``/v5/account/info`` read.
|
|
55
|
+
|
|
56
|
+
ccxt's ``bybit.parse_position`` hardcodes ``marginMode: None``; the symbol only feeds
|
|
57
|
+
``safe_symbol``, so any held instrument answers for all of them.
|
|
58
|
+
|
|
59
|
+
Served from the cache once it is warm — the read shares ccxt's throttle with order
|
|
60
|
+
placement, and ``set_margin_mode`` drops the cache when the value can have changed.
|
|
61
|
+
"""
|
|
62
|
+
if not positions:
|
|
63
|
+
return
|
|
64
|
+
mode = self._margin_mode or await self._read_margin_mode(instrument_to_ccxt_symbol(positions[0].instrument))
|
|
65
|
+
if mode is None:
|
|
66
|
+
return
|
|
67
|
+
self._margin_mode = mode
|
|
68
|
+
for pos in positions:
|
|
69
|
+
pos.margin_mode = mode
|
|
70
|
+
|
|
71
|
+
async def _read_margin_mode(self, symbol: str) -> Literal["cross", "isolated"] | None:
|
|
72
|
+
"""PORTFOLIO_MARGIN has no framework equivalent and normalizes to None."""
|
|
73
|
+
try:
|
|
74
|
+
row = await self._em.exchange.fetch_margin_mode(symbol)
|
|
75
|
+
except Exception as e: # noqa: BLE001
|
|
76
|
+
logger.debug(f"[{self.exchange_name}] fetch_margin_mode for {symbol}: {e}")
|
|
77
|
+
return None
|
|
78
|
+
return normalize_margin_mode(row.get("marginMode"))
|
|
79
|
+
|
|
80
|
+
def set_margin_mode(self, instrument: Instrument, mode: str) -> bool:
|
|
81
|
+
"""Drop the cached mode on a successful write so the next read goes back to the venue."""
|
|
82
|
+
ok = super().set_margin_mode(instrument, mode)
|
|
83
|
+
if ok:
|
|
84
|
+
self._margin_mode = None
|
|
85
|
+
return ok
|
|
86
|
+
|
|
87
|
+
def get_margin_mode(self, instrument: Instrument) -> str | None:
|
|
88
|
+
"""Serve what the snapshot cached; a cold cache costs one REST hop on the strategy
|
|
89
|
+
thread, every later call a field read. Never raises at the caller: a venue read that
|
|
90
|
+
fails or times out reports None, as the base connector's does."""
|
|
91
|
+
if self._margin_mode is not None:
|
|
92
|
+
return self._margin_mode
|
|
93
|
+
try:
|
|
94
|
+
self._margin_mode = self._run_sync(self._read_margin_mode(instrument_to_ccxt_symbol(instrument)))
|
|
95
|
+
except Exception as e: # noqa: BLE001
|
|
96
|
+
logger.debug(f"[{self.exchange_name}] margin mode read for {instrument.symbol}: {e}")
|
|
97
|
+
return None
|
|
98
|
+
return self._margin_mode
|
|
99
|
+
|
|
100
|
+
def _extract_venue_figures(
|
|
101
|
+
self, raw_balance: dict[str, Any]
|
|
102
|
+
) -> tuple[float | None, float | None, float | None, float | None, float | None, float | None]:
|
|
103
|
+
"""(equity, available_margin, margin_ratio, withdrawable, maint_margin, initial_margin)
|
|
104
|
+
from ``info.result.list[0]``.
|
|
105
|
+
|
|
106
|
+
``accountMMRate`` is maintenance margin OVER equity — the reciprocal of the framework's
|
|
107
|
+
ratio — and ``""``/``"0"`` map to None, as does withdrawable (per coin only), so that AM
|
|
108
|
+
derives those metrics.
|
|
109
|
+
"""
|
|
110
|
+
acct = _account_block(raw_balance)
|
|
111
|
+
mm_rate = info_float(acct, "accountMMRate")
|
|
112
|
+
return (
|
|
113
|
+
info_float(acct, "totalMarginBalance"),
|
|
114
|
+
info_float(acct, "totalAvailableBalance"),
|
|
115
|
+
1.0 / mm_rate if mm_rate is not None and mm_rate > 0 else None,
|
|
116
|
+
None,
|
|
117
|
+
info_float(acct, "totalMaintenanceMargin"),
|
|
118
|
+
info_float(acct, "totalInitialMargin"),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def _reject_details(self, raw: dict[str, Any]) -> tuple[str | None, RejectCause]:
|
|
122
|
+
"""The venue's verdict on a rejection seen on the read path.
|
|
123
|
+
|
|
124
|
+
Bybit either reports ``orderStatus=Rejected`` outright or accepts and then cancels,
|
|
125
|
+
which ``BybitF.parse_order`` normalises to rejected; both carry ``rejectReason``.
|
|
126
|
+
"""
|
|
127
|
+
reason = (raw.get("info") or {}).get("rejectReason") or None
|
|
128
|
+
if reason is None:
|
|
129
|
+
return None, RejectCause.UNKNOWN
|
|
130
|
+
# the price could not rest (post-only crossing) or fill (IOC/FOK with nothing to take)
|
|
131
|
+
not_fillable = reason.startswith((_POST_ONLY_REFUSAL, "EC_NoImmediateQty"))
|
|
132
|
+
return reason, RejectCause.NOT_FILLABLE if not_fillable else RejectCause.UNKNOWN
|