Skip to content

Commit

Permalink
refactor(py): enable the live feature conditionally.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaz001 committed Nov 24, 2024
1 parent 1a8bf22 commit 11d0067
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 3 additions & 5 deletions py-hftbacktest/hftbacktest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
ROIVectorMarketDepthLiveBot_,
ROIVectorMarketDepthLiveBot as ROIVectorMarketDepthLiveBot_TypeHint,
)
LIVE_FEATURE = True
except:
pass
LIVE_FEATURE = False

__all__ = (
'BacktestAsset',
Expand Down Expand Up @@ -217,7 +218,7 @@ def ROIVectorMarketDepthBacktest(
return ROIVectorMarketDepthBacktest_(ptr)


try:
if LIVE_FEATURE:
def ROIVectorMarketDepthLiveBot(
assets: List[LiveInstrument]
) -> ROIVectorMarketDepthLiveBot_TypeHint:
Expand All @@ -232,6 +233,3 @@ def ROIVectorMarketDepthLiveBot(
"""
ptr = build_roivec_livebot(assets)
return ROIVectorMarketDepthLiveBot_(ptr)

except:
pass
7 changes: 3 additions & 4 deletions py-hftbacktest/hftbacktest/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from .state import StateValues, StateValues_
from .types import event_dtype, state_values_dtype, EVENT_ARRAY

LIVE_FEATURE = 'build_hashmap_livebot' in dir(_hftbacktest)

lib = CDLL(_hftbacktest.__file__)

hashmapdepth_best_bid_tick = lib.hashmapdepth_best_bid_tick
Expand Down Expand Up @@ -1310,7 +1312,7 @@ def order_latency(self, asset_no: uint64) -> Tuple[int64, int64, int64] | None:

ROIVectorMarketDepthBacktest_ = jitclass(ROIVectorMarketDepthBacktest)

try:
if LIVE_FEATURE:
hashmaplive_elapse = lib.hashmaplive_elapse
hashmaplive_elapse.restype = c_int64
hashmaplive_elapse.argtypes = [c_void_p, c_uint64]
Expand Down Expand Up @@ -2144,6 +2146,3 @@ def order_latency(self, asset_no: uint64) -> Tuple[int64, int64, int64] | None:


ROIVectorMarketDepthLiveBot_ = jitclass(ROIVectorMarketDepthLiveBot)

except:
pass

0 comments on commit 11d0067

Please sign in to comment.