fix(trend): reconcile state from actual fills

This commit is contained in:
2026-09-05 00:29:50 +08:00
parent 6c2eca8fdc
commit a53fc738cf
5 changed files with 76 additions and 37 deletions

View File

@@ -13,8 +13,6 @@ from .runtime import Runtime
from .state import STATUS_ING
import logging as log
LEG_BASE = "base"
LEG_ADDED = "add"
LOSS_TIERS = (-30.0, -50.0)
@@ -129,7 +127,7 @@ def handle_profit(
volume = position.can_use_volume - position.can_use_volume % 100
if volume <= 0:
return TradeDecision(False, "无可用整手持仓")
order_id = runtime.orders.new_order_id(LEG_BASE)
order_id = runtime.orders.new_order_id()
request = PlaceOrderRequest(
client=runtime.client,
op=OP_SELL,
@@ -172,7 +170,7 @@ def handle_loss(
if volume <= 0 or amount > available:
return TradeDecision(False, "本轮可用资金不足")
order_id = runtime.orders.new_order_id(LEG_ADDED)
order_id = runtime.orders.new_order_id()
request = PlaceOrderRequest(
client=runtime.client,
op=OP_BUY,
@@ -184,11 +182,8 @@ def handle_loss(
if not runtime.orders.place(request):
return TradeDecision(False, "补仓委托失败")
state.added_num += 1
state.added_status = STATUS_ING
state.added_order_id = order_id
state.added_qty = volume
state.added_cost = tick.last_price
runtime.state.set(state)
runtime.state.save()
runtime.add_watch.forget(position.stock_code)