feat dev6
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
from libs.calc import calc_buy_volume, calculate_min_profit_rate
|
||||
@@ -12,6 +11,7 @@ from sdk import OP_BUY, OP_SELL, PositionItem, Tick
|
||||
from .order import PlaceOrderRequest
|
||||
from .runtime import Runtime
|
||||
from .state import STATUS_ING
|
||||
import logging as log
|
||||
|
||||
LEG_BASE = "base"
|
||||
LEG_ADDED = "add"
|
||||
@@ -43,11 +43,11 @@ def manage_positions(
|
||||
runtime.profit_tracker.retain(active_keys)
|
||||
remaining_cash = max(0.0, available)
|
||||
|
||||
logging.info("[持仓] 共 %d 只,开始处理", len(positions))
|
||||
for position in positions:
|
||||
code = position.stock_code
|
||||
tick = ticks.get(code)
|
||||
if code in runtime.account_cfg.excluded_codes:
|
||||
log.info("[持仓] 代码=%s,名称=%s,止盈=跳过,补仓=跳过,原因=已配置为排除股票", code, position.stock_name)
|
||||
continue
|
||||
if (
|
||||
not code
|
||||
@@ -56,6 +56,7 @@ def manage_positions(
|
||||
or tick is None
|
||||
or tick.last_price <= 0
|
||||
):
|
||||
log.warning("[持仓] 代码=%s,名称=%s,止盈=跳过,补仓=跳过,原因=持仓或行情数据无效", code or "未知", position.stock_name)
|
||||
continue
|
||||
|
||||
pnl_rate = round(
|
||||
@@ -70,9 +71,8 @@ def manage_positions(
|
||||
pnl_rate=pnl_rate,
|
||||
minimum_profit=minimum_profit,
|
||||
)
|
||||
if profit_decision.message:
|
||||
logging.info("[止盈] %s %s", code, profit_decision.message)
|
||||
|
||||
profit_action = profit_decision.message or "未触发"
|
||||
loss_add_action = "未启用"
|
||||
if runtime.account_cfg.enable_loss_add_position and market_ok:
|
||||
loss_decision = handle_loss(
|
||||
runtime=runtime,
|
||||
@@ -82,8 +82,14 @@ def manage_positions(
|
||||
available=remaining_cash,
|
||||
)
|
||||
remaining_cash -= loss_decision.reserved_cash
|
||||
if loss_decision.message:
|
||||
logging.info("[补仓] %s %s", code, loss_decision.message)
|
||||
loss_add_action = loss_decision.message or "未触发"
|
||||
elif runtime.account_cfg.enable_loss_add_position:
|
||||
loss_add_action = "大盘信号不允许"
|
||||
|
||||
log.info(
|
||||
"[持仓] 代码=%s,名称=%s,盈亏=%.2f%%,止盈=%s,补仓=%s",
|
||||
code, position.stock_name, pnl_rate, profit_action, loss_add_action,
|
||||
)
|
||||
|
||||
|
||||
def handle_profit(
|
||||
|
||||
Reference in New Issue
Block a user