Skip to content

Commit

Permalink
Refine BybitEnumParser for Bybit
Browse files Browse the repository at this point in the history
  • Loading branch information
sunlei committed Dec 14, 2024
1 parent dd9cd27 commit ac55a2f
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions nautilus_trader/adapters/bybit/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,23 @@ def __init__(self) -> None:
TimeInForce.FOK,
}

# trigger direction
self.trigger_direction_map_buy = {
OrderType.STOP_MARKET: BybitTriggerDirection.RISES_TO,
OrderType.STOP_LIMIT: BybitTriggerDirection.RISES_TO,
OrderType.MARKET_IF_TOUCHED: BybitTriggerDirection.RISES_TO,
OrderType.TRAILING_STOP_MARKET: BybitTriggerDirection.RISES_TO,
OrderType.LIMIT_IF_TOUCHED: BybitTriggerDirection.FALLS_TO,
}

self.trigger_direction_map_sell = {
OrderType.STOP_MARKET: BybitTriggerDirection.FALLS_TO,
OrderType.STOP_LIMIT: BybitTriggerDirection.FALLS_TO,
OrderType.MARKET_IF_TOUCHED: BybitTriggerDirection.FALLS_TO,
OrderType.TRAILING_STOP_MARKET: BybitTriggerDirection.FALLS_TO,
OrderType.LIMIT_IF_TOUCHED: BybitTriggerDirection.RISES_TO,
}

def parse_bybit_order_status(
self,
order_type: OrderType,
Expand Down Expand Up @@ -553,26 +570,10 @@ def parse_trigger_direction(
order_type: OrderType,
order_side: OrderSide,
) -> BybitTriggerDirection | None:
map_buy = {
OrderType.STOP_MARKET: BybitTriggerDirection.RISES_TO,
OrderType.STOP_LIMIT: BybitTriggerDirection.RISES_TO,
OrderType.MARKET_IF_TOUCHED: BybitTriggerDirection.RISES_TO,
OrderType.TRAILING_STOP_MARKET: BybitTriggerDirection.RISES_TO,
OrderType.LIMIT_IF_TOUCHED: BybitTriggerDirection.FALLS_TO,
}

map_sell = {
OrderType.STOP_MARKET: BybitTriggerDirection.FALLS_TO,
OrderType.STOP_LIMIT: BybitTriggerDirection.FALLS_TO,
OrderType.MARKET_IF_TOUCHED: BybitTriggerDirection.FALLS_TO,
OrderType.TRAILING_STOP_MARKET: BybitTriggerDirection.FALLS_TO,
OrderType.LIMIT_IF_TOUCHED: BybitTriggerDirection.RISES_TO,
}

if order_side == OrderSide.BUY:
return map_buy.get(order_type)
return self.trigger_direction_map_buy.get(order_type)
else: # SELL
return map_sell.get(order_type)
return self.trigger_direction_map_sell.get(order_type)

def parse_bybit_kline(self, bar_type: BarType) -> BybitKlineInterval:
try:
Expand Down

0 comments on commit ac55a2f

Please sign in to comment.