Skip to content

Commit

Permalink
Fix Bybit Spot instrument parsing and startup
Browse files Browse the repository at this point in the history
cjdsellers committed Mar 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 06fb3b0 commit cb0f855
Showing 4 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions examples/live/bybit/bybit_market_maker.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@
# *** THIS INTEGRATION IS STILL UNDER CONSTRUCTION. ***
# *** CONSIDER IT TO BE IN AN UNSTABLE BETA PHASE AND EXERCISE CAUTION. ***

instrument_type = BybitInstrumentType.LINEAR

# Configure the trading node
config_node = TradingNodeConfig(
trader_id=TraderId("TESTER-001"),
@@ -73,7 +75,7 @@
api_secret=None, # 'BYBIT_API_SECRET' env var
base_url_http=None, # Override with custom endpoint
instrument_provider=InstrumentProviderConfig(load_all=True),
instrument_types=[BybitInstrumentType.LINEAR],
instrument_types=[instrument_type],
testnet=False, # If client uses the testnet
),
},
@@ -84,7 +86,7 @@
base_url_http=None, # Override with custom endpoint
base_url_ws=None, # Override with custom endpoint
instrument_provider=InstrumentProviderConfig(load_all=True),
instrument_types=[BybitInstrumentType.LINEAR],
instrument_types=[instrument_type],
testnet=False, # If client uses the testnet
),
},
@@ -99,7 +101,7 @@
node = TradingNode(config=config_node)

# Configure your strategy
symbol = "ETHUSDT-LINEAR"
symbol = f"ETHUSDT-{instrument_type.value.upper()}"
strat_config = VolatilityMarketMakerConfig(
instrument_id=InstrumentId.from_str(f"{symbol}.BYBIT"),
external_order_claims=[InstrumentId.from_str(f"{symbol}.BYBIT")],
2 changes: 2 additions & 0 deletions nautilus_trader/adapters/bybit/execution.py
Original file line number Diff line number Diff line change
@@ -287,6 +287,8 @@ async def generate_position_status_reports(
self._log.info("Requesting PositionStatusReports...")
reports: list[PositionStatusReport] = []
for instrument_type in self._instrument_types:
if instrument_type == BybitInstrumentType.SPOT:
continue # No positions on spot
positions = await self._http_account.query_position_info(instrument_type)
for position in positions:
instr: InstrumentId = BybitSymbol(
4 changes: 4 additions & 0 deletions nautilus_trader/adapters/bybit/factories.py
Original file line number Diff line number Diff line change
@@ -282,6 +282,8 @@ def _get_ws_base_url_public(
return "wss://stream.bybit.com/v5/public/linear"
elif instrument_type == BybitInstrumentType.INVERSE:
return "wss://stream.bybit.com/v5/public/inverse"
elif instrument_type == BybitInstrumentType.OPTION:
return "wss://stream.bybit.com/v5/public/option"
else:
raise RuntimeError(
f"invalid `BybitAccountType`, was {instrument_type}", # pragma: no cover
@@ -293,6 +295,8 @@ def _get_ws_base_url_public(
return "wss://stream-testnet.bybit.com/v5/public/linear"
elif instrument_type == BybitInstrumentType.INVERSE:
return "wss://stream-testnet.bybit.com/v5/public/inverse"
elif instrument_type == BybitInstrumentType.OPTION:
return "wss://stream-testnet.bybit.com/v5/public/option"
else:
raise RuntimeError(f"invalid `BybitAccountType`, was {instrument_type}")

2 changes: 1 addition & 1 deletion nautilus_trader/adapters/bybit/schemas/instrument.py
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ def parse_to_instrument(
base_currency=self.parse_to_base_currency(),
quote_currency=self.parse_to_quote_currency(),
price_precision=price_precision,
size_precision=size_increment,
size_precision=size_increment.precision,
price_increment=price_increment,
size_increment=size_increment,
margin_init=Decimal("0.1"),

0 comments on commit cb0f855

Please sign in to comment.