Fix missing trade log after manual close when CTP is connected.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-18
@@ -2405,23 +2405,23 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
lots=lots, price=price, settings=_settings_dict(),
|
||||
order_type="market",
|
||||
)
|
||||
if not ctp_status(mode).get("connected"):
|
||||
write_manual_close_trade_log(
|
||||
conn,
|
||||
mon,
|
||||
symbol=sym,
|
||||
direction=direction,
|
||||
lots=lots,
|
||||
close_price=price,
|
||||
entry_price=entry or price,
|
||||
trading_mode=mode,
|
||||
capital=capital,
|
||||
stop_loss=float(mon["stop_loss"]) if mon and mon.get("stop_loss") is not None else None,
|
||||
take_profit=float(mon["take_profit"]) if mon and mon.get("take_profit") is not None else None,
|
||||
open_time=(mon.get("open_time") or "") if mon else "",
|
||||
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
||||
market_code=(mon.get("market_code") or "") if mon else "",
|
||||
)
|
||||
# 始终写本地记录:CTP 同步依赖内存开平配对,重启后或成交回报延迟时会漏记
|
||||
write_manual_close_trade_log(
|
||||
conn,
|
||||
mon,
|
||||
symbol=sym,
|
||||
direction=direction,
|
||||
lots=lots,
|
||||
close_price=price,
|
||||
entry_price=entry or price,
|
||||
trading_mode=mode,
|
||||
capital=capital,
|
||||
stop_loss=float(mon["stop_loss"]) if mon and mon.get("stop_loss") is not None else None,
|
||||
take_profit=float(mon["take_profit"]) if mon and mon.get("take_profit") is not None else None,
|
||||
open_time=(mon.get("open_time") or "") if mon else "",
|
||||
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
||||
market_code=(mon.get("market_code") or "") if mon else "",
|
||||
)
|
||||
_close_all_monitors_for_sym_dir(conn, sym, direction)
|
||||
conn.commit()
|
||||
try:
|
||||
@@ -2432,7 +2432,7 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
logger.debug("sync trades after close: %s", exc)
|
||||
conn.close()
|
||||
_push_position_snapshot_async()
|
||||
return jsonify({"ok": True, "message": "已平仓;交易记录将按柜台成交同步"})
|
||||
return jsonify({"ok": True, "message": "已平仓,交易记录已写入"})
|
||||
except ValueError as exc:
|
||||
conn.close()
|
||||
return jsonify({"ok": False, "error": str(exc)}), 400
|
||||
|
||||
Reference in New Issue
Block a user