From 11d00678a12daac08d568a6166a78a33fa32d0ee Mon Sep 17 00:00:00 2001 From: nkaz001 Date: Sun, 24 Nov 2024 07:45:21 -0500 Subject: [PATCH] refactor(py): enable the live feature conditionally. --- py-hftbacktest/hftbacktest/__init__.py | 8 +++----- py-hftbacktest/hftbacktest/binding.py | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/py-hftbacktest/hftbacktest/__init__.py b/py-hftbacktest/hftbacktest/__init__.py index 07ba62a..0402980 100644 --- a/py-hftbacktest/hftbacktest/__init__.py +++ b/py-hftbacktest/hftbacktest/__init__.py @@ -59,8 +59,9 @@ ROIVectorMarketDepthLiveBot_, ROIVectorMarketDepthLiveBot as ROIVectorMarketDepthLiveBot_TypeHint, ) + LIVE_FEATURE = True except: - pass + LIVE_FEATURE = False __all__ = ( 'BacktestAsset', @@ -217,7 +218,7 @@ def ROIVectorMarketDepthBacktest( return ROIVectorMarketDepthBacktest_(ptr) -try: +if LIVE_FEATURE: def ROIVectorMarketDepthLiveBot( assets: List[LiveInstrument] ) -> ROIVectorMarketDepthLiveBot_TypeHint: @@ -232,6 +233,3 @@ def ROIVectorMarketDepthLiveBot( """ ptr = build_roivec_livebot(assets) return ROIVectorMarketDepthLiveBot_(ptr) - -except: - pass diff --git a/py-hftbacktest/hftbacktest/binding.py b/py-hftbacktest/hftbacktest/binding.py index a23269c..76a2a6e 100644 --- a/py-hftbacktest/hftbacktest/binding.py +++ b/py-hftbacktest/hftbacktest/binding.py @@ -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 @@ -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] @@ -2144,6 +2146,3 @@ def order_latency(self, asset_no: uint64) -> Tuple[int64, int64, int64] | None: ROIVectorMarketDepthLiveBot_ = jitclass(ROIVectorMarketDepthLiveBot) - -except: - pass