Skip to content

Commit 11d0067

Browse files
committed
refactor(py): enable the live feature conditionally.
1 parent 1a8bf22 commit 11d0067

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

py-hftbacktest/hftbacktest/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959
ROIVectorMarketDepthLiveBot_,
6060
ROIVectorMarketDepthLiveBot as ROIVectorMarketDepthLiveBot_TypeHint,
6161
)
62+
LIVE_FEATURE = True
6263
except:
63-
pass
64+
LIVE_FEATURE = False
6465

6566
__all__ = (
6667
'BacktestAsset',
@@ -217,7 +218,7 @@ def ROIVectorMarketDepthBacktest(
217218
return ROIVectorMarketDepthBacktest_(ptr)
218219

219220

220-
try:
221+
if LIVE_FEATURE:
221222
def ROIVectorMarketDepthLiveBot(
222223
assets: List[LiveInstrument]
223224
) -> ROIVectorMarketDepthLiveBot_TypeHint:
@@ -232,6 +233,3 @@ def ROIVectorMarketDepthLiveBot(
232233
"""
233234
ptr = build_roivec_livebot(assets)
234235
return ROIVectorMarketDepthLiveBot_(ptr)
235-
236-
except:
237-
pass

py-hftbacktest/hftbacktest/binding.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
from .state import StateValues, StateValues_
2929
from .types import event_dtype, state_values_dtype, EVENT_ARRAY
3030

31+
LIVE_FEATURE = 'build_hashmap_livebot' in dir(_hftbacktest)
32+
3133
lib = CDLL(_hftbacktest.__file__)
3234

3335
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:
13101312

13111313
ROIVectorMarketDepthBacktest_ = jitclass(ROIVectorMarketDepthBacktest)
13121314

1313-
try:
1315+
if LIVE_FEATURE:
13141316
hashmaplive_elapse = lib.hashmaplive_elapse
13151317
hashmaplive_elapse.restype = c_int64
13161318
hashmaplive_elapse.argtypes = [c_void_p, c_uint64]
@@ -2144,6 +2146,3 @@ def order_latency(self, asset_no: uint64) -> Tuple[int64, int64, int64] | None:
21442146

21452147

21462148
ROIVectorMarketDepthLiveBot_ = jitclass(ROIVectorMarketDepthLiveBot)
2147-
2148-
except:
2149-
pass

0 commit comments

Comments
 (0)