fix bug
This commit is contained in:
@@ -35,7 +35,6 @@ class OrderBook:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self, order_prefix: str, lock_timeout_sec: int = 180, cancel_timeout_sec: float = 30
|
self, order_prefix: str, lock_timeout_sec: int = 180, cancel_timeout_sec: float = 30
|
||||||
) -> None:
|
) -> None:
|
||||||
self.order_prefix = order_prefix
|
|
||||||
self.lock_timeout_sec = max(1, lock_timeout_sec)
|
self.lock_timeout_sec = max(1, lock_timeout_sec)
|
||||||
self.cancel_timeout_sec = timedelta(seconds=cancel_timeout_sec)
|
self.cancel_timeout_sec = timedelta(seconds=cancel_timeout_sec)
|
||||||
self.data: list[OrderItem] = []
|
self.data: list[OrderItem] = []
|
||||||
@@ -45,9 +44,9 @@ class OrderBook:
|
|||||||
)
|
)
|
||||||
self.mutex = Lock()
|
self.mutex = Lock()
|
||||||
|
|
||||||
def new_order_id(self, side: str) -> str:
|
def new_order_id(self,prefix:str, side: str) -> str:
|
||||||
"""生成带策略前缀的本地订单号。"""
|
"""生成带策略前缀的本地订单号。"""
|
||||||
return f"{self.order_prefix}-{side}-{secrets.token_hex(10)}"
|
return f"{prefix}-{side}-{secrets.token_hex(10)}"
|
||||||
|
|
||||||
def busy(self, code: str, side: str) -> bool:
|
def busy(self, code: str, side: str) -> bool:
|
||||||
"""判断证券是否存在仍在处理中的同方向委托。"""
|
"""判断证券是否存在仍在处理中的同方向委托。"""
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ def do_open(
|
|||||||
run: Runtime, code: str, volume: int, signal_key: str, price: float
|
run: Runtime, code: str, volume: int, signal_key: str, price: float
|
||||||
) -> None:
|
) -> None:
|
||||||
"""生成本地订单号并按最新价提交开仓委托。"""
|
"""生成本地订单号并按最新价提交开仓委托。"""
|
||||||
order_id = run.orders.new_order_id("BUY")
|
prefix = signal_key[:4].upper()
|
||||||
|
order_id = run.orders.new_order_id(prefix,"BUY")
|
||||||
request = PlaceOrderRequest(
|
request = PlaceOrderRequest(
|
||||||
OP_BUY,
|
OP_BUY,
|
||||||
code,
|
code,
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ def open_signal(run: Runtime, ticks, signals, available: float) -> float:
|
|||||||
# 等待价格从观察低点反弹,防止直接接下跌中的“飞刀”。
|
# 等待价格从观察低点反弹,防止直接接下跌中的“飞刀”。
|
||||||
if not run.open_watch.triggered("ZT 建仓", item.code, price):
|
if not run.open_watch.triggered("ZT 建仓", item.code, price):
|
||||||
continue
|
continue
|
||||||
order_id = run.orders.new_order_id("base")
|
order_id = run.orders.new_order_id("ZT","base")
|
||||||
request = PlaceOrderRequest(
|
request = PlaceOrderRequest(
|
||||||
OP_BUY, item.code, volume, order_id, "zt"
|
OP_BUY, item.code, volume, order_id, "zt"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user