This commit is contained in:
2026-09-10 12:50:40 +08:00
parent 72a49bc741
commit d837250bcb
10 changed files with 423 additions and 458 deletions

View File

@@ -4,7 +4,6 @@ from datetime import datetime
import logging as log
import math
from libs.calc import calc_buy_volume
from sdk import OP_BUY
from libs.runtime import Runtime
from libs.order import PlaceOrderRequest
@@ -12,11 +11,11 @@ from libs.order import PlaceOrderRequest
def open_signal(run: Runtime, ticks, signals, available: float) -> float:
"""逐个验证开仓信号并提交买入委托,返回本轮剩余资金。"""
now = datetime.now()
if (now.hour, now.minute) >= (14, 50):
return available
for item in signals:
try:
now = datetime.now()
if (now.hour, now.minute) >= (14, 50):
break
if item.code in run.account_cfg.excluded_codes:
continue
# 由委托簿检查活动委托,防止重复下单。
@@ -36,16 +35,16 @@ def open_signal(run: Runtime, ticks, signals, available: float) -> float:
continue
# 根据单笔买入金额计算整手数量,并预留少量价差和费用。
budget = min(run.account_cfg.buy_value, available)
volume = calc_buy_volume(price, budget)
volume = int(budget / (price * 1.01)) // 100 * 100
amount = price * volume * 1.01
if volume <= 0 or price * volume > budget or amount > available:
if volume < (200 if item.code.startswith('688') else 100):
continue
# 等待价格从观察低点反弹,防止直接接下跌中的“飞刀”。
if not run.open_watch.triggered("ZT 建仓", item.code, price):
continue
order_id = run.orders.new_order_id("base")
request = PlaceOrderRequest(
OP_BUY, item.code, volume, order_id, "zt", kind="base"
OP_BUY, item.code, volume, order_id, "zt"
)
# 即使响应丢失,本轮也预留资金;状态簿只在取得实际成交后入账。
available -= amount