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(),
|
lots=lots, price=price, settings=_settings_dict(),
|
||||||
order_type="market",
|
order_type="market",
|
||||||
)
|
)
|
||||||
if not ctp_status(mode).get("connected"):
|
# 始终写本地记录:CTP 同步依赖内存开平配对,重启后或成交回报延迟时会漏记
|
||||||
write_manual_close_trade_log(
|
write_manual_close_trade_log(
|
||||||
conn,
|
conn,
|
||||||
mon,
|
mon,
|
||||||
symbol=sym,
|
symbol=sym,
|
||||||
direction=direction,
|
direction=direction,
|
||||||
lots=lots,
|
lots=lots,
|
||||||
close_price=price,
|
close_price=price,
|
||||||
entry_price=entry or price,
|
entry_price=entry or price,
|
||||||
trading_mode=mode,
|
trading_mode=mode,
|
||||||
capital=capital,
|
capital=capital,
|
||||||
stop_loss=float(mon["stop_loss"]) if mon and mon.get("stop_loss") is not None else None,
|
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,
|
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 "",
|
open_time=(mon.get("open_time") or "") if mon else "",
|
||||||
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
symbol_name=(mon.get("symbol_name") or "") if mon else "",
|
||||||
market_code=(mon.get("market_code") or "") if mon else "",
|
market_code=(mon.get("market_code") or "") if mon else "",
|
||||||
)
|
)
|
||||||
_close_all_monitors_for_sym_dir(conn, sym, direction)
|
_close_all_monitors_for_sym_dir(conn, sym, direction)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
try:
|
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)
|
logger.debug("sync trades after close: %s", exc)
|
||||||
conn.close()
|
conn.close()
|
||||||
_push_position_snapshot_async()
|
_push_position_snapshot_async()
|
||||||
return jsonify({"ok": True, "message": "已平仓;交易记录将按柜台成交同步"})
|
return jsonify({"ok": True, "message": "已平仓,交易记录已写入"})
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
conn.close()
|
conn.close()
|
||||||
return jsonify({"ok": False, "error": str(exc)}), 400
|
return jsonify({"ok": False, "error": str(exc)}), 400
|
||||||
|
|||||||
Reference in New Issue
Block a user