Skip to content

Commit

Permalink
Continue Bybit execution
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 1, 2024
1 parent 71bb800 commit 4f939b1
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 147 deletions.
5 changes: 2 additions & 3 deletions examples/live/bybit/bybit_ema_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
# *** THIS IS A TEST STRATEGY WITH NO ALPHA ADVANTAGE WHATSOEVER. ***
# *** IT IS NOT INTENDED TO BE USED TO TRADE LIVE WITH REAL MONEY. ***

# LINEAR
# SPOT/LINEAR
product_type = BybitProductType.SPOT
symbol = f"ETHUSDT-{product_type.value.upper()}"
trade_size = Decimal("0.010")

# Configure the trading node
config_node = TradingNodeConfig(
trader_id=TraderId("TESTER-001"),
logging=LoggingConfig(log_level="INFO"),
logging=LoggingConfig(log_level="INFO", use_pyo3=True),
exec_engine=LiveExecEngineConfig(
reconciliation=True,
reconciliation_lookback_mins=1440,
Expand All @@ -55,7 +55,6 @@
# ),
# message_bus=MessageBusConfig(
# database=DatabaseConfig(),
# encoding="json",
# streams_prefix="quoters",
# use_instance_id=False,
# timestamps_as_iso8601=True,
Expand Down
4 changes: 1 addition & 3 deletions examples/live/bybit/bybit_market_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# *** THIS INTEGRATION IS STILL UNDER CONSTRUCTION. ***
# *** CONSIDER IT TO BE IN AN UNSTABLE BETA PHASE AND EXERCISE CAUTION. ***

# LINEAR
# SPOT/LINEAR
product_type = BybitProductType.LINEAR
symbol = f"ETHUSDT-{product_type.value.upper()}"
trade_size = Decimal("0.010")
Expand All @@ -59,13 +59,11 @@
),
# cache=CacheConfig(
# database=DatabaseConfig(),
# encoding="json",
# timestamps_as_iso8601=True,
# buffer_interval_ms=100,
# ),
# message_bus=MessageBusConfig(
# database=DatabaseConfig(),
# encoding="json",
# timestamps_as_iso8601=True,
# buffer_interval_ms=100,
# streams_prefix="quoters",
Expand Down
91 changes: 64 additions & 27 deletions nautilus_trader/adapters/bybit/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ class BybitPositionIdx(Enum):
SELL_HEDGE = 2


@unique
class BybitAccountType(Enum):
UNIFIED = "UNIFIED"


@unique
class BybitProductType(Enum):
SPOT = "spot"
LINEAR = "linear"
INVERSE = "inverse"
OPTION = "option"

@property
def is_spot(self) -> bool:
return self == BybitProductType.SPOT

@property
def is_linear(self) -> bool:
return self == BybitProductType.LINEAR

@property
def is_inverse(self) -> bool:
return self == BybitProductType.INVERSE

@property
def is_option(self) -> bool:
return self == BybitProductType.OPTION


@unique
class BybitPositionSide(Enum):
BUY = "Buy"
Expand Down Expand Up @@ -95,7 +124,23 @@ class BybitOrderSide(Enum):
class BybitOrderType(Enum):
MARKET = "Market"
LIMIT = "Limit"
UNKNOWN = "Unknown"
UNKNOWN = "Unknown" # Used when execution type is Funding


@unique
class BybitStopOrderType(Enum):
NONE = "" # Default
UNKNOWN = "UNKNOWN" # Classic account value
TAKE_PROFIT = "TakeProfit"
STOP_LOSS = "StopLoss"
TRAILING_STOP = "TrailingStop"
STOP = "Stop"
PARTIAL_TAKE_PROFIT = "PartialTakeProfit"
PARTIAL_STOP_LOSS = "PartialStopLoss"
TPSL_ORDER = "tpslOrder"
OCO_ORDER = "OcoOrder" # Spot only
MM_RATE_CLOSE = "MmRateClose"
BIDIRECTIONAL_TPSL_ORDER = "BidirectionalTpslOrder"


@unique
Expand All @@ -114,24 +159,16 @@ class BybitTimeInForce(Enum):


@unique
class BybitAccountType(Enum):
UNIFIED = "UNIFIED"


@unique
class BybitProductType(Enum):
SPOT = "spot"
LINEAR = "linear"
INVERSE = "inverse"
OPTION = "option"

@property
def is_spot(self) -> bool:
return self in [BybitProductType.SPOT]

@property
def is_spot_or_margin(self) -> bool:
return self in [BybitProductType.SPOT]
class BybitExecType(Enum):
TRADE = "Trade"
ADL_TRADE = "AdlTrade" # Auto-Deleveraging
FUNDING = "Funding" # Funding fee
BUST_TRADE = "BustTrade" # Liquidation
DELIVERY = "Delivery" # Delivery
SETTLE = "Settle" # Settle Inverse futures settlement
BLOCK_TRADE = "BlockTrade"
MOVE_POSITION = "MovePosition"
UNKNOWN = "UNKNOWN" # Classic account value (cannot be used to query)


@unique
Expand All @@ -155,6 +192,14 @@ class BybitTransactionType(Enum):
AIRDROP = "AIRDRP"


@unique
class BybitEndpointType(Enum):
NONE = "NONE"
MARKET = "MARKET"
ACCOUNT = "ACCOUNT"
TRADE = "TRADE"


def check_dict_keys(key, data):
try:
return data[key]
Expand Down Expand Up @@ -284,11 +329,3 @@ def parse_bybit_kline(self, bar_type: BarType) -> BybitKlineInterval:
raise RuntimeError(
f"unrecognized Bybit bar type, was {bar_type}", # pragma: no cover
)


@unique
class BybitEndpointType(Enum):
NONE = "NONE"
MARKET = "MARKET"
ACCOUNT = "ACCOUNT"
TRADE = "TRADE"
4 changes: 2 additions & 2 deletions nautilus_trader/adapters/bybit/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def _subscribe_order_book_deltas(

if instrument_id in self._tob_quotes:
if depth == 1:
self._log.info(
self._log.debug(
f"Already subscribed to {instrument_id} top-of-book",
LogColor.MAGENTA,
)
Expand All @@ -321,7 +321,7 @@ async def _subscribe_quote_ticks(self, instrument_id: InstrumentId) -> None:

if bybit_symbol.is_spot or instrument_id not in self._depths:
# Subscribe top level (faster 10ms updates)
self._log.info(
self._log.debug(
f"Subscribing quotes {instrument_id} (faster top-of-book @10ms)",
LogColor.MAGENTA,
)
Expand Down
Loading

0 comments on commit 4f939b1

Please sign in to comment.